BookmarkSubscribeRSS Feed
promo_at_work
Obsidian | Level 7

I noticed that there are two types of residuals and predictions calculated:

  • Structural Model (first stage OLS to detrend data)
  • Total Model (= Structural Model + AR Error Model)

However when examining the predictions and residuals, they don't seem to add up for the first p observations and wanted to clarify how these are calculated

For e.g. in the table below, for obs 1, the total prediction is 0, but the total residuals is -136.85 instead of -243.5 (=DURABLES - predict total)

Obs predict_total residual_total predict_struct residual_struct DATE _TYPE_ _LEAD_ DURABLES
1 0 -136.85 0 -243.5 Jan-80 RESIDUAL 0 -243.5
2 -73.87 5033.78 0 8460.6 Feb-80 RESIDUAL 0 8460.6
3 2642.39 4439 0 10165.7 Mar-80 RESIDUAL 0 10165.7
4 2282.5 708.65 0 3444.8 Apr-80 RESIDUAL 0 3444.8
5 2607.48 -1756.04 0 -233.1 May-80 RESIDUAL 0 -233.1
6 519.1 1444.32 0 2801 Jun-80 RESIDUAL 0 2801
7 12.12 -5722.97 0 -7971.9 Jul-80 RESIDUAL 0 -7971.9
8 906.53 -3244.69 0 -3507.81 Aug-80 RESIDUAL 0 -3507.81
9 3172.29 3045.45 0 7314.29 Sep-80 RESIDUAL 0 7314.29
10 1505.36 5866.55 0 9482.39 Oct-80 RESIDUAL 0 9482.39
11 2800.77 1529.45 0 4860.49 Nov-80 RESIDUAL 0 4860.49
12 2967.3 -625.37 0 2138.59 Dec-80 RESIDUAL 0 2138.59
13 -3093.05 161.77 0 -2898.31 Jan-81 RESIDUAL 0 -2898.31

 

Code to generate this was from following:

 

proc forecast data=sashelp.usecon interval=month
              method=stepar nlags = 0 trend=2 lead=0
              out=out outresid outfull outest=est;
   id date;
   var durables;
   where date >= '1jan80'd;
run;

proc sql;
CREATE TABLE resid AS
SELECT *, 0 AS zer FROM out
WHERE _TYPE_ = 'RESIDUAL';
run;

proc autoreg data=resid;
   model durables = zer/ noint nlag=(1 6 10 12 13) method=yw;
   output out = autoreg_res pm = predict_struct p = predict_total rm = residual_struct r = residual_total;
run;
1 REPLY 1
SASCom1
SAS Employee

For the first NLAG = observations or the first NLAG = observations after missing values, the formula R = Y - P does not apply. For the first NLAG = observations, some Kalman Filtering technique is involved in obtaining the predicted values and residuals, (though for the first observation, P is set to be equal to PM). The following section of the PROC AUTOREG documentation contains some discussion which may give you some idea of the computation:

https://go.documentation.sas.com/doc/en/pgmsascdc/v_011/etsug/etsug_autoreg_details02.htm#etsug.auto...



Scroll down to Computational Methods-->Data Transformation and the Kalman Filter , the first two paragraphs illustrate how to calculate the L, the Cholesky root of V where σ^2 V is Ω=E((Y-Xβ) (Y-Xβ)^'). So, from the estimation of AR parameters φ ̂_1,…,φ ̂_m, the V ̂ could be constructed (constructing covariance matrix Ω ̂ and V ̂=Ω ̂/σ ̂^2), then find the Cholesky root of V ̂, L ̂ such that V^=L^L^'. The residual r=L ̂^(-1) (Y-Xβ ̂). How to construct the covariance matrix Ω ̂ from AR parameters and σ^2 is illustrated in equation 3.4.36 in page 59 of Hamilton (1994. Time Series Analysis. Princeton University Press, Princeton, N.J.). The first NLAG residuals may only need the first NLAG by NLAG block of L ̂^(-1).

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Discussion stats
  • 1 reply
  • 776 views
  • 0 likes
  • 2 in conversation