Initial distributions used with nimbleMCMC

25 views
Skip to first unread message

blanca sarzo

unread,
Nov 13, 2022, 7:16:40 AM11/13/22
to nimble-users
Good afternoon,
I am running a CJS model with individual effects using nimbleMCMC function. For one of the parameters I do not have given an initial distribution but I would like to know which one has used NIMBLE internally. Is there any way to extract this information?

Thanks,
Blanca

Matthijs Hollanders

unread,
Nov 13, 2022, 3:10:30 PM11/13/22
to blanca sarzo, nimble-users
Hi Blanca,

I'm not entirely sure, but when using nimbleMCMC you can probably set the thinning rate to 1 and just look at the first value of the MCMC chain.

Regards,

Matt

--
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/896aa6c5-374b-45c2-8e3b-53a17bbe6c81n%40googlegroups.com.

blanca sarzo

unread,
Nov 14, 2022, 4:19:35 AM11/14/22
to Matthijs Hollanders, nimble-users
Hi Matt,

Thanks so much, I will try it!

Blanca

Blanca Sarzo
PhD Statistics
Postdoctoral fellow
Department of Microbiology and Ecology, University of Valencia
School of Mathematics, University of Edinburgh



On 13 Nov 2022, at 20:10, Matthijs Hollanders <matthijs....@gmail.com> wrote:



Jose Jimenez Garcia-Herrera

unread,
Nov 14, 2022, 4:28:30 AM11/14/22
to blanca sarzo, Matthijs Hollanders, nimble-users

Dear Blanca,

 

Maybe you can try as well the approach suggested by Olivier Gimenez here: https://gist.github.com/oliviergimenez/e41e9cb99174f2124f948308e19ca7ec

 

Best regards

 

--

José Jiménez, Ph.D.

Unit of Ecology and Animal Science

Instituto de Investigación en Recursos Cinegéticos - IREC (CSIC-UCLM-JCCM)

University of Castilla la Mancha

Ronda de Toledo nº12, 13005 Ciudad Real, Spain

      Tel: +34 926 295 450 ext. 3388

      Fax: +34 926 295 451

https://www.researchgate.net/profile/Jose_Jimenez12

https://github.com/JoseJimenezGH/Curso_SCR_Mexico

Wei Zhang

unread,
Nov 14, 2022, 4:35:16 AM11/14/22
to Jose Jimenez Garcia-Herrera, blanca sarzo, Matthijs Hollanders, nimble-users
Hi Blanca,

I guess you refer to the initial value of a parameter in the CJS model. nimble will generate initial values for stochastic nodes that are not initialized from their prior distributions, as long as their random generation functions are available. Hope this helps.

Best wishes,
Wei 

Blanca Sarzo

unread,
Nov 14, 2022, 7:10:23 AM11/14/22
to Wei Zhang, Jose Jimenez Garcia-Herrera, Matthijs Hollanders, nimble-users

Many thanks for your suggestions and comments, they have been quite useful.

Blanca

El 14/11/22 a las 9:35, Wei Zhang escribió:
-- 
Blanca Sarzo Carles
PhD Statistics
Postdoctoral fellow
Department of Microbiology and Ecology, University of Valencia
School of Mathematics, University of Edinburgh

Chris Paciorek

unread,
Nov 15, 2022, 3:41:15 PM11/15/22
to Blanca Sarzo, nimble-users
Hi Blanca,

If you look at the values after the first iteration is over, those won't be the initial values in many cases. I think your best bet is to run an uncompiled version of the MCMC, but using the same random number seed as in your current code. You won't be able to use nimbleMCMC because it uses the compiled MCMC, which is harder to work with.

You'll need to set up the model and build the MCMC. Then you can call `runMCMC` with the R debugger turned on. You'll be able to step through the R code for the  initialization steps that NIMBLE carries out. It would look something like this:

set.seed(seedValue)    # seedValue should be whatever seed you are using for nimbleMCMC
m <- nimbleModel(code, ...)
mcmc <- buildMCMC(m)
debug(mcmc$run)
runMCMC(mcmc, niter = 1)   # runMCMC calls mcmc$run to do the actual MCMC computations, including initialization
# then step through the code using the R debugger and look at the values in the model after `my_initializeModel$run()` has been run.

-Chris


Perry de Valpine

unread,
Nov 15, 2022, 3:51:38 PM11/15/22
to paci...@stat.berkeley.edu, Blanca Sarzo, nimble-users
With compiled or uncompiled, I think if you do mcmc$run(niter = 0), then all the initialization will be done but no iterations will be run.  You can then inspect the model object, e.g. model$variable, to see the results of initialization.

As Wei explained, when a variable is not included in inits, then initial values for nodes in that variable will be generated by simulation from their priors.  This will be done in the order of calculations in the model (i.e. topologically sorted order).

Perry





Blanca Sarzo

unread,
Nov 16, 2022, 6:16:37 AM11/16/22
to Perry de Valpine, paci...@stat.berkeley.edu, nimble-users

Many thanks all of you, it has been very useful! I will try all your suggestions, thanks.

Blanca

El 15/11/22 a las 20:51, Perry de Valpine escribió:
Reply all
Reply to author
Forward
0 new messages