segreg.model.TwoBkptSegRegEstimator

class TwoBkptSegRegEstimator(num_end_to_skip=None, num_between_to_skip=None, no_bias_variance=False)[source]

Estimator for two-bkpt segmented regression.

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

[u1, v1, u2, v2, m1, m2, sigma]

where

(u1,v1), (u2, v2) are the breakpoints (in x-y plane), ordered such that u1 < u2

m1 is the slope of the left-most segment

m2 is the slope of the right-most segment

sigma is the standard deviation of the residuals

Notes

The slope of the middle segment of the two-bkpt model does not appear as a parameter since it is implied by the parameters (u1, v1) and (u2, v2).

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-most and right-most segments in the returned fit. If None, defaults to the underlying implementation. TODO: explain

  • num_between_to_skip (int) – Number of data points to skip between the two bkpts (ie: the middle segment) when solving for the bkpts. Specifically, for each choice of left bkpt u1, will skip this many data points between u1 and u2. As such, this determines a guaranteed minimum number of data points between the bkpts in the returned fit.

Examples

>>> from segreg.model import TwoBkptSegRegEstimator
>>> indep = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
>>> dep = [1,2,3,4,5,4,3,2,1,0,1,2,3,4]
>>> estimator = TwoBkptSegRegEstimator()
>>> estimator.fit(indep, dep)
array([ 5.,  5., 10., -0.,  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.