# How will random effects with only 1 observation affect a generalized linear mixed model?

I have a data set in which the variable I'd like to use as a random effect only has a single observation for some levels. Based on the answers to previous questions, I've gathered that, in principle, this can be fine.

Can I fit a mixed model with subjects that only have 1 observation?

Random intercepts model - one measurement per subject

"...assuming you are not using a generalized linear mixed model GLMM where in that case issues of over-dispersion come into play"

I am considering using a GLMM, but I don't really understand how random effect levels with single observations will affect the model.

Here is an example of one of the models I'm trying to fit. I'm studying birds, and I'd like to model the effects of population and season on the number of stops during migration. I'd like to use individual as a random effect, because for some individuals I have up to 5 years of data.

library(dplyr)
library(lme4)
pop <- as.character(c("BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "BF", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "MA", "NU", "NU", "NU", "NU", "NU", "NU", "NU", "NU", "NU", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA", "SA"))
id <- "2 2 4 4 7 7 9 9 10 10 84367 84367 84367 84368 84368 84368 84368 84368 84368 84369 84369 33073 33073 33073 33073 33073 33073 33073 33073 33073 80149 80149 80149 80150 80150 80150 57140 57141 126674 126677 126678 126680 137152 137152 137157 115925 115925 115925 115925 115925 115925 115925 115925 115926 115926 115926 115926 115926 115926 115927 115928 115929 115929 115929 115930 115930 115930 115930 115931 115931 115931 115932 115932 115932"
id <- strsplit(id, " ")
id <- as.numeric(unlist(id))
year <- "2014 2015 2014 2015 2014 2015 2014 2015 2014 2015 2009 2010 2010 2009 2010 2010 2011 2011 2012 2009 2010 2009 2009 2010 2010 2011 2011 2012 2012 2013 2008 2008 2009 2008 2008 2009 2008 2008 2013 2013 2013 2013 2014 2015 2014 2012 2013 2013 2014 2014 2015 2015 2016 2012 2013 2013 2014 2014 2015 2013 2012 2012 2013 2013 2012 2013 2013 2014 2013 2014 2014 2013 2014 2014"
year <- strsplit(year, " ")
year <- as.numeric(unlist(year))
season <- as.character(c("fall", "spring", "fall", "spring", "fall", "spring", "fall", "spring", "fall", "spring", "fall", "fall", "spring", "fall", "fall", "spring", "fall", "spring", "spring", "fall", "spring", "fall", "spring", "fall", "spring", "fall", "spring", "fall", "spring", "spring", "fall", "spring", "spring", "fall", "spring", "spring", "fall", "fall", "fall", "fall", "fall", "fall", "fall", "spring", "fall", "fall", "fall", "spring", "fall", "spring", "fall", "spring", "spring", "fall", "fall", "spring", "fall", "spring", "spring", "fall", "fall", "fall", "fall", "spring", "fall", "fall", "spring", "spring","fall", "fall", "spring", "fall", "fall", "spring"))
stops <- "0 0 0 0 0 0 1 0 2 1 1 0 0 3 2 0 1 1 0 1 1 2 0 1 0 2 0 4 0 0 2 1 1 2 5 2 1 0 9 6 2 3 4 7 2 0 0 0 0 0 2 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0"
stops <- strsplit(stops, " ")
stops <- as.numeric(unlist(stops))

stopdata <- data.frame(pop = pop, id = id, year = year, season = season, stops = stops, stringsAsFactors = FALSE)

