简体   繁体   中英

Why do nested random effects work in nlme but not work in lme4?

A glimse of my data

I want to see the effect of M on Com using linear mixed model, with M as the fixed effect and year nested in plot as random effect. There is no problem if I use lme in package 'nlme'.

fit <- lme(Com ~ M + random = ~ 1|plot/year, data)

But it didn't work in lmer in package 'lme4'.

fit <- lmer(Com ~ M + (1|plot/year), data)

# Error: number of levels of each grouping factor must be < number of observations

However, it works if I only include plot or year in the random effect. Is there any way to solve it?

fit <- lme(Com ~ M + random = ~ 1|plot, data)
fit <- lme(Com ~ M + random = ~ 1|year, data)

nlme is well known to deal with nested random effects and not with interactions whereas on the contrary lme4 deals well with interactions and does not suits well for some things nlme is good for. I think lme4 provides variance component models only whereas nlme allows correlations between observations. Maybe if your nested structure lies within your data you could try fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t) , assuming that years are nested within plots.

fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t) and fit <- lmer(Com ~ M + (1:plot) + (1|plot:year), data = t) are equivalent but the latter formula may be more consistant. You could also compare the results of this command with fit <- lme(Com ~ M, random = ~ 1|plot/year, data) and see if you find the same variance components. I think it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM