lmSubsets (version 0.5-1)

methods: Methods for 'lmSubsets' and 'lmSelect' Objects

Description

Extractor methods for "lmSubsets" and "lmSelect" objects.

Usage

# S3 method for lmSubsets
variable.names(object, size, best = 1, …, na.rm = TRUE, drop = TRUE)
# S3 method for lmSelect
variable.names(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets formula(x, size, best = 1, …) # S3 method for lmSelect formula(x, best, …)

# S3 method for lmSubsets model.frame(formula, …) # S3 method for lmSelect model.frame(formula, …)

# S3 method for lmSubsets model.matrix(object, size, best = 1, …) # S3 method for lmSelect model.matrix(object, best, …)

# S3 method for lmSubsets model_response(data, …) # S3 method for lmSelect model_response(data, …)

# S3 method for lmSubsets refit(object, size, best = 1, …) # S3 method for lmSelect refit(object, best = 1, …)

# S3 method for lmSubsets deviance(object, size, best = 1, …, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect deviance(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets sigma(object, size, best = 1, …, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect sigma(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets logLik(object, size, best = 1, …, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect logLik(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets AIC(object, size, best = 1, …, k = 2, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect AIC(object, best = 1, …, k = 2, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets BIC(object, size, best = 1, …, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect BIC(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets coef(object, size, best = 1, …, na.rm = TRUE, drop = TRUE) # S3 method for lmSelect coef(object, best = 1, …, na.rm = TRUE, drop = TRUE)

# S3 method for lmSubsets vcov(object, size, best = 1, …) # S3 method for lmSelect vcov(object, best = 1, …)

# S3 method for lmSubsets fitted(object, size, best = 1, …) # S3 method for lmSelect fitted(object, best = 1, …)

# S3 method for lmSubsets residuals(object, size, best = 1, …) # S3 method for lmSelect residuals(object, best = 1, …)

Arguments

object, formula, data, x

An object of class "lmSubsets" or "lmSelect".

size

The submodel size.

best

The submodel ranking.

Forwarded arguments.

k

AIC penalty.

drop

Control shape of return value.

na.rm

Remove missing submodels.

Details

The extractor methods work for "lmSubsets" and "lmSelect" objects, i.e., objects that have been generated using the formula interface.

If drop == FALSE, the extractor methods variable.names, deviance, sigma, logLik, AIC, BIC and coef return a data.frame object. If drop == TRUE, the return value is a logical matrix (variable.names), a numeric matrix (coef), or a numeric vector. If the drop parameter is not set explicitly when calling variable.names or coef, one-dimensional values are represented in a compact form.

If a desired extractor function is not available, refit can be called explicitly to obtain the corresponding "lm" object.

See Also

lmSubsets, lmSelect, refit.

Examples

Run this code
# NOT RUN {
## load data
data("AirPollution", package = "lmSubsets")

## fit subsets (5 best subsets per size)
lm_all <- lmSubsets(mortality ~ ., data = AirPollution, nbest = 5)

## extract information (for best submodel of size 3)
coef(lm_all, size = 3)
vcov(lm_all, size = 3)
residuals(lm_all, size = 3)
fitted(lm_all, size = 3)
model.matrix(lm_all, size = 3)

## select best (BIC) submodels
lm_best <- lmSelect(lm_all)

## extract information
deviance(lm_best)
logLik(lm_best)
AIC(lm_best)
BIC(lm_best, best = 1:5)

## refit model
lm5 <- refit(lm_all, size = 5)
summary(lm5)
## (Note that the p-values are not valid due to model selection.)
# }

Run the code above in your browser using DataCamp Workspace