问题
I have constructed a generalized mixed linear model with lmer (lme4) last week which worked fine:
fit<-lmer(dat$presence~log(dat$SIZE_strict)*dat$Troph_level+log(dat$HAB500EXCL_strict+1)+(1|dat$dataset), family=poisson, REML=FALSE)
After updating the lme4 package however, the model no longer worked, giving the error message:
Error in `[[<-.data.frame`(`*tmp*`, i, value = integer(0)) :
replacement has 0 rows, data has 174
In addition: Warning messages:
1: In lmer(dat$presence ~ log(dat$SIZE_strict) * dat$Troph_level + :
calling lmer with 'family' is deprecated; please use glmer() instead
2: In checkArgs("glmer", REML = FALSE) :
extra argument(s) ‘REML’ disregarded
Using glmer instead of lmer did not solve the first error message. Any suggestions would be very much appreciated!
Here are some of the data (called dat):
Troph_level presence dataset SIZE_strict HAB500EXCL_strict
carnivorous 2 1 46155 26005
carnivorous larvae 0 1 46155 26005
phytophagous 2 1 46155 26005
phytophagous 0 3 195295 360882
carnivorous 0 3 195295 360882
carnivorous larvae 0 3 195295 360882
phytophagous 4 2 18272 21169
carnivorous larvae 0 2 18272 21169
carnivorous 1 2 18272 21169
carnivorous 1 2 24964 26745
carnivorous larvae 0 2 24964 26745
phytophagous 4 2 24964 26745
phytophagous 5 2 6220 12543
carnivorous larvae 0 2 6220 12543
carnivorous 1 2 6220 12543
phytophagous 0 3 102633 12198
carnivorous larvae 0 3 102633 12198
carnivorous 0 3 102633 12198
phytophagous 0 3 2092 291439
carnivorous larvae 1 3 2092 291439
carnivorous 0 3 2092 291439
phytophagous 3 5 80410 0
Many thanks in advance! Toos van Noordwijk
回答1:
This is a buglet in the new version of lme4
(to be fixed in an upcoming patch release) that requires grouping variables to be findable within the data frame specified by the data
argument. In general things will work more smoothly (and your code will be easier to read) if you use the data
argument and eschew using variables of the form dat$var
, for example:
fit <- glmer(presence~log(SIZE_strict)*Troph_level+log(HAB500EXCL_strict+1)+
(1|dataset), family=poisson, data=dat)
来源:https://stackoverflow.com/questions/19431863/lme4-upgrade-produces-error-message-error-in-data-frametmp-i-value