1
votes

I have been running the function "aictab" in R on a list of six candidate GLM models (nine times for nine different response variables). My response variables are distributed either Gamma or negative binomial. (I'm using negative binomial error structures because I have count data that is over dispersed.) The aictab function worked great and gave me a table with AICc values, model weights, etc. on my models with Gamma error structures, but when I tried running the function on my models with negative binomial error structures, I realized that that type of error structure isn't supported for aictab() and I can't get AICc or model weights.

My question is: what other functions or code can I use to get the equivalent output of the aictab function for my negative binomial GLM models? Example of code/error is below.

setwd('C:/Users/Laura/Desktop/')
library(ggplot2)
library(Hmisc)
library(psych)
library(multcomp)
library(gridExtra)
library(lmerTest)
library(plotrix)
library(stats)
library(stats4)
library(gplots)
library(sciplot)
library(lme4)
library(lmerTest)
library(AICcmodavg)
library(glmulti)

##########################################
indi<-read.csv("trait_data_all_years.csv", header=T)
indi$year<-as.factor(indi$year)
str(indi)
summary(indi$tot.sil)
hist(indi$tot.sil, breaks=20)
indi<-subset(indi, tot.sil!="NA")
summary(indi$tot.sil)

year_site<-glm.nb(tot.sil~year + site, data=indi) 
year_site_hab<-glm.nb(tot.sil~year + site + hab, data=indi)
yearhabinteract_plus_site<-glm.nb(tot.sil~year*hab + site, data=indi)
yearsiteinteract_plus_hab<-glm.nb(tot.sil~year*site + hab, data=indi)
habsiteinteract_plus_year<-glm.nb(tot.sil~year + site*hab, data=indi)
threewayinteract<-glm.nb(tot.sil~site*hab*year, data=indi)

model.set<- list(year_site, year_site_hab, yearhabinteract_plus_site, yearsiteinteract_plus_hab, habsiteinteract_plus_year, threewayinteract)

aictab (model.set)

I get this error when running aictab(model.set)

aictab (model.set)
Error in aictab.default(model.set) : 
Function not yet defined for this object class
1

1 Answers

0
votes

There is no such function called aictab.default() that I am aware of, nor have you defined such a function in your program.

You should be able to use something like

model.set <- c(year_site, year_site_hab, yearhabinteract_plus_site, yearsiteinteract_plus_hab, habsiteinteract_plus_year, threewayinteract)

AIC(model.set)

Alternatively, year_site$aic will return the AIC for the year_site binomial GLM. You can do the same thing with the other models to extract the individual AICs.