I have a problem with the glmulti package and linear mixed models.
When I try to estimate the model-averaged coefficients with the coff.glmulti function I get this error:
Error in data.frame(..., check.names = FALSE) :arguments imply
differing number of rows: 1, 0
I did a little bit of debugging and I found that the problem starts in the highlighted line of the coeff.glmulti function:
if (length(object@adi) >= 1)
for (j in 1:length(object@adi)) {
cak[[length(names(cak)) + 1]] = object@adi[[j]]
names(cak)[length(names(cak))] = names(object@adi)[j]
}
modf = eval(cak)
coffee = c(coffee, list(modf))
}
}
if (length(coffee) == 1) {
warning("Only one candidate: standard conditional inference was performed.")
**return(coef(coffee[[1]]))**
}
After, when it tries to apply getfit on the coffee object it fails. I think that the error is due to a different structure of the lmer.fir object respect to lm or other type of models object.
I'm pasting a minimum repeatable example to facilitate who wants to help me:
#Add the required package
library(lme4)
library(glmulti)
# A random vector of count data
vy1<-round(runif(100, min=1,max=20)*round(runif(100,min=1,max=20)))
# Predictors
va = runif(100,min=1,max=100)
vb = runif(100,min=,max=100)
random_effect <- as.factor(rep(c(1,2,3,4),each=25))
pippo<-as.data.frame(cbind(vy1,va,vb,random_effect))
form_glmulti = as.formula(paste("vy1~va*vb"))
# The wrapper function for linear mixed-models
lmer.glmulti<-function(formula,data,random="",...){
lmer(paste(deparse(formula),random),data=data,REML=F,...)
}
# The wrapper function for linear models
lm.glmulti<-function(formula,data,...){
lm(paste(deparse(formula)),data=data,...)
}
# Multi selection for lmer
glmulti_lmm<-glmulti(form_glmulti,random="+(1|random_effect)",data=pippo,method="h",
fitfunc=lmer.glmulti, intercept=TRUE,marginality=FALSE,level=2)
# Model selection for lm
glmulti_lm<-glmulti(form_glmulti,data=pippo,method="h",fitfunc=lm.glmulti,intercept=TRUE,
marginality=FALSE, level=2)
# Coeffs estimation lmer #Here the error
coef.glmulti(glmulti_lmm,select="all",varweighting="Johnson",icmethod="Burnham")
#Coeffs estimation lm #With lm everything is ok
coef(glmulti_lm,varweighting="Johnson",icmethod="Burnham",select="all")
See Question&Answers more detail:
os