Hello All,
I've created a simple state-space model (see below) that estimates correctly. But when I use the checkConsistency function, I get the error message :
Error in x$reverse.update(value, j) : Implicit simulation failed.
Cannot update operands of '(x - mean)[1L]' when both are missing
Would anyone know why this occurs? Any hint would be appreciated.
Thanks,
Gary Nelson
#Create Data
len <- 500
u1 <- numeric(len + 1)
psd <- 0.1 #process error
for(i in 1:len) u1[i+1] <- u1[i] + rnorm(1, 0, psd)
series <- numeric(len)
osd<- 0.1 #observation error
series<- u1[2:(len+1)] + rnorm(len, 0, osd)
#Setup information
datar<-data.frame(series=series)
parameters<-list(logpe = log(0.1), logoe = log(0.1),
u=rep(0, length(series)+1))
map <- list(u=as.factor(c(NA,1:length(series))))
#Objective function
estimate<-function(parms){
RTMB::getAll(datar,parms,warn=FALSE)
series<-RTMB::OBS(series)
psd<-exp(logpe)
osd<-exp(logoe)
nll<-0
for(i in 2:length(u)){
nll <-nll-RTMB::dnorm(u[i], u[i-1], psd, TRUE)
}
for(i in 1:length(series)){
nll <- nll-RTMB::dnorm(series[i],u[i+1], osd, TRUE)
}
ADREPORT(psd)
ADREPORT(osd)
nll
}
#Fit model
model <- RTMB::MakeADFun(estimate,parameters,map=map,random="u")
fit<-try(nlminb(model$par, model$fn, model$gr,control=nlminb.control),silent=T)
RTMB::checkConsistency(model)