Uneven hierarchies

15 views
Skip to first unread message

Jack Draper

unread,
Apr 14, 2025, 2:08:10 PM4/14/25
to nimble-users
I am not even sure how to phrase what I am doing so this may have been asked and answered and I just don't know how to search for it efficiently. I have written a hierarchical model with 4 levels of hierarchy: population<-individual animal<-individual year for that animal<-seasons within that year.  As would be expected, some animals are only recorded in a single year and/or don't have records from every season within a year.  

The for loops to generate the priors are all written with indicator variables to generate a "ragged" output that only generates a prior if that animal existed that year and season. I use $getNodeNames and $getParents to define my monitors and it correctly identifies the data shape. 

However, when I get the posteriors, everything has been squared off and I have posteriors that are all zero filling in what would be the holes in matrices and arrays (I did have to define my initial values with these "ghost values" because I am unaware of a way to define my inital values with uneven structure).

The outputs and estimates of the hyperparameters seem reasonable given my knowledge of the system being modeled and a subjective look at the different levels of the hierarchy feeding into each other. I have two questions. The first and most important is, do these values somehow skew my estimates? And second, how do I prevent them from being extracted? They are not included in my monitors and balloon my output, and provide no value to interpretation.  

John 

Below is my nimble code, I am currently very early in forming this model and focusing on hierarchy structure.

simpleModel <- nimbleCode( {
  mu.R.Individual.I~dnorm(0, sd=2)
  mu.B.Forest.dens~ddexp(0, 1)
  mu.B.Dev.dist~ddexp(0,1)
  mu.B.Dist_Maj_Road~ddexp(0,1)
  for(i in 1:n.bears){
    R.Individual.I[i]~dnorm(mu.R.Individual.I, sd=2)
    B.Forest.dens[i]~ddexp(mu.B.Forest.dens, 1)
    B.Dev.dist[i]~ddexp(mu.B.Dev.dist,1)
    B.Dist_Maj_Road[i]~ddexp(mu.B.Dist_Maj_Road,1)
    for(j in 1:bear.year.index[i]){
      R.Individual.I.y[i,j]~dnorm(R.Individual.I[i], sd=2)
      B.Forest.dens.y[i,j]~ddexp(B.Forest.dens[i], 1)
      B.Dev.dist.y[i,j]~ddexp(B.Dev.dist[i],1)
      B.Dist_Maj_Road.y[i,j]~ddexp(B.Dist_Maj_Road[i],1)
      for(k in 1:3){
        R.Individual.I.y.s[i,j,k]~dnorm(R.Individual.I.y[i,j], sd=2)
        B.Forest.dens.y.s[i,j,k]~ddexp(B.Forest.dens.y[i,j], 1)
        B.Dev.dist.y.s[i,j,k]~ddexp(B.Dev.dist.y[i,j],1)
        B.Dist_Maj_Road.y.s[i,j,k]~ddexp(B.Dist_Maj_Road.y[i,j],1)
      }
    }
  }
  # Likelihood
  for(i in 1:N){
    used[i]~dbern(s[i])
    logit(s[i])<-R.Individual.I.y.s[bear.number[i],bear.year[i], season[i]]+
      B.Forest.dens.y.s[bear.number[i],bear.year[i], season[i]]*Forest.dens[i]+
      B.Dev.dist.y.s[bear.number[i],bear.year[i], season[i]]*Dev.dist[i]+
      B.Dist_Maj_Road.y.s[bear.number[i],bear.year[i], season[i]]*Dist_Maj_Road[i]
  }
})

Perry de Valpine

unread,
Apr 14, 2025, 4:12:46 PM4/14/25
to Jack Draper, nimble-users
Hi John,
Thanks for the question. Monitoring of MCMC output is done on the basis of variables, not nodes. Hence, for better or worse, when a variable is involved in an entry for monitors, you will get the entire variable. The contents of elements that aren't used in the model can be ignored. One way to manage output size is to use monitors2 and thin2 with thin2 > thin to record fewer samples of large variables. But you will still get all elements of the variable (not ragged) in the output. 
HTH
Perry

--
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 visit https://groups.google.com/d/msgid/nimble-users/dd6f87b3-c3c5-43b8-bd2c-5058d21785b4n%40googlegroups.com.

Jack Draper

unread,
Apr 14, 2025, 4:17:52 PM4/14/25
to Perry de Valpine, nimble-users
Thank you for the prompt reply.  I figured/hoped that was the case on both questions. Glad I dont have make things more complicated.  
John

Sent via the Samsung Galaxy S23 5G, an AT&T 5G smartphone
Get Outlook for Android

From: Perry de Valpine <pdeva...@berkeley.edu>
Sent: Monday, April 14, 2025 2:12:28 PM
To: Jack Draper <jjpd...@gmail.com>
Cc: nimble-users <nimble...@googlegroups.com>
Subject: Re: Uneven hierarchies
 
Reply all
Reply to author
Forward
0 new messages