segreg.model.alt.brute_fit_one_bkpt

brute_fit_one_bkpt(indep, dep, num_end_to_skip=0, dx=0.0001, verbose=False, extra_verbose=False)

Estimate one-bkpt segmented regression model using a brute-force method.

This method is limited to univariate, continuous, linear, one-bkpt segmented regression problems. Estimates the parameters:

[u, v, m1, m2]

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

Notes

This method picks the parameters giving the minimum RSS by brute-force calculation on a grid in the space of bkpt parameter, u. That is, for each choice of bkpt, the method computes the RSS for the segmented fit conditional on that bkpt. The parameters corresponding to the overall minimal RSS from these calculations are returned.

Parameters
  • indep (numpy array of shape (num_data,)) – The independent data. Also called predictor, explanatory variable, regressor, or exogenous variable.

  • dep (numpy array of shape (num_data,)) – The dependent data. Also called response, regressand, or endogenous variable.

  • 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

  • dx (float) – The stepsize for the grid search.

  • verbose (bool) –

  • extra_verbose (bool) –

Examples

>>> import numpy as np
>>> from segreg.model.alt import brute_fit_one_bkpt
>>> indep = np.array([1,2,3,4,5,6,7,8,9])
>>> dep = np.array([1,2,3,4,5,4,3,2,1])
>>> brute_fit_one_bkpt(indep, dep)
(array([ 5.,  5.,  1., -1.]), 0.0)
Returns

  • params (array of shape (num_params,)) – The estimated parameters. The returned parameters are, in order, [u, v, m1, m2].

  • rss (float) – Residual sum of squares of the fit.