Learn R Programming

FindMinIC (version 1.6)

FindMinIC: Find Model with Minimum IC

Description

Evaluates all models in a set of candidates, and ranks them by IC such as AIC. Either lm or lme can be used for the model.

Usage

# Find the minimum IC "FindMinIC"(coly, candidates = c(""), fixed = c(""), data = list(), modeltype = "lm", random = ~1, ic = "AIC", ...) "FindMinIC"(formula, data=list(), na.action=na.omit, fixed = c(""), random = ~1, ...)
# find the minimum IC, fmi is the shorter name form of FindMinIC "fmi"(coly, candidates = c(""), fixed = c(""), data = list(), modeltype = "lm", random = ~1, ic = "AIC", ...) "fmi"(formula, data=list(), na.action=na.omit, fixed = c(""), random = ~1, ...)

Arguments

formula
A formula containing the response variable and terms. All the terms of the formula become candidates for inclusion as covariates.
na.action
action to use when data contains NAs. Options include na.omit, na.exclude, na.fail
coly
The name of the column to use for the response variable y of the model
candidates
A list of names of columns that are candidates for inclusion as covariates in the model
fixed
A list of names of columns (can be empty) that must always be included in every model
data
An object containing the variables for use in the model.
modeltype
Currently a choice between "lm" (the default) and "lme". If a model follows the calling convention of lm, it might work here, but it is not guaranteed.
random
When modeltype = "lme", use random the same way as would inside a call to lme and to indicate the variable for groupedData
ic
Type of information criterion to used. Defaults to "AIC". Other options are "AICc" or "BIC"
...
Extra arguments are passed directly into the call to lm or lme.

Value

FindMinIC returns a list of candidate models sorted by information criterion IC. The first model has the "best" IC. The list is of class("cmList") while each element of that list is of class("cm") see cmList for more details

Details

FindMinIC tries all possible model combinations of the candidate covariates, while always including the same response variable and fixed variables. It returns a list of candidate models ranked by IC. The model combinations include all 2-way interactions among the candidate variables. Other interactions (like age^2) can be directly included in the candidates or fixed lists.

References

Burnham, K. P.; Anderson, D. R. (2004), "Multimodel inference: understanding AIC and BIC in Model Selection", Sociological Methods and Research 33: 261-304.

See Also

getFirstModel

Examples

Run this code

data(iris)

coly="Sepal.Length"
fixed="Sepal.Width"
candidates=c("Species","-1","Sepal.Width:Species")

results.lm = FindMinIC(coly, candidates, fixed, iris)

# model with lowest IC:
first.model = getFirstModel(results.lm)
print(summary(first.model))

# model with 3rd lowest IC:
third.model = getNthModel(results.lm, 3)
print(summary(third.model))

# list of first 5 models, ordered by AIC
print(summary(results.lm)$table[1:5,])

# list of first 5 models, ordered by BIC
results.bic = FindMinIC(coly, candidates, fixed, iris, ic="BIC")
print(summary(results.bic)$table[1:5,])

fm = FindMinIC(Infant.Mortality ~ ., data = swiss)
summary(fm)

fm2 = FindMinIC(Infant.Mortality ~ Fertility + Agriculture + Education * Catholic,
                data = swiss)
summary(fm2)

# list of first 5 models, ordered by AICc
if (require(nlme)) {
  results.aicc = FindMinIC(distance~age, data=Orthodont, 
                           ic="AICc", model="lme",
                           random= ~ 1 | Subject)
  print(summary(results.aicc))
}

Run the code above in your browser using DataLab