How to estimate Prediction error and its variance

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
Post Reply
hardmann
Posts: 262
Joined: Sat Feb 26, 2011 9:49 pm

How to estimate Prediction error and its variance

Unread post by hardmann »

Dear Tom:

I will estimate prediction error and its variance of GDP. I have decomposied the log GDP into trend and cycle components.How can I esitmate prediction error and its variance of GDP. Firstly,computing prediction error and its variance of the trend and cycle components, then summing them?
I refer to the example on page 8 of the SSM DSGE workbook.
as follows:

set trend * forecastl = xstates(t)(1)
set cycle * forecastl = xstates(t)(3)
set p_trend * forecastl = %scalar(vstates(t)(1,1))
set p_cycle * forecastl = %scalar(vstates(t)(3,3))

set trend_lower * forecastl = trend -sqrt(p_trend)*%invnormal(.95)
set trend_up * forecastl = trend +sqrt(p_trend)*%invnormal(.95)
set cycle_lower * forecastl = trend -sqrt(p_cycle)*%invnormal(.95)
set cycle_up * forecastl = trend +sqrt(p_cycle)*%invnormal(.95)

set lgdp_lower * forecastl= trend_lower + cycle_lower
set lgdp_up * forecastl = trend_up + cycle_up

Is right?

Could I use vhat and svhat option in DLM?

While I saw example on Chapter 8 of the Commandeur & Koopman, An Introduction to State Space Time Series Analysis.

dlm(a=a,c=c,sv=sigsqeps,f=f,sw=%diag(||sigsqxi,sigsqomega||),exact,$
y=%if(t<=1983:1,logksi-explan,%na),yhat=yhat,svhat=svhat) / xstates vstates
*
set forecast 1970:1 * = explan+%if(t<=1983:1,%scalar(yhat),%dot(c,xstates))
set fvariance 1970:1 * = %if(t<=1983:1,%scalar(svhat),%qform(vstates,c))
*
set upper = forecast+1.64*sqrt(fvariance)
set lower = forecast-1.64*sqrt(fvariance)

Best Regard
Hardmann
Last edited by hardmann on Mon Sep 28, 2026 4:09 am, edited 1 time in total.
hardmann
Posts: 262
Joined: Sat Feb 26, 2011 9:49 pm

Re: Prediction error and its variance

Unread post by hardmann »

Dear Tom:

My result and graph seem wrong.
please check my code.

Best Reagrd
Hardmann
Attachments
US GDP.xlsx
(11.98 KiB) Downloaded 192 times
US UC 2026Q2 Forecast .RPF
(2.86 KiB) Downloaded 189 times
hardmann
Posts: 262
Joined: Sat Feb 26, 2011 9:49 pm

Re: How to estimate Prediction error and its variance

Unread post by hardmann »

Dear Tom:

I changed the type option from smoothed to filter. When it is smoothed, prediction 1 seems to be incorrect. I read the user guide and SSM workbook. Kalman filter uses YHAT option giving the predictions for Y and SVHAT giving the forecast variance; This Kalman smooths uses the two additional options WHAT and VHAT options to save smoothed estimates of the W and V. Note that in the Kalman filter, the VHAT are (by construction) independent of each other, and so can be used easily for diagnostics. The smoothed estimates are not independent. Can't smothed be applied to prediction?
I tried three methods to estimate the prediction error and its variance. The first and third ones seem to work. The second one cites the code from Chapter 8 of Commandeur&Koopman's "Introduction to State Space Time Series Analysis".
The upper and lower limits of prediction 1 and prediction 3 differ significantly. I don't know which one is correct?

Please help me provide the correct answer.
The attachment is my modified code.

Best Regard
Hardmann
Attachments
US UC 2026Q2 Forecast 0.04.RPF
(4.1 KiB) Downloaded 133 times
TomDoan
Posts: 7826
Joined: Wed Nov 01, 2006 4:36 pm

Re: How to estimate Prediction error and its variance

Unread post by TomDoan »

You can't predict Y using Kalman smoothing because smoothing is conditional on Y (the whole record), hence the SVHAT zeroing out. If TYPE=FILTER, XSTATES and VSTATES are the filtered state and covariance matrix, which means they include Y(t) to generate the values at t. YHAT and SVHAT are the one-step prediction values when you filter, thus using only information through t-1. So you can't use XSTATES and VSTATES to compute YHAT and SVHAT.
hardmann
Posts: 262
Joined: Sat Feb 26, 2011 9:49 pm

Re: How to estimate Prediction error and its variance

Unread post by hardmann »

Dear Tom:

Thank you. I have another question. In some countries, growth rate data is released instead of underlying data. If I use GDP growth rate as an observation indicator, according to the definition, I can only retrieve the GDP index and then calculate the growth rate. How do I calculate the upper and lower limits of a prediction? In this situation, what does yhat represent?

The attachment is my code, please guide me.

Best Regard
Hardmann
Attachments
US UC 2026Q2 Forecast 0.07.RPF
(4.43 KiB) Downloaded 6 times
Post Reply