yatsm.regression package

Module contents

yatsm.regression.design_to_indices(design_matrix, features)[source]

Return indices of coefficients for features in design matrix

Parameters:
  • design_matrix – OrderedDict containing design features keys and indices of coefficient matrix as values
  • features – list of feature coefficients to extract
Returns:

list of indices and names for each feature specified in

features

Return type:

tuple

yatsm.regression.find_packaged_regressor(name)[source]

Find location of a regression method packaged with YATSM

See packaged_regressions for a list of available pre-packaged regressors

Parameters:

name – name of packaged regression object

Returns:

path to packaged regression method

Return type:

str

Raises:
  • KeyError – raise KeyError if user specifies unknown regressor
  • IOError – raise IOError if the packaged regressor cannot be found
yatsm.regression.recresid(X, y, span=None)[source]

Return standardized recursive residuals for y ~ X

For a matrix \(X_t\) of \(T\) total observations of \(n\) variables, the \(t\) th recursive residual is the forecast prediction error for \(y_t\) using a regression fit on the first \(t - 1\) observations. Recursive residuals are scaled and standardized so they are N(0, 1) distributed.

Using notation from Brown, Durbin, and Evans (1975) and Judge, et al (1985):

\[ \begin{align}\begin{aligned}w_r = \frac{y_r - \boldsymbol{x}_r^{\prime}\boldsymbol{b}_{r-1}} {\sqrt{(1 + \boldsymbol{x}_r^{\prime} S_{r-1}\boldsymbol{x}_r)}} = \frac {y_r - \boldsymbol{x}_r^{\prime}\boldsymbol{b}_r} {\sqrt{1 - \boldsymbol{x}_r^{\prime}S_r\boldsymbol{x}_r}}\\r = k + 1, \ldots, T,\end{aligned}\end{align} \]

where \(S_{r}\) is the residual sum of squares after fitting the model on \(r\) observations.

A quick way of calculating \(\boldsymbol{b}_r\) and \(S_r\) is using an update formula (Equations 4 and 5 in Brown, Durbin, and Evans; Equation 5.5.14 and 5.5.15 in Judge et al):

\[\boldsymbol{b}_r = b_{r-1} + \frac {S_{r-1}\boldsymbol{x}_j (y_r - \boldsymbol{x}_r^{\prime}\boldsymbol{b}_{r-1})} {1 + \boldsymbol{x}_r^{\prime}S_{r-1}x_r}\]
\[S_r = S_{j-1} - \frac{S_{j-1}\boldsymbol{x}_r\boldsymbol{x}_r^{\prime}S_{j-1}} {1 + \boldsymbol{x}_r^{\prime}S_{j-1}\boldsymbol{x}_r}\]

See the recursive residuals implementation that this follows, recursive_olsresiduals, within the statsmodels.stats.diagnostic module.

Parameters:
  • X – 2D (n_features x n_obs) design matrix
  • y – 1D independent variable
  • span – minimum number of observations for initial regression. If span is None, use the number of features in X
Returns:

array containing recursive residuals standardized by

prediction error variance

Return type:

np.ndarray

yatsm.regression.bisquare(resid, c=4.685)[source]

Returns weighting for each residual using bisquare weight function

Parameters:
  • resid – residuals to be weighted
  • c – tuning constant for Tukey’s Biweight (default: 4.685)
Returns:

weights for residuals

Return type:

weight (ndarray)

Reference:
http://statsmodels.sourceforge.net/stable/generated/statsmodels.robust.norms.TukeyBiweight.html