helske / KFAS

KFAS: R Package for Exponential Family State Space Models
64 stars 17 forks source link

Error: $ operator is invalid for atomic vectors #58

Closed Vera1996 closed 3 years ago

Vera1996 commented 3 years ago

Dear Helkse,

I want to predict values from my fitted SSModel. However, I get the error $ operator is invalid for atomic vectors and I don't know how to fix this. My code is correct when I compare this to the code in the manual and KFAS Exponential Families. Can you please help me? My model works until I use the predict function, then I get the error.

fit <- fitSSM(model, updatefn = updatefn, inits = fitinit$optim.out$par, method = "BFGS", nsim = 1000, hessian = TRUE) observation_sim <- simulateSSM(fit$model, type = "observations", nsim = 1000, conditional = FALSE) pred <- predict(fit$model, newdata = observation_sim ,interval="prediction", level=0.9)

This is one of the last steps in my thesis and I hope you can help! Thanks a lot!

helske commented 3 years ago

Argument newdata should be an SSModel object, not an array of simulated values like in your code. Check examples in ?predict.SSModel

Vera1996 commented 3 years ago

Thanks a lot! That works better but I get 151 new observations with exactly the same pattern. I want to forecast 10 or 20 steps ahead. How can I tackle this problem?

helske commented 3 years ago

Please read the documentation, the instructions are there. There is also a complete example in the KFAS paper (https://www.jstatsoft.org/article/view/v078i10)