0

I'm trying to create a dlm for a timeserie, to forecast unemploymentQ47 values in 2018 and 2019. However when i'm making a checkresiduals, i'm getting the following Error: Error in resi[1:(n - x)] : only 0's may be mixed with negative subscripts.

I think the problem is, that my code is trying to force positive and negative indices when subsetting - but i aint sure, and if that is the case; then i aint sure what i'm doing wrong (in the code) and therefore how to fix it.

Code below:

library(tidyverse)
library(dLagM)
library(car)
library(forecast)

unemploymentQ1 <- c(217.4094564, 178.7939251, 274.6398281, 317.9067375, 354.3497359, 442.3060048, 525.0264607, 531.7866978, 693.6163208, 1215.780892, 1185.383829, 1114.481227, 1188.530867) 
unemploymentQ47 <- c(56.14192219, 77.8410073, 131.4395539, 153.9413853, 159.4512142, 180.6444622, 191.8790669, 184.7989505, 238.898338, 434.8695034, 392.8650138, 0,0 )
year <- c(2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019)


ufm.tbl<- data.frame(year, unemploymentQ1, unemploymentQ47) %>% 
filter(year <= 2017) %>% 
select(-year)


for (i in 1:4){
model1 <- dlm(x = ufm.tbl$unemploymentQ47, y = ufm.tbl$unemploymentQ1, q = i)
cat("q =", i, "AIC =", AIC(model1$model), "BIC =", BIC(model1$model), "MASE =", MASE(model1)$MASE, 
"\n")
}

finite_dlm <- dlm(x = as.vector(ufm.tbl$unemploymentQ47), y = (ufm.tbl$unemploymentQ1), q = 4)
summary(finite_dlm)

vif(finite_dlm$model)


residualcheck <- function(x){
checkresiduals(x)
bgtest(x)
shapiro.test(x$residuals)
}

residualcheck(finite_dlm$model)

Possible related:

Thanks in anvanced,

best,

Agner
  • 1
  • 1
  • your code stops at line 8. with the following error: `Error in dlm(x = ufm.tbl$unemploymentQ47, y = ufm.tbl$unemploymentQ1, : Component(s) m0, C0, FF, V, GG, W is (are) missing`. I can't reproduce your code. – Edo Aug 11 '20 at 13:50
  • Hmmm I just ran it again - copy/paste the code from here - and it worked fine... I could be the packages. I'm have edited the code to inc. packages – Agner Aug 11 '20 at 14:17

0 Answers0