Hi Zoey,
Thanks for the question. It's a good one. Oh, Daniel just gave a good reply as well! I have another suggestion for you that might work nicely, but let me walk through a bit more of what is happening.
The typical steps are nimbleModel -> configureMCMC -> buildMCMC -> compile model and MCMC -> runMCMC.
buildMCMC will do configureMCMC if you skip that step. All are done inside of nimbleMCMC.
At configureMCMC, the samplers are set up based on the current tags of what is data that are in the model. Hence, if you use setData to change what is tagged as data, you will generally need to re-create and re-compile the MCMC again. (There are some ways that buildMCMC also uses the data tags, but in any case it comes after configureMCMC).
I think you should be able to do this without recompiling the *model* again, which is some help. That is, you should be able to do:
m <- nimbleModel(...)
cm <- compileNimble(m)
MCMC1 <- buildMCMC(m)
cMCMC1 <- compileMCMC(MCMC1, project = m)
## change what is data in m using resetData and setData, checking with isData.
MCMC2 <- buildMCMC(m)
cMCMC2 <- compileMCMC(MCMC2, project = m) # Possibly use resetFunctions = TRUE
I'd suggest trying this in a toy model first to be sure it all works and does what you want.
If you have a limited set of cases and the above doesn't work, you should be able to hold off on compiling the MCMCs and do them together:
cMCMClist <- compileMCMC(MCMC1, MCMC2, project = m)
Here is another option that should work in many cases and I think would achieve what you want. You could make the model with NAs anywhere you'll ever need them. The MCMC configuration object (returned by configureMCMC) will have methods printSamplers() or getSamplers() that will show you the order in which they are listed. You'll need that. Specifically you'll need to see which samplers are for the NAs, so you can omit them when you want to treat those nodes as data. Then go through compiling that MCMC. Then inspect and modify the sampler execution order list:
cMCMC$samplerExecutionOrderFromConfPlusTwoZeros
This will be a vector of integers from 1 to the number of samplers, with two 0s at the end for internal purposes. Always keep those two zeros.
You can modify that as you please and assign it back into cMCMC$samplerExecutionOrderFromConfPlusTwoZeros. If you omit a sampler that you don't want, it will not be used.
For example:
samplerToSkip <- 101 ## If sampler 101 has target node y[1] and you do not want to sample y[1] as an NA,
cMCMC$samplerExecutionOrderFromConfPlusTwoZeros <- cMCMC$samplerExecutionOrderFromConfPlusTwoZeros[-samplerToSkip]
Be sure to put the data values you want into the compiled model
cm$y[1] <- data_for_y1
Let us know if it works or brings up more questions.
-Perry