Multiple random effects in a linear mixed model with nlme and lme4

可紊 提交于 2021-01-29 06:17:40

问题


I would like to study differences in fat between 2 visits with a linear mixed effects model. So everything would start as lme(fat~, now... for the coefficients, I have some that will change from visit 1 to visit 2, as they are hypertension status, diabetis status, bmi, waist circunference, smoking_status etc. And other variables that won't change from visit 1 to visit 2, as they are gender or ethnicity.

Note that the following variables are dummy (hypertension status, diabetis status, smoking_status, gender) while the following are continuous (bmi, waist circunference, age).

My initial model using nlme package was expressed as:

lme(fat~ diabetes_status + hypertension_status + bmi + waist + smoker + gender + ethnicity, random= ~1|PatientID/Visit, data = df_1, na.action = na.omit)

visit has 2 levels (1 and 2)

However, I have been told that those variables which change over time should be random effects while all the others should be fixed. In another question from stackoverflow (specifying multiple separate random effects in nlme) I read that nlme is not good for specifying crossed effects (aka, multiple separated random effects) and that lme4 package would handle this best.

I tried multiple ways of doing this:

attempt_1 = lmer(fat ~ gender + ethnicity + (1|diabetes_status) + (1|hypertension_status) + (1|PatientID/visit), data=df_1, REML=TRUE)

attempt_2 = lmer(fat ~ gender + ethnicity + (1|diabetes_status) + (1|hypertension_status) + (1|PatientID/visit), data=df_1, REML=FALSE)

attempt_3 = lmer(fat ~ gender + ethnicity + (diabetes_status+hypertension_status|PatientID/visit), data=df_1, REML=TRUE)

attempt_4 = lmer(fat ~ age + ethnicity + (1|diabetes_status) + (1|hypertension_status) + (1|PatientID/visit), data=df_1, REML=FALSE)

attempt_5 = lmer(fat ~ age + ethnicity + (1+diabetes_status+hypertension_status|PatientID/visit), data=df_1, REML=TRUE)

But none of these attempts work, and the error is always the same: Error: number of levels of each grouping factor must be < number of observations I assume that this can be for one of these 3 reasons:

  1. The code is not correct in any of the attempts, if this is true, which would be the best way to express this?

  2. The random effects should really be fixed effects (so, in this case the right model would be lme(fat~ diabetes_status + hypertension_status + bmi + waist + smoker + gender + ethnicity, random= ~1|PatientID/Visit, data = df_1, na.action = na.omit)) which runs perfectly.

  3. Linear mixed effects models are not prepared to handle so many random effects.

Any thoughts? Thanks!

来源:https://stackoverflow.com/questions/63299882/multiple-random-effects-in-a-linear-mixed-model-with-nlme-and-lme4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!