rank deficiency warning mixed model lmer

允我心安 提交于 2019-12-03 17:20:13

This is not really specifically a linear-mixed model problem.

It comes down to the fact that you can't estimate an interaction if you don't have any treatment happening in the 'before' period (year 0).

Simplest possible example:

(dd <- data.frame(y=1:3,treat=c(0,0,1),year=c(0,1,1)))

##   y treat year
## 1 1     0    0
## 2 2     0    1
## 3 3     1    1

Fit the model:

lm(y~treat*year,dd) ## == year+treat+year:treat
## Call:
## lm(formula = y ~ treat * year, data = dd)
## 
## Coefficients:
## (Intercept)        treat         year   treat:year  
##           1            1            1           NA  

lm doesn't warn you, but it effectively does the same thing as lmer by removing the extra, collinear column and giving its parameter an NA value. If you try caret::findLinearCombos(dd[c("year","treat")]) you won't get anything back (year and treat are not perfectly collinear), but if you look at the model matrix that R constructs to include the treatment column, you will get something:

X <- model.matrix(~year*treat,dd)
caret::findLinearCombos(X)
## $linearCombos
## $linearCombos[[1]]
## [1] 4 3
## $remove
## [1] 4

This experimental design simply doesn't allow you to estimate the interaction. If you remove it from the formula (use year+treat instead of year*treat) you'll get the same answer, but without the message. Alternatively, in a typical "before-after-control-impact" design (in environmental impact assessment), you would label the individuals who would be getting the treatment as "impact" or "treated" individuals even in year 0; then the interaction would be your actual estimated effect of treatment.

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