0

I am trying to model counts distribute across groups in JAGS, but I need to add a random effect for the presence of multiple counts from the same individual.

The model is taken from here enter link description here I am stuck, so I would greatly appreciate any help with this.

# File name "count model.jags"

model {
    #Likelihood
    for (i in 1:nGroups) {
        obs[i] ~ dbin(p[i],n[i])
        p[i] ~ dbeta(a[i],b[i])
        a[i] ~ dgamma(1,0.01)
        b[i] ~ dgamma(1,0.01)
    } 
} # end of model
8
  • I am sorry. I was not aware of this rule. Commented Dec 23, 2024 at 7:18
  • To be quite frank, this rule makes no sense at all. Whenever we are to quote something from an outside source, we need to share the link in order to avoid plagiarism. So if this rule exists indeed, then it forces us to choose between not quoting (really bad) or plagiarism (really, REALLY bad). Can you point out where the rule you referred to exists @Luuk ? Commented Dec 24, 2024 at 9:58
  • @Luuk sure, a link description is an improvement and may be mandatory, in which case we can edit the question which omitted it and provide a meaningful description. Commented Dec 24, 2024 at 10:24
  • @LajosArpad: Sure, next time I will stop editing the question and only choose: The question is unclear (Because how can a link to https://https:... be clear ? ) I just rolled back my edit. Commented Dec 24, 2024 at 11:04
  • @Luuk if you read the question you are editing, then you may be able to infer what the likely description is based on the context into which the link was embedded or based on the content of the page. In our case, it's https:www.flutterbys.com.au/stats/tut/tut11.2b.html which has the title of Tutorial 11.2a - Generalized linear mixed effects models which would serve excellently as a link description. Commented Dec 24, 2024 at 11:36

1 Answer 1

2
+200

To incorporate random effects for repeated measurements from the same individual in your binomial model, you'll need to add a hierarchical structure. Here's how you can modify your JAGS model:

model {
  # Likelihood
  for (i in 1:nObs) {  # Loop over all observations
    obs[i] ~ dbin(p[i], n[i])
    logit(p[i]) <- beta0 + beta[group[i]] + u[individual[i]]  # Linear predictor with random effect
  }
  
  # Random effects for individuals
  for (j in 1:nIndividuals) {
    u[j] ~ dnorm(0, tau.u)  # Individual random effects
  }
  
  # Group-level effects
  for (k in 1:nGroups) {
    beta[k] ~ dnorm(0, 0.001)  # Group effects
  }
  
  # Hyperpriors
  beta0 ~ dnorm(0, 0.001)      # Global intercept
  tau.u ~ dgamma(0.001, 0.001) # Precision for random effects
  sigma.u <- 1/sqrt(tau.u)     # Convert to standard deviation
}

Your data structure should look like this:

data <- list(
  nObs = length(obs),
  nIndividuals = length(unique(individual_ids)),
  nGroups = length(unique(group_ids)),
  obs = observed_counts,
  n = trials,
  individual = individual_ids,
  group = group_ids
)

This approach properly accounts for within-individual correlation while maintaining your group structure. The random effects capture individual-specific deviations from the group-level effects.


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.