yatsm.regression.recresid module

Recursive residuals computation

Citations:

  • Brown, RL, J Durbin, and JM Evans. 1975. Techniques for Testing the Consistency of Regression Relationships over Time. Journal of the Royal Statistical Society. Series B (Methodological) 37 (2): 149-192.
  • Judge George G., William E. Griffiths, R. Carter Hill, Helmut Lütkepohl, and Tsoung-Chao Lee. 1985. The theory and practice of econometrics. New York: Wiley. ISBN: 978-0-471-89530-5
yatsm.regression.recresid.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