I'm trying to do Pseudo out-of-sample forecasting using R. And, I also have the following initial data (gdp)

Time    gdp
2004Q1  1.0
2004Q2  1.0
2004Q3  0.9
2004Q4  1.9
2005Q1  0.2
2005Q2  -0.2
2005Q3  0.9
2005Q4  0.4
2006Q1  2.3
2006Q2  0.5
2006Q3  0.8
2006Q4  1.0
2007Q1  1.8
2007Q2  1.6
2007Q3  0.7
2007Q4  1.8
2008Q1  -0.4
2008Q2  -0.7
2008Q3  0.0
2008Q4  -1.8
2009Q1  -6.8
2009Q2  -0.5
2009Q3  0.8
2009Q4  -0.2
2010Q1  0.4
2010Q2  2.8
2010Q3  -0.4
2010Q4  2.1
2011Q1  0.5
2011Q2  -0.3
2011Q3  0.3
2011Q4  0.1
2012Q1  0.0
2012Q2  -1.6
2012Q3  -0.3
2012Q4  -0.6
2013Q1  -0.1
2013Q2  0.4
2013Q3  0.3
2013Q4  -0.4
2014Q1  -0.7
2014Q2  0.0
2014Q3  0.3
2014Q4  0.0
2015Q1  -0.6
2015Q2  1.2
2015Q3  0.0
2015Q4  0.6
2016Q1  1.2
2016Q2  0.3
2016Q3  1.1
2016Q4  0.4
2017Q1  1.0
2017Q2  0.5
2017Q3  0.4
2017Q4  0.6
2018Q1  0.9
2018Q2  0.4
2018Q3  0.3
2018Q4  0.8

I have already figured out how write code for simple AR(1) model i.e. GDP_t= beta_0+beta_1*GDP_{t-1}. Also, in the future I'm planning to expand this AR(1) model with some additional factors so I used lm() function.

#data manipulation
gdpgrowth <- gdp[,2]
gdpgrowth_level <- as.numeric(gdpgrowth[-1])
gdpgrowth_lags <- as.numeric(gdpgrowth[-N])

#AR(1) model
armod <- lm(gdpgrowth_level ~ gdpgrowth_lags)

However, Pseudo out-of-sample (for loop) has prove to be quite burdensome. I'm trying to use 20% of my GDP sample as a training sample. In other words, it has 60 rows (60*0,2)=12 rows. Thus, 48 rows are out-of-sample. Therefore, my initial code for the Pseudo out-of-sample loop is the following:

#Pseudo out-of-sample
forecasts = list(length = 48)
for (i in 1:48) {
forecasts[i]<-lm(gdpgrowth_level[i:(12+i)] ~ gdpgrowth_lags[i:(12+i)])

However, the forecasts do not seem to be correct when comparing them to actual GDP data. Is the AR(1) model and the loop correctly specified?

Thanks for any help in advance!


When you have 12 actual values and an AR(1) model & coefficient the prediction for the 13th period is straightforward. From the same origin (the 12th period) the prediction for the 14th period assumes that the value of the 13th period is the 1 period out prediction. This bootstrapping process continues until the 60th period.

Note that the actual for any period beyond 12 is NEVER used thus the stream of forecasts is invariant.

Compare this to estimating the ar(1) coefficient based upon 60 values. In this case the one period out predictions (fitted values) premises the actual value in the prior period and consequently will deliver more visually reasonable predictions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.