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)
contrast(ref,method="pairwise",adjust="bonferroni")
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?
- What about the warning I received?
- Do you have any suggestions ?
AREA
as both a fixed effect and a random effect ... $\endgroup$