Reputation: 125
As example two LMM.
lme1 <- lme(mpg ~ cyl + disp,
random = ~1|disp,
method = "ML",
data = mtcars)
lme2 <- lme(mpg ~ cyl * disp,
random = ~1|disp,
method = "ML",
data = mtcars)
AIC table to select the best model.
library(AICcmodavg)
Cand.models <- list( )
Cand.models[[1]] <- lme1
Cand.models[[2]] <- lme2
aictab(Cand.models, sort = TRUE)
Model selection based on AICc:
K AICc Delta_AICc AICcWt Cum.Wt LL
Mod2 6 164.40 0.00 0.94 0.94 -74.52
Mod1 5 169.87 5.46 0.06 1.00 -78.78
To export the AIC table I like to use the tab_df() function.
library(sjPlot)
tab_df(aictab(Cand.models, sort = TRUE))
Unnecessary the tab_df() functions add the column "ModelLik" to the table, how can I avoid this?
Upvotes: 1
Views: 208
Reputation: 5813
The reason is that the object returned by aictab
has some more columns then printed with its print method. In the following, I assign the returned table to a variable tb
and inspect it with str()
. If you use RStudio, you can also see it in the Environment explorer.
Function tab_df
just formats the data frame, so we can select, remove or even rename columns according to our needs. The following shows an example. As a small goody, I user-defined names for the models:
library("nlme")
library("AICcmodavg")
library("sjPlot")
lme1 <- lme(mpg ~ cyl + disp, random = ~1|disp, method = "ML", data = mtcars)
lme2 <- lme(mpg ~ cyl * disp, random = ~1|disp, method = "ML", data = mtcars)
# alternative way to produce the list, can optionally provide speaking names
Cand.models <- list(
'model 1' = lme1,
'model 2' = lme2
)
# assign the table to a variable
tb <- aictab(Cand.models, sort = TRUE)
## look what is in
str(tb)
which_columns <- c("Modnames", "K", "AICc", "Delta_AICc", "AICcWt", "Cum.Wt", "LL")
tab_df(aictab(Cand.models, sort = TRUE)[which_columns])
Upvotes: 1