I am trying to compare the AIC (or AICc) values of various mixed effects logistic (or for some outcomes gamma) models containing all the variables in my dataset, a simplified version of which can be downloaded here: https://drive.google.com/file/d/1YO17J7Dx1cFD0Wf3fNGe-a37ccTKyWNp/view?usp=sharing. However I am new to glmulti and have only used lme4 for a month or so, so I believe I am doing something very wrong:
I have set up the initial model containing all variables as follows:
data_reprex <- read_csv("reprex_glmulti_data.csv")
data_reprex <- within(data_reprex, {
Dog <- factor(Dog)
Box <-factor(Box)
Sex <- factor(Sex)
Group <- factor(Group)
Breedtype <- factor(Breedtype)
OwnerSeverity <- factor(OwnerSeverity, levels = c("None", "Mild", "Moderate", "Severe"))
})
outcome_model <- glmer(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
Group + Group*Interval + Group*Box + Group*Trial + Group*Age + Group*Sex + Group*Breedtype
+ (1 | Dog), data = data_reprex, family = binomial, nAGQ=100)
The model runs fine (with the exception of a few warnings that I have investigated already). However I want to run glmulti for models with each combination of those variables to identify the best model, and have tried several different forms of syntax based on various examples I have found online, but none of these work (I have also tried changing the criterion and "confsetsize" settings):
attempt1 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
Group + (1 | Dog), data=data_reprex,
level=1, fitfunction=glmer, family= binomial, crit="aicc", confsetsize=150)
attempt2 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
Group + (1 | Dog), data=data_reprex,
level=1, fitfunction=glmer, crit="aicc", confsetsize=150)
attempt3 <- glmulti(outcome_model, level=2, fitfunction=glmer, crit=AICc)
attempt4 <- glmulti(outcome_model, level=2, crit=AICc)
The error messages include:
Improper call of glmulti.
Error in .subset2(x, i, exact = exact) :
attempt to select less than one element in get1index
I also sometimes get warning messages such as:
In Ops.factor(Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity, :
‘+’ not meaningful for factors
In Ops.factor(Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity + : ‘|’ not meaningful for factors
I am assuming this is a syntax issue and I need to alter the structure of the code because I am using a logistic glmer rather than a glm like most of the examples I have found online, and from the documentation I believe that glmulti should be compatible with models from lme4. Please could someone advise me on how to structure this so that it runs? (Also, is there a relatively straightforward way to include only the interactions with variable "Group" instead of with all of the other variables?)
EDIT: As a last-ditch attempt I have also tried using the advice provided here (though I think I may have got confused somewhat): glmulti and liner mixed models to use the following code, but this does not work either:
glmer2.glmulti <- setMethod('getfit', 'merMod', function(object, ...) {
summ=summary(object)$coef
summ1=summ[,1:2]
if (length(dimnames(summ)[[1]])==1) {
summ1=matrix(summ1, nr=1, dimnames=list(c("(Intercept)"),c("Estimate","Std. Error")))
}
cbind(summ1, df=rep(10000,length(fixef(object))))
})
attempt5 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
Group + (1 | Dog), data=data_reprex,
level=1, fitfunction=glmer2.glmulti, family=binomial, crit="aicc", confsetsize=150)
Thanks in advance!
I got confused myself and also tried to apply glmulti to a mixed effect model fitted with glmmTMB and got very similar error messages than you did. I did not manage to make it work with glmulti, but it seems that the function dredge from MuMIn package here is working for me. Maybe you could try this? (In case you haven't found a solution yet).