Created
October 16, 2022 00:08
-
-
Save galenseilis/5147606b002df38f64045b3677834580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.stats import t | |
| import statsmodels.api as sm | |
| np.random.seed(2022) | |
| # Prepare data | |
| N = 51 | |
| k = 1 | |
| x = np.random.normal(size=N) | |
| y = 2 * x + np.random.normal(size=N) | |
| X = sm.add_constant(x) | |
| # Define and train | |
| model = sm.OLS(y, X) | |
| results = model.fit() | |
| # t-test | |
| dof = results.df_resid | |
| tstat = (results.params[k] - 2) / results.bse[k] | |
| print(1 - t.sf(tstat, dof)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment