helske / KFAS

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

Problem with one-step-ahead prediction residuals (standardised) when using an intervention variable #42

Closed k41m4n closed 4 years ago

k41m4n commented 4 years ago

I am trying to run the model with an intervention variable. It seems that the output of function rstandard() does not provide correctly one-step-ahead prediction residuals (standardised). Many of them are not available. The script with data file are attached. I am using KFAS ver 1.3.7.

UKdriversKSI.zip

helske commented 4 years ago

This is because you are using a diffuse initialization for the regression coefficient state of the intervention variable. The standardized residuals are not defined for the diffuse phase, which does not end before there is a change in the intervention variable, and thus you only have standardized residual estimates available after the intervention. I suggest that you switch to nondiffuse prior for the intervention variable, e.g.,

model <- SSModel(dataUKdriversKSI ~ 
  SSMtrend(degree=1, Q=list(matrix(0))) + 
  SSMregression(~ seatbeltLaw, Q=matrix(0), P1 = 100, P1inf = 0), H = matrix(NA))
k41m4n commented 4 years ago

Thank you for your prompt reply which was very helpful!