Description Usage Arguments Details Value See Also Examples
Best-variable-subset selection in ordinary linear regression.
1 2 3 4 5 6 |
formula, data, subset, weights, na.action, model, x, y,
contrasts, offset |
standard formula interface |
... |
forwarded to |
The lmSelect()
generic provides various methods to conveniently
specify the regressor and response variables. The standard formula
interface (see lm()
) can be used, or the model
information can be extracted from an already fitted "lm"
object. The model matrix and response can also be passed in directly.
After processing the arguments, the call is forwarded to
lmSelect_fit()
.
"lmSelect"
—a list
containing the components returned
by lmSelect_fit()
Further components include call
, na.action
,
weights
, offset
, contrasts
, xlevels
,
terms
, mf
, x
, and y
. See
lm()
for more information.
lmSelect.matrix()
for the
matrix interface
lmSelect.lmSubsets()
for
coercing an all-subsets regression
lmSelect_fit()
for the low-level
interface
lmSubsets()
for all-subsets
regression
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ## load data
data("AirPollution", package = "lmSubsets")
###################
## basic usage ##
###################
## fit 20 best subsets (BIC)
lm_best <- lmSelect(mortality ~ ., data = AirPollution, nbest = 20)
lm_best
## summary statistics
summary(lm_best)
## visualize
plot(lm_best)
########################
## custom criterion ##
########################
## the same as above, but with a custom criterion:
M <- nrow(AirPollution)
ll <- function (rss) {
-M/2 * (log(2 * pi) - log(M) + log(rss) + 1)
}
aic <- function (size, rss, k = 2) {
-2 * ll(rss) + k * (size + 1)
}
bic <- function (size, rss) {
aic(size, rss, k = log(M))
}
lm_cust <- lmSelect(mortality ~ ., data = AirPollution,
penalty = bic, nbest = 20)
lm_cust
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.