Created
May 20, 2018 21:54
-
-
Save zhiyzuo/972b8b95e115c44d6805c929b7b4e2ca to your computer and use it in GitHub Desktop.
Obtain regression model coefficients from statsmodels
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 pandas as pd | |
def get_coef_table(lin_reg): | |
''' lin_reg is a fitted statsmodels regression model | |
Return a dataframe containing coefficients, pvalues, and the confidence intervals | |
''' | |
err_series = lin_reg.params - lin_reg.conf_int()[0] | |
coef_df = pd.DataFrame({'coef': lin_reg.params.values[1:], | |
'ci_err': err_series.values[1:], | |
'pvalue': lin_reg.pvalues.round(4).values[1:], | |
'varname': err_series.index.values[1:] | |
}) | |
return coef_df |
This has been such a great help. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great thank you! Comes up google search for python stats models how to print coef values