stopdata <- group_by(stopdata, pop, id)
summary1 <- summarise(stopdata, n.years = length(year))
table(summary1$n.years)  There are 27 individuals. 9 individuals have a single observations. 18 individuals have 2-9 observations. What should be concerned about if 1/3 of the random effect levels only have one observation? I've been considering: Option 1: GLMM as described above stops.glmm <- glmer(stops ~ pop + season + (1|id), data=stopdata, family = poisson)  Option 2: Weighted generalized linear model GLM using means for the individuals with multiple observations aggfun <- function(data, idvars=c("pop", "season", "id"), response){ #select id variables, response variable, and year sub1 <- na.omit(data[,c(idvars, "year", response)]) #aggregate for mean response by year agg1 <- aggregate(sub1[names(sub1) == response],by=sub1[idvars],FUN=mean) #sample size for each aggregated group aggn <- aggregate(sub1[response],by=sub1[idvars],FUN=length) #rename sample size column names(aggn)[4] <- "n" agg2 <- merge(agg1, aggn) agg2} #Create weighted dataset stops.weight <- aggfun(data = stopdata, response = "stops") stops.weight$stops <- round(stops.weight$stops) #Weighted GLM stops.glm <- glm(stops~pop + season, data=stops.weight, family = poisson, weights = n)  • Where does the quote come from? I cannot find the corresponding answer. Nov 1 '16 at 23:25 • Second link, first answer, in parentheses Nov 3 '16 at 23:44 • short not-quite-answer: I don't think there would be any problem. Don't know exactly what the first answerer to the second question linked above meant: have you considered leaving a comment there to ask (if you have sufficient rep)? In the limit where you have exactly 1 observation per group then the among-group and residual variability will be completely confounded. I might not bother with mixed models if you had a minority of groups with >1 observation (and a small number in those groups), but your case sounds fine ... Nov 4 '16 at 0:23 • I'm not sure your second option (weighted Poisson) really works correctly, but I'd have to think about it more carefully. Nov 4 '16 at 0:24 • @BenBolker What would you choose to do in the case you describe, where there are only a minority of groups with >1 observation? – mkt Feb 8 '19 at 10:33 ## 2 Answers In general, you have an issue with identifiability. Linear models with a random effect assigned to a parameter with only one measurement can't distinguish between the random effect and the residual error. A typical linear mixed effect equation will look like:$E = \beta + \eta_i + \epsilon_j$Where$\beta$is the fixed effect,$\eta_i$is the random effect for level$i$, and$\epsilon_j$is the residual variability for the$j$th measurement. When you have only one observation of a level with a random effect, it is difficult to distinguish between$\eta$and$\epsilon$. You will (typically) be fitting a variance or standard deviation to$\eta$and$\epsilon$, so with only one measure per individual, you will be not be as certain that you have an accurate estimate for$SD(\eta)$and$SD(\epsilon)$, but the estimate of the sum of the variances ($var(\eta) + var(\epsilon)$) should be relatively robust. On to the practical answer: If you have about 1/3 of your observations with a single observation per individual, you are probably OK overall. The rest of the population should provide a reasonable estimate for$SD(\eta)$and$SD(\epsilon)\$, and these individuals should be minor contributors overall. On the other hand, if you have all individuals at a specific fixed effect and random effect with a single measure (e.g. for your example, perhaps all of a population-- perhaps that means species for you), then you would trust the result less.

This example used poisson distribution, which defaults to link log, right? I'd expect the random effect, even if ALL groups had one observation, to estimate the variance in the log, whereas the residual error would then measure the error in the prediction including the random effect.

Example, 10 observations, first without random effect:

 summary(pp <- glmmTMB(nvn~offset(log(vnhr)),data=foc10,family="poisson"))
Family: poisson  ( log )
Formula:          nvn ~ offset(log(vnhr))
Data: foc10
AIC      BIC   logLik deviance df.resid
111.5    111.8    -54.7    109.5        9
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.14680    0.09129  -12.56   <2e-16 ***


and now with random effect

> summary(pp <- glmmTMB(nvn~offset(log(vnhr))+(1|focal),data=foc10,family="poisson"))
Family: poisson  ( log )
Formula:          nvn ~ offset(log(vnhr)) + (1 | focal)
Data: foc10
AIC      BIC   logLik deviance df.resid
54.1     54.7    -25.0     50.1        8


[ notice much lower AIC ]

 Random effects:
Conditional model:
Groups Name        Variance Std.Dev.
focal  (Intercept) 5.088    2.256
Number of obs: 10, groups:  focal, 10
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept)   -2.692      1.166  -2.309   0.0209 *


In any case, there are no convergence complaints.
Whereas there are if I leave out the poisson.

• Now I begin to think that in a model like this there IS NO RESIDUAL term! Oct 27 '20 at 18:23
• That is, the loglik is computed directly from the random effect, not from a residual. Oct 27 '20 at 18:30