Hey NIMBLE team,
I recently used runCrossValidate() on a model that uses the Dirichlet process (DP). In previous NIMBLE versions, CV worked without any error but having updated NIMBLE to the development version to recheck analysis, I have an error message. Below is the NIMBLE DP example given in the manual and this gives the same error I obtained with my model.
code <- nimbleCode({
z[1:N] ~ dCRP(alpha, size = N)
alpha ~ dgamma(1, 1)
for(i in 1:M) {
thetatilde[i] ~ dnorm(0, var = 100)
s2tilde[i] ~ dinvgamma(1, 1)
}
for(i in 1:N)
y[i] ~ dnorm(thetatilde[z[i]], var = s2tilde[z[i]])
})
set.seed(1)
constants <- list(N = 100, M = 50)
data <- list(y = c(rnorm(50, -5, sqrt(3)), rnorm(50, 5, sqrt(4))))
inits <- list(thetatilde = rnorm(constants$M, 0, 10),
s2tilde = rinvgamma(constants$M, 1, 1),
z = sample(1:10, size = constants$N, replace = TRUE),
alpha = 1)
model <- nimbleModel(code, constants, data, inits)
model$calculate()
foldFunction <- function(i){
foldNodes_i <- paste0('y[i]') # will return 'y[1]' for i = 1 e.g.
return(foldNodes_i)
}
dyesMCMCconfiguration <- configureMCMC(model)
crossValOutput <- runCrossValidate(MCMCconfiguration = dyesMCMCconfiguration,
k = 2,
foldFunction = foldFunction,
lossFunction = "MSE",
MCMCcontrol = list(niter = 5000,
nburnin = 500), silent = T)
The error I obtained is Error in buildMCMC(modelMCMCConf) :
sampler_CRP: At least one variable has to be clustered for each cluster membership ID.
I think this has to do with my initial values for z? Many thanks for the help.
Kind regards,
Fabian