Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Last active October 9, 2022 16:26
Show Gist options
  • Save galenseilis/3ecc54807a7fd949d8701ceac6021566 to your computer and use it in GitHub Desktop.
Save galenseilis/3ecc54807a7fd949d8701ceac6021566 to your computer and use it in GitHub Desktop.
'''
Easier method: regress y−2x against x and read the t-test results directly off the summary, making sure to halve any reported p-values to account for the one-sided alternative.
- whuber
'''
import numpy as np
import statsmodels.api as sm
x = np.array([1,2,3,3,4,5,5])
y = np.array([3,7,5,8,11,14,12])
Y = y - 2 * x
X = sm.add_constant(x)
model = sm.OLS(Y, X)
results = model.fit()
print(results.summary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment