Linear models with independently and identically distributed errors, and for errors with heteroscedasticity or autocorrelation. This module allows estimation by ordinary least squares (OLS), weighted least squares (WLS), generalized least squares (GLS), and feasible generalized least squares with autocorrelated AR(p) errors.
See Module Reference for commands and arguments.
# Load modules and data
import numpy as np
import statsmodels.api as sm
spector_data = sm.datasets.spector.load()
spector_data.exog = sm.add_constant(spector_data.exog, prepend=False)
# Fit and summarize OLS model
mod = sm.OLS(spector_data.endog, spector_data.exog)
res = mod.fit()
print res.summary()
Detailed examples can be found here:
The statistical model is assumed to be
Y = X\beta + \mu, where \mu\sim N\left(0,\sigma^{2}\Sigma\right)
depending on the assumption on \Sigma, we have currently four classes available
All regression models define the same methods and follow the same structure, and can be used in a similar fashion. Some of them contain additional model specific methods and attributes.
GLS is the superclass of the other regression classes.
General reference for regression models:
Econometrics references for regression models:
The following is more verbose description of the attributes which is mostly common to all regression classes
OLS(endog[, exog, missing, hasconst]) | A simple ordinary least squares model. |
GLS(endog, exog[, sigma, missing, hasconst]) | Generalized least squares model with a general covariance structure. |
WLS(endog, exog[, weights, missing, hasconst]) | A regression model with diagonal but non-identity covariance structure. |
GLSAR(endog[, exog, rho, missing]) | A regression model with an AR(p) covariance structure. |
yule_walker(X[, order, method, df, inv, demean]) | Estimate AR(p) parameters from a sequence X using Yule-Walker equation. |
QuantReg(endog, exog, **kwargs) | Quantile Regression |
Fitting a linear regression model returns a results class. OLS has a specific results class with some additional methods compared to the results class of the other linear models.
RegressionResults(model, params[, ...]) | This class summarizes the fit of a linear regression model. |
OLSResults(model, params[, ...]) | Results class for for an OLS model. |
QuantRegResults(model, params[, ...]) | Results instance for the QuantReg model |