Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - StatsModels, OLS Confidence interval

In Statsmodels I can fit my model using

import statsmodels.api as sm

X = np.array([22000, 13400, 47600, 7400, 12000, 32000, 28000, 31000, 69000, 48600])
y = np.array([0.62, 0.24, 0.89, 0.11, 0.18, 0.75, 0.54, 0.61, 0.92, 0.88])
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()

then print a nice summary using

print(est2.summary())

and the extract things like the p-values using

est2.pvalues

which can be found on this page http://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.RegressionResults.html

but in the summary there are confidence intervals and I am lost as to how to extract these confidence intervals, like I do with the pvalues.

Apart from seeing them in the summary, how can i get these confidence intervals?

like image 203
Runner Bean Avatar asked Jun 01 '17 08:06

Runner Bean


People also ask

What is OLS in Python statsmodels?

OLS or Ordinary Least Squares is a useful method for evaluating a linear regression model. It does this by using specific statistical performance metrics about the model as a whole and each specific parameter of the model. The OLS method comes from the StatsModels python package.

Why Statsmodel is used in Python?

Statsmodels is a Python package that allows users to explore data, estimate statistical models, and perform statistical tests. An extensive list of descriptive statistics, statistical tests, plotting functions, and result statistics are available for different types of data and each estimator.

What is the difference between prediction interval and confidence interval?

The prediction interval predicts in what range a future individual observation will fall, while a confidence interval shows the likely range of values associated with some statistical parameter of the data, such as the population mean.


1 Answers

est2.conf_int(alpha=0.05, cols=None)

See also the statsmodels manual.

like image 112
Runner Bean Avatar answered Oct 03 '22 02:10

Runner Bean