Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Created October 16, 2022 00:01
Show Gist options
  • Save galenseilis/e7542a89b128823751f9875e793e51b7 to your computer and use it in GitHub Desktop.
Save galenseilis/e7542a89b128823751f9875e793e51b7 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.stats import t
import statsmodels.api as sm
# Prepare data
x = np.array([1,2,3,3,4,5,5])
y = np.array([3,7,5,8,11,14,12])
n = y.size
X = sm.add_constant(x)
# Define and train
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())
# t-test
t_obs = (results.params[1] - 2) / results.bse[1]
print(1 - t.sf(t_obs, n-2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment