Derived quantities using MLE in NIMBLE?

57 views
Skip to first unread message

Gates Dupont

unread,
Sep 8, 2023, 10:33:28 AM9/8/23
to nimble-users
Hi all,

I was reading the tutorial on MLE with NIMBLE and wondered if it's possible to estimate a derived quantity in this framework?

For example, I have this model:

  # ---- Likelihoods ----
 
  for(i in 1:n) {
   
    # Model 1 likelihood
    occurrence[i] ~ dbern(p1[i])
    logit(p1[i]) <- int_m1 + (beta_m1_year * year[i])
   
    occurred[i] ~ dbern(p1[i])
   
    # Model 2 likelihood
    count[i] ~ dpois(lambda2[i] * occurred[i])
    log(lambda2[i]) <- int_m2 + (beta_m2_year * year[i])
   
  }

  

And right now, using MCMC, I can easily calculate this derived quantity, below, too.
 
  # ---- Derived quantities ----
 
  for(t in 1:nyears){
   
    logit(p[t]) <- int_m1 + (beta_m1_year * years[t])
    log(lambda[t]) <-  int_m2 + (beta_m2_year * years[t])
    avg_abd[t] <- p[t] * lambda[t]
   
  }


Might this derived-quantity-estimation be possible with the NIMBLE MLE approach? 

This is a simple example of a much more complex model I'm working on (including random effects with hundreds of levels),  which I need to run for 40 species across 13 sites (520 models), and so the classic Bayesian approach would take too long. I'm also considering trying out nimbleHMC to see if that makes the model more feasible in terms of run time, or maybe switching to stan, which I haven't used. Also considering the subsampling approach from King et al. 2022. Not sure which direction has the best chances of letting me custom-code a model and also have derived quantities. Any advice would be much appreciated before I go down one of these rabbit holes!

Many thanks,
Gates

Wei Zhang

unread,
Sep 8, 2023, 12:44:43 PM9/8/23
to Gates Dupont, nimble-users
Hi Gates,

A quick suggestion is to try nimble's Laplace approximation (function 'buildLaplace') to do mle and then return the Hessian matrix of model parameters (call the summary method). Then you can write a nimbleFunction about your derived quantities for which you can get the gradient using AD. Then you can estimate the std errors using the delta method given the gradients and the Hessian. I know all these can be done easily in TMB using the report macro, but you need to write models in C++. 

If you have any questions on trying nimble Laplace feel absolutely free to let me know. 

Best wishes,
Wei

--
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/e6383525-0b94-4258-b4f6-9ecd67ca1465n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages