--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/16d7a70c-1ded-4ea8-875a-cebcfb74f699n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/40f7c6ae-7d0e-4192-9ac1-1d96d4c7b6e7n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/CAG%3DM9Lpou8sqxmo5j%2BkRf5e3pTng7E8LoL7-gD8CRP1G7zw7sA%40mail.gmail.com.
nimble:::matrix2mv(posteriorSamplesMatrix,
CmyMCMC$mvSamples)
CmyMCMC$enableWAIC <- TRUE
CmyMCMC$calculateWAIC()
does not do what I thought it was doing, since the WAIC value before and after this code is the same which it should not be. I would suggest replace this with:
calculateWAIC(posteriorSamplesMatrix, CmyModel)
but then the code provided by Michael lacks some parameters (z) for WAIC to be calculated.
This therefore questions me on what does the above code, as well as what does a similar code in runMCMC & so on.
Sincerely,
Frédéric
################################################################
########### Here is the first code (Michael's adapted):
##################################################################
library(nimble)
n.iter <- 100 # non-zero number of iterations
n.burnin <- 2
myModel <- nimbleModel(code = hmm.model,
constants = my.constants,
data = my.data,
inits = initial.values)
CmyModel <- compileNimble(myModel)
myMCMC <- buildMCMC(CmyModel, monitors = parameters.to.save, enableWAIC =
TRUE)
CmyMCMC <- compileNimble(myMCMC)
results <- runMCMC(CmyMCMC, niter = n.iter, nburnin = n.burnin, nchains = 1)
posteriorSamplesMatrix <- results[8:20,]
CmyMCMC$getWAIC()
CmyMCMC$run(5) ## non-zero number of iterations
CmyMCMC$getWAIC()
nimble:::matrix2mv(posteriorSamplesMatrix, CmyMCMC$mvSamples)
CmyMCMC$enableWAIC <- TRUE
CmyMCMC$calculateWAIC()
CmyMCMC$getWAIC()
calculateWAIC(posteriorSamplesMatrix, CmyModel)
## Error with the following message:
# To calculate WAIC in NIMBLE, all parameters of data nodes in the model must be monitored.
# Currently, the following parameters are not monitored: z
#############################################################
##### Second code with saving z:
#######################################################
library(nimble)
parameters.to.save <- c("phi","p","z")
#MCMC model details
n.iter <- 100 # non-zero number of iterations
n.burnin <- 2
myModel <- nimbleModel(code = hmm.model,
constants = my.constants,
data = my.data,
inits = initial.values)
CmyModel <- compileNimble(myModel)
myMCMC <- buildMCMC(CmyModel, monitors = parameters.to.save, enableWAIC =
TRUE)
CmyMCMC <- compileNimble(myMCMC)
results <- runMCMC(CmyMCMC, niter = n.iter, nburnin = n.burnin, nchains = 1)
posteriorSamplesMatrix <- results[8:20,]
CmyMCMC$getWAIC()
CmyMCMC$run(5) ## non-zero number of iterations
CmyMCMC$getWAIC()
nimble:::matrix2mv(posteriorSamplesMatrix, CmyMCMC$mvSamples)
CmyMCMC$enableWAIC <- TRUE
CmyMCMC$calculateWAIC()
CmyMCMC$getWAIC()
calculateWAIC(posteriorSamplesMatrix, CmyModel)
##OK
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/b0c4ffd7-6ae1-40d3-9b44-dbb3f58e5497n%40googlegroups.com.