Help on class OLS in module statsmodels.regression.linear_model:
class OLS(WLS)
| 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
| :func:`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.
|
|
| Attributes
| ----------
| weights : scalar
| Has an attribute weights = array(1.0) due to inheritance from WLS.
|
| See Also
| --------
| GLS
|
| 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>
|
| Notes
| -----
| No constant is added by the model unless you are using formulas.
|
| Method resolution order:
| OLS
| WLS
| RegressionModel
| statsmodels.base.model.LikelihoodModel
| statsmodels.base.model.Model
| builtins.object
|
| Methods defined here:
|
| __init__(self, endog, exog=None, missing='none', hasconst=None, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| loglike(self, params)
| The likelihood function for the clasical OLS model.
|
| Parameters
| ----------
| params : array-like
| The coefficients with which to estimate the log-likelihood.
|
| Returns
| -------
| The concentrated likelihood function evaluated at params.
|
| whiten(self, Y)
| OLS model whitener does nothing: returns Y.
|
| ----------------------------------------------------------------------
| Methods inherited from RegressionModel:
|
| fit(self, method='pinv', cov_type='nonrobust', cov_kwds=None, use_t=None, **kwargs)
| Full fit of the model.
|
| The results include an estimate of covariance matrix, (whitened)
| residuals and an estimate of scale.
|
| Parameters
| ----------
| method : str
| Can be "pinv", "qr". "pinv" uses the Moore-Penrose pseudoinverse
| to solve the least squares problem. "qr" uses the QR
| factorization.
|
| Returns
| -------
| A RegressionResults class instance.
|
| See Also
| ---------
| regression.RegressionResults
|
| Notes
| -----
| The fit method uses the pseudoinverse of the design/exogenous variables
| to solve the least squares minimization.
|
| fit_regularized(self, method='coord_descent', maxiter=1000, alpha=0.0, L1_wt=1.0, start_params=None, cnvrg_tol=1e-08, zero_tol=1e-08, **kwargs)
| Return a regularized fit to a linear regression model.
|
| Parameters
| ----------
| method : string
| Only the coordinate descent algorithm is implemented.
| maxiter : integer
| The maximum number of iteration cycles (an iteration cycle
| involves running coordinate descent on all variables).
| alpha : scalar or array-like
| The penalty weight. If a scalar, the same penalty weight
| applies to all variables in the model. If a vector, it
| must have the same length as `params`, and contains a
| penalty weight for each coefficient.
| L1_wt : scalar
| The fraction of the penalty given to the L1 penalty term.
| Must be between 0 and 1 (inclusive). If 0, the fit is
| ridge regression. If 1, the fit is the lasso.
| start_params : array-like
| Starting values for ``params``.
| cnvrg_tol : scalar
| If ``params`` changes by less than this amount (in sup-norm)
| in once iteration cycle, the algorithm terminates with
| convergence.
| zero_tol : scalar
| Any estimated coefficient smaller than this value is
| replaced with zero.
|
| Returns
| -------
| A RegressionResults object, of the same type returned by
| ``fit``.
|
| Notes
| -----
| The approach closely follows that implemented in the glmnet
| package in R. The penalty is the "elastic net" penalty, which
| is a convex combination of L1 and L2 penalties.
|
| The function that is minimized is: ..math::
|
| 0.5*RSS/n + alpha*((1-L1_wt)*|params|_2^2/2 + L1_wt*|params|_1)
|
| where RSS is the usual regression sum of squares, n is the
| sample size, and :math:`|*|_1` and :math:`|*|_2` are the L1 and L2
| norms.
|
| Post-estimation results are based on the same data used to
| select variables, hence may be subject to overfitting biases.
|
| References
| ----------
| Friedman, Hastie, Tibshirani (2008). Regularization paths for
| generalized linear models via coordinate descent. Journal of
| Statistical Software 33(1), 1-22 Feb 2010.
|
| initialize(self)
| Initialize (possibly re-initialize) a Model instance. For
| instance, the design matrix of a linear model may change
| and some things must be recomputed.
|
| predict(self, params, exog=None)
| Return linear predicted values from a design matrix.
|
| Parameters
| ----------
| params : array-like
| Parameters of a linear model
| exog : array-like, optional.
| Design / exogenous data. Model exog is used if None.
|
| Returns
| -------
| An array of fitted values
|
| Notes
| -----
| If the model has not yet been fit, params is not optional.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from RegressionModel:
|
| 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.
|
| ----------------------------------------------------------------------
| Methods inherited from statsmodels.base.model.LikelihoodModel:
|
| hessian(self, params)
| The Hessian matrix of the model
|
| information(self, params)
| Fisher information matrix of model
|
| Returns -Hessian of loglike evaluated at params.
|
| score(self, params)
| Score vector of model.
|
| The gradient of logL with respect to each parameter.
|
| ----------------------------------------------------------------------
| Class methods inherited from statsmodels.base.model.Model:
|
| from_formula(formula, data, subset=None, *args, **kwargs) from builtins.type
| Create a Model from a formula and dataframe.
|
| Parameters
| ----------
| formula : str or generic Formula object
| The formula specifying the model
| data : array-like
| The data for the model. See Notes.
| subset : array-like
| An array-like object of booleans, integers, or index values that
| indicate the subset of df to use in the model. Assumes df is a
| `pandas.DataFrame`
| args : extra arguments
| These are passed to the model
| kwargs : extra keyword arguments
| These are passed to the model with one exception. The
| ``eval_env`` keyword is passed to patsy. It can be either a
| :class:`patsy:patsy.EvalEnvironment` object or an integer
| indicating the depth of the namespace to use. For example, the
| default ``eval_env=0`` uses the calling namespace. If you wish
| to use a "clean" environment set ``eval_env=-1``.
|
|
| Returns
| -------
| model : Model instance
|
| Notes
| ------
| data must define __getitem__ with the keys in the formula terms
| args and kwargs are passed on to the model instantiation. E.g.,
| a numpy structured or rec array, a dictionary, or a pandas DataFrame.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from statsmodels.base.model.Model:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| endog_names
|
| exog_names