-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
See the reproducible example below. The same model works with laplace = FALSE.
library(hmmTMB)
data(energy, package = "MSwM")
dists <- list(Price = "norm")
par0_2s <- list(Price = list(mean = c(3, 6), sd = c(1, 1)))
f <- list(Price = list(mean = ~s(EurDol, k = 10, bs = "cs"),
sd = ~poly(EurDol, 3)))
hid <- MarkovChain$new(data = energy, n_states = 2, initial_state = "stationary")
obs <- Observation$new(data = energy, n_states = 2, dists = dists,
par = par0_2s, formulas = f)
hmm <- HMM$new(obs = obs, hid = hid)
hmm$fit_stan(chains = 1, iter = 2000, laplace = TRUE)leading to the error:
Error in initSanitizer(x) :
Detected initial parameter of the wrong length.
It seems to be a problem with using the option init = "par" when tmbstan() is called in HMM$fit_stan(). There seems to be a mismatch between the parameter vector stored in the model (obs$env$par), which includes random effects, and the parameter vector expected by tmbstan() with laplace = TRUE, which doesn't.
A possible fix would be to replace init = "par" by init = "random" when laplace = TRUE in HMM$fit_stan().
Metadata
Metadata
Assignees
Labels
No labels