Created
August 29, 2018 07:33
-
-
Save csetzkorn/84cfb993328904e07c4fd0908552d38c to your computer and use it in GitHub Desktop.
get CI of r-squared
This file contains 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
rsquared_boot, coefs_boot, sims = [], [], 1000 | |
reg_fit = sm.OLS(df['y'], df.iloc[:,1:]).fit() | |
# Run 1K iterations | |
for i in range(sims): | |
# First create a bootstrap sample with replacement with n=df.shape[0] | |
bootstrap = df.sample(n=df.shape[0], replace=True) | |
# Fit the regression and append the r square to rsquared_boot | |
rsquared_boot.append(sm.OLS(bootstrap['y'],bootstrap.iloc[:,1:]).fit().rsquared) | |
# Calculate 95% CI on rsquared_boot | |
print("R Squared 95% CI = {}".format(np.percentile(rsquared_boot, [2.5, 97.5]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment