# Mixed model ANOVA - multiple measurements

I am dealing with multiple measurements of the same variable in different subject in three geographical areas. Unfortunately, the number of measurements of the variable differs among subjects. My data set looks like this:

#AREA  ID  VARIABLE
#A   Z13.1  4.5
#A   Z13.1  5.7
#A   Z13.1  7.6
#A   Z15.2  5.1
#A   Z15.2  3.9
#B   T15.3  2.1
#B   T15.3  9.1
#B   T20.6  1.1
#B   T20.6  3.2
#B   T20.6  4.3
...


In my opinion, the best option for analysing such a data set would be a mixed model ANOVA, in order to take into account the variability within each area (random variability among subjects from the same area, the random factor) and the variability between areas (the fixed factor, the area). After checking the normality of the data set and the homogeneity of the variance, as far as I understood the proper mixed model would be the following (using afex and lsmeans in R):

model1 <-  lmer(VARIABLE ~ AREA + (1|AREA/ID), data= my_data)
summary(model1)
anova(model1)
ref <- lsmeans(model1, specs = c("AREA"))
ref_df <- as.data.frame(summary(ref))
pd <- position_dodge(0.1)
g4 <- ggplot(ref_df, aes(x=AREA, y=lsmean))+
geom_errorbar(aes(ymin=lsmean-SE, ymax=lsmean+SE), width=.1,position=pd)+
geom_line(position=pd)+
geom_point(position=pd)+theme_classic()
print(g4)


If I got it right the Subject (random factor) is nested in Area (fixed factor). Of note when I run such analysis I get this warning:

Model may not have converged with 1 eigenvalue close to zero: 5.0e-09

• Am I right with the mixed model? Are the factors placed properly?
• Do you have any suggestions ?
• it doesn't make sense to include AREA as both a fixed effect and a random effect ... – Ben Bolker Dec 29 '18 at 14:47
• So @BenBolker is lmer(VARIABLE ~ AREA + (1 | ID), data = my_data) correct? – Luca Dec 29 '18 at 15:24

• your model seems correct, except that you should use VARIABLE ~ AREA + (1|ID): you shouldn't include the same variable as both a fixed and a random effect (except in some special cases); in any cases, three areas would probably not be enough to practically fit a random effect in any case (without regularization/Bayesian priors), and wouldn't allow you test differences among specific areas (as in your post-hoc pairwise comparisons).
• you might want to move from lsmeans to emmeans (almost identical, but slightly more up-to-date); I'd also recommend Tukey rather than Bonferroni adjustment unless you have particular reasons ...