glmulti wrapper with offset term

100 views Asked by At

I am using glmulti to assess the relative importance of several predictors on counts. As I am using glm.nb I am using the wrapper. I would like to add an offset term, but I am not sure where it should go or, if it is even possible. I tried adding it directly into the formula, but the offset is not used then. I also tried to add it similar to how I would do it with a random effect, but then the offset simply turns up as another predictor. I tried then to put it in as a weight, although an offset is not a weight, which worked, but gave me extremely high AIC values (2000 compared to 740 given by the same "regular" glm.nb model I ran for comparison).

Please see the code below. I would highly appreciate some advice on this! Thank you!

  1. version: the offset is ignored when put into the formula
glmnb.glmulti<-function(formula,data,...){
glm.nb(paste(deparse(formula)),data=data)
}
test<-glmulti(counts~a+b+c+offset(log(d)),data=mydata,level=1,fitfunction=glmnb.glmulti,crit="aic")
  1. version: the offset becomes another predictor when added similar as one would do it with a random effect
glmnb.glmulti<-function(formula,data,offset,...){
glm.nb(paste(deparse(formula),offset),data=data)
}
selection<-glmulti(counts~a+b+c,data=mydata,offset="+(log(d))",level=1,fitfunction=glmnb.glmulti,crit="aic")
0

There are 0 answers