segreg.model.OneBkptSegRegEstimator

class OneBkptSegRegEstimator(num_end_to_skip=None, restrict_rhs_slope=None, no_bias_variance=False)[source]

Estimator for one-bkpt segmented regression.

This estimator is limited to univariate, continuous, linear, one-bkpt segmented regression problems. The model fitting estimates the parameters:

[u, v, m1, m2, sigma]

where

(u,v) is the breakpoint (in x-y plane)

m1 is the slope of the left-hand segment

m2 is the slope of the right-hand segment

sigma is the standard deviation of the residuals

Examples

>>> from segreg.model import OneBkptSegRegEstimator
>>> indep = [1,2,3,4,5,6,7,8,9]
>>> dep = [1,2,3,4,5,4,3,2,1]
>>> estimator = OneBkptSegRegEstimator()
>>> estimator.fit(indep, dep)
array([ 5.,  5.,  1., -1.,  0.])
Parameters
  • num_end_to_skip (int) – Number of data points to skip at each end of the data when solving for the bkpts. As such, this determines a guaranteed minimum number of data points in the left and right segments in the returned fit. If None, defaults to the underlying implementation. TODO: explain

  • restrict_rhs_slope (float or None) – If not None, will fix the rhs slope, m2, to the given value. As such, the rhs slope m2 will not be estimated when fit is called.

  • no_bias_variance (bool) – If True, will modify the MLE estimate of the variance so that it is unbiased.

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.