R KFAS Ar(1) Model

67 views Asked by At

I am using the latest KFAS package and it's SSMarima method to build an AR(1). I followed the instruction given in this https://www.jstatsoft.org/article/view/v078i10. Below is my code snippet.

However, after running the fitSSM method, i am getting the error "Error in is.SSModel(do.call(updatefn, args = c(list(inits, model), update_args)), : Matrix P1 contains nonzero diagonal elements for diffuse states." My dataset is a weekly dataset of 52 data points. Any help please?

`model_arima <- SSModel(ssm_total_vol$total_vol ~ SSMarima(ar = 0, d = 1, Q = 1))

update_model <- function(pars, model) {
  tmp <- SSMarima(ar = pars[1], d = 0, Q = pars[2])
  model["R", states = "arima"] <- tmp$R
  model["Q", states = "arima"] <- tmp$Q
  model["P1", states = "arima"] <- tmp$P1
  model
  }

fit_arima <- fitSSM(model_arima, inits = c(0, 1), updatefn = update_model,
                    method = "L-BFGS-B")`
1

There are 1 answers

0
Jouni Helske On

You have d=1 in your initial model definition (indicating differences), but d=0 in the update_model function.