1.2.10. statsmodels.api.OLS

class statsmodels.api.OLS(endog, exog=None, missing='none', hasconst=None, **kwargs)[source]

A simple ordinary least squares model.

Parameters:

endog : array-like

1-d endogenous response variable. The dependent variable.

exog : array-like

A nobs x k array where nobs is the number of observations and k is the number of regressors. An intercept is not included by default and should be added by the user. See statsmodels.tools.add_constant().

missing : str

Available options are ‘none’, ‘drop’, and ‘raise’. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise’, an error is raised. Default is ‘none.’

hasconst : None or bool

Indicates whether the RHS includes a user-supplied constant. If True, a constant is not checked for and k_constant is set to 1 and all result statistics are calculated as if a constant is present. If False, a constant is not checked for and k_constant is set to 0.

See also

GLS

Notes

No constant is added by the model unless you are using formulas.

Examples

>>> import numpy as np
>>>
>>> import statsmodels.api as sm
>>>
>>> Y = [1,3,4,5,2,3,4]
>>> X = range(1,8)
>>> X = sm.add_constant(X)
>>>
>>> model = sm.OLS(Y,X)
>>> results = model.fit()
>>> results.params
array([ 2.14285714,  0.25      ])
>>> results.tvalues
array([ 1.87867287,  0.98019606])
>>> print(results.t_test([1, 0])))
<T test: effect=array([ 2.14285714]), sd=array([[ 1.14062282]]), t=array([[ 1.87867287]]), p=array([[ 0.05953974]]), df_denom=5>
>>> print(results.f_test(np.identity(2)))
<F test: F=array([[ 19.46078431]]), p=[[ 0.00437251]], df_denom=5, df_num=2>

Attributes

weights (scalar) Has an attribute weights = array(1.0) due to inheritance from WLS.
__init__(endog, exog=None, missing='none', hasconst=None, **kwargs)[source]

1.2.10.1. Methods

__init__(endog[, exog, missing, hasconst])
fit([method, cov_type, cov_kwds, use_t]) Full fit of the model.
fit_regularized([method, maxiter, alpha, ...]) Return a regularized fit to a linear regression model.
from_formula(formula, data[, subset]) Create a Model from a formula and dataframe.
hessian(params) The Hessian matrix of the model
information(params) Fisher information matrix of model
initialize()
loglike(params) The likelihood function for the clasical OLS model.
predict(params[, exog]) Return linear predicted values from a design matrix.
score(params) Score vector of model.
whiten(Y) OLS model whitener does nothing: returns Y.

1.2.10.2. Attributes

df_model The model degree of freedom, defined as the rank of the regressor matrix minus 1 if a constant is included.
df_resid The residual degree of freedom, defined as the number of observations minus the rank of the regressor matrix.
endog_names
exog_names