# How compute the Intra-Class Correlation for a Negative Binomial Mixed Model in lme4

I have a negative binomial mixed model with counties nested within states. I've read that the formula for the ICC for a negative binomial model is:

When I run VarCorr(m10), on my random intercept model, I get:
Groups Name Std.Dev. state (Intercept) 0.22709

Could someone explain how to extract the other information from my glmer() model so that I can write a function to compute the ICC? e.g., fixef(m10) gets me the intercept term.

• It seems that in your model you did not estimate several of the terms that are referenced in the ICC equation. The equation refers to several different variance components but you only have a single random intercept term. Sep 1, 2015 at 21:48

This is my functional code (using glmer.nb()):

ICC.NB <- function(model){
sigma_a2 <- as.numeric(exp(data.frame(VarCorr(model))["vcov"]))
beta <- as.numeric(fixef(model)["(Intercept)"])
r <- getME(model,"glmer.nb.theta")
icc <- (exp(sigma_a2) - 1) / ((exp(sigma_a2) - 1) + ((exp(sigma_a2) - 1) / r) + (exp(-beta - (sigma_a2 / 2))))
icc
}
ICC.NB(model = m12)

• I think there are some ways to make this less fragile and more readable, e.g. use ["vcov"] in place of  in the sigma extraction; use "(Intercept)" instead of  to get the intercept; use getME(model,"glmer.nb.theta")) instead of the big ugly gsub call ... Sep 1, 2015 at 20:55
• @BenBolker , I edited the post and implemented your suggested changes. Thank you. Sep 1, 2015 at 21:03
• don't forget to test them ... :-) Sep 1, 2015 at 21:09
• PS I think the as.numeric()s are unnecessary? Sep 1, 2015 at 21:10
• Good idea. Now, I'm trying to add a "var" parameter to make it work with a three level model by setting what the sigma should be. Sep 1, 2015 at 21:12