Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print 'std err' value from statsmodels OLS results

(Sorry to ask but http://statsmodels.sourceforge.net/ is currently down and I can't access the docs)

I'm doing a linear regression using statsmodels, basically:

import statsmodels.api as sm model = sm.OLS(y,x) results = model.fit() 

I know that I can print out the full set of results with:

print results.summary() 

which outputs something like:

                            OLS Regression Results                             ============================================================================== Dep. Variable:                      y   R-squared:                       0.952 Model:                            OLS   Adj. R-squared:                  0.951 Method:                 Least Squares   F-statistic:                     972.9 Date:                Mon, 20 Jul 2015   Prob (F-statistic):           5.55e-34 Time:                        15:35:22   Log-Likelihood:                -78.843 No. Observations:                  50   AIC:                             159.7 Df Residuals:                      49   BIC:                             161.6 Df Model:                           1                                          Covariance Type:            nonrobust                                          ==============================================================================                  coef    std err          t      P>|t|      [95.0% Conf. Int.] ------------------------------------------------------------------------------ x1             1.0250      0.033     31.191      0.000         0.959     1.091 ============================================================================== Omnibus:                       16.396   Durbin-Watson:                   2.166 Prob(Omnibus):                  0.000   Jarque-Bera (JB):                3.480 Skew:                          -0.082   Prob(JB):                        0.175 Kurtosis:                       1.718   Cond. No.                         1.00 ==============================================================================  Warnings: [1] Standard Errors assume that the covariance matrix of the errors is correctly specified. 

I need a way to print out only the values of coef and std err.

I can access coef with:

print results.params 

but I've found no way to print out std err.

How can I do this?

like image 967
Gabriel Avatar asked Jul 20 '15 18:07

Gabriel


People also ask

How do you find standard error in OLS?

Standard Error of OLS Estimates All of the terms in the equations above except σ2 can be calculated from the sample drawn. Therefore, we will need an unbiased estimator ^σ2=∑^u2in−2 σ ^ 2 = ∑ u ^ i 2 n − 2 . The denominator n−2 represents the degrees of freedom. ∑^u2i ∑ u ^ i 2 is the residual sum of squares.

What is condition number in statsmodels?

Python: StatsModels I will point out two issues here. The condition number (abbreviated “Cond. No.” in the summary) is a measure of “how close to singular” a matrix is; the higher, the “more singular” (and infinite means singular — i.e. noninvertible), and the more “error” a best fit approximation is.


1 Answers

Applying the answer given here I used dir() to print all the attributes of the results object.

After that I searched for the one that contained the std err value and it turned out to be:

print results.bse 

(Not sure what the b stands for in bse, but I guess the se stands for "standard error")

like image 99
Gabriel Avatar answered Oct 18 '22 15:10

Gabriel