Skip to content
Prev 19114 / 20628 Next

A three-level GLMM with binomial link in R

On 3/11/21 1:11 PM, Hedyeh Ahmadi wrote:
So far I can't replicate this.  It seemed fishy to me that family was an 
integer (I would try explicitly converting it to a factor), but doesn't 
actually cause any problems in my example.

  (This differs from your example but not in ways I would expect to be 
important: in particular, the types of the grouping variables are the 
same [chr, int, chr]

n <- 10000
set.seed(101)
dd <- data.frame(y=rnorm(n),
                  x1=rnorm(n),
                  x2=rnorm(n),
                  x3=rnorm(n),
                  site=sample(paste0("s",1:15),size=n,replace=TRUE),
                  family=sample(1:100,size=n,replace=TRUE),
                  id=sample(paste0("id",1:20),size=n,replace=TRUE))
library(lme4)
lmer(y~1 + x1 + x2 + x3 + (1|site/family/id), data=dd)

###

What is meant by "adding grouping factor to data frame explicitly" would 
be in this case expanding out the nested terms:

  dd <- within(dd,
{
     site_family <- interaction(site,family)
     site_family_id <- interaction(site,family,id)
})

lmer(y~1 + x1 + x2 + x3 + (1|site) + (1|site_family) + 
(1|site_family_id), data =dd)
I'm not sure either.
It seems surprising.
   Is there any way we can get a reproducible example?  For example, 
suppose you randomize your X1, X2, X3 and anonymize all of your grouping 
variables: would you then be able to share the data set?

   Does the problem (let's say just the first problem) still occur if 
you leave out the fixed effects? (I would expect so, and that would 
simplify things somewhat - we're trying to get to the *simplest* example 
that still demonstrates the problem.)