segreg.model.OLSRegressionEstimator

class OLSRegressionEstimator[source]

Estimator for ordinary least-squares regression.

This estimator is limited to univariate, linear, regression problems. The model fitting estimates the parameters:

[intercept, slope, sigma]

where the fitted line is defined by

y = intercept + slope * x

and sigma is the standard deviation of the residuals.

Notes

There are many standard python libraries for this type of OLS. This class is provided as a convenience to implement the same interface as the estimators for segmented regression. Moreover, the underlying implementation has been customized for the univariate regression problems for which this class is limited, for the purpose of greater calculation speed.

Examples

>>> from segreg.model import OLSRegressionEstimator
>>> indep = [1,2,3,4,5]
>>> dep = [2,3,4,5,6]
>>> estimator = OLSRegressionEstimator()
>>> estimator.fit(indep, dep)
array([1., 1., 0.])

Methods

fit(indep, dep)

Fit the model to the given data.

get_func_for_params(params)

Returns the regression model function defined by the given parameters.

Properties

estimated_params_indices

Indices in the parameter array of the fitted parameters.

has_restricted_params

Whether there are any model parameters set to a fixed value.

loglikelihood

Computes loglikelihood at the MLE (maximum likelihood estimate).

model_function

Returns the regression model function defined by the estimated parameters.

num_params

Number of model parameters.

param_names

Names of the parameters.

params

Returns the fitted parameters.

r_squared

R-squared of the fit.

residuals

Returns the residuals from the fit.

rss

Residual sum of squares of the fit.