Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

subsets

Plot Output from regsubsets Function in leaps package


Description

The regsubsets function in the leaps package finds optimal subsets of predictors based on some criterion statistic. This function plots a measure of fit against subset size.

Usage

subsets(object, ...)

## S3 method for class 'regsubsets'
subsets(object, 
    names=abbreviate(object$xnames, minlength = abbrev), 
    abbrev=1, min.size=1, max.size=length(names), 
    legend="interactive", 
    statistic=c("bic", "cp", "adjr2", "rsq", "rss"), 
    las=par('las'), cex.subsets=1, ...)

Arguments

object

a regsubsets object produced by the regsubsets function in the leaps package.

names

a vector of (short) names for the predictors, excluding the regression intercept, if one is present; if missing, these are derived from the predictor names in object.

abbrev

minimum number of characters to use in abbreviating predictor names.

min.size

minimum size subset to plot; default is 1.

max.size

maximum size subset to plot; default is number of predictors.

legend

If not FALSE, in which case the legend is suppressed, the coordinates at which to place a legend of the abbreviated predictor names on the plot, in a form recognized by the legend function. If "interactive", the legend is placed on the plot interactively with the mouse. By expanding the left or right plot margin, you can place the legend in the margin, if you wish (see par).

statistic

statistic to plot for each predictor subset; one of: "bic", Bayes Information Criterion; "cp", Mallows's Cp; "adjr2", R^2 adjusted for degrees of freedom; "rsq", unadjusted R^2; "rss", residual sum of squares.

las

if 0, ticks labels are drawn parallel to the axis; set to 1 for horizontal labels (see par).

cex.subsets

can be used to change the relative size of the characters used to plot the regression subsets; default is 1.

...

arguments to be passed down to subsets.regsubsets and plot.

Value

NULL if the legend is TRUE; otherwise a data frame with the legend.

Author(s)

John Fox

References

Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third Edition. Sage.

Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.

See Also

Examples

if (require(leaps)){
    subsets(regsubsets(undercount ~ ., data=Ericksen),
            legend=c(3.5, -37))
}

car

Companion to Applied Regression

v3.0-10
GPL (>= 2)
Authors
John Fox [aut, cre], Sanford Weisberg [aut], Brad Price [aut], Daniel Adler [ctb], Douglas Bates [ctb], Gabriel Baud-Bovy [ctb], Ben Bolker [ctb], Steve Ellison [ctb], David Firth [ctb], Michael Friendly [ctb], Gregor Gorjanc [ctb], Spencer Graves [ctb], Richard Heiberger [ctb], Pavel Krivitsky [ctb], Rafael Laboissiere [ctb], Martin Maechler [ctb], Georges Monette [ctb], Duncan Murdoch [ctb], Henric Nilsson [ctb], Derek Ogle [ctb], Brian Ripley [ctb], William Venables [ctb], Steve Walker [ctb], David Winsemius [ctb], Achim Zeileis [ctb], R-Core [ctb]
Initial release
2020-09-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.