Learn R Programming

StepReg (version 1.6.0)

plot.StepReg: Visualize Stepwise Regression Results

Description

Creates informative visualizations of the variable selection process from a StepReg object. This function generates two types of plots: detailed step-by-step selection process and an overview of the final selected variables.

Usage

# S3 method for StepReg
plot(
  x,
  strategy = attr(x, "nonhidden"),
  process = c("overview", "detail"),
  num_digits = 6,
  ...
)

Value

A ggplot object showing either:

  • For "detail" process: A heatmap showing variable selection status at each step

  • For "overview" process: A line plot showing metric values across steps

Arguments

x

A StepReg object containing the results of stepwise regression analysis.

strategy

Character. Specifies which selection strategy to visualize:

  • "forward" - Forward selection

  • "backward" - Backward elimination

  • "bidirection" - Bidirectional selection

  • "subset" - Best subset selection

Default is the first strategy name in the StepReg object.

process

Character. Specifies the type of visualization to display:

  • "detail" - Shows detailed step-by-step selection process with variable entry/removal

  • "overview" - Shows summary of the selection process with metric values

Default is "overview".

num_digits

Integer. Number of decimal places to display in the plots. Default is 6.

...

Additional argument passed to plotting functions (currently not used).

Details

The function creates different types of visualizations based on the selection strategy:

  • For forward/backward/bidirectional selection:

    • detail view shows a heatmap with green tiles for added variables, tan tiles for removed variables, and gray tiles for non-selected variables

    • Overview shows metric values across steps with variable labels

  • For subset selection:

    • detail view shows a heatmap of selected variables at each step

    • Overview shows metric values for different subset sizes

See Also

stepwise for creating StepReg objects

Examples

Run this code
if (FALSE) {
# Load example data
data(mtcars)

# Run stepwise regression with multiple strategies
formula <- mpg ~ .
result <- stepwise(
  formula = formula,
  data = mtcars,
  type = "linear",
  strategy = c("forward", "bidirection", "subset"),
  metric = c("AIC", "BIC", "SL")
)

# Generate default overview plot
plot(result)

# Generate detailed plot for forward selection
plot(result, strategy = "forward", process = "detail")

# Generate overview plot with 3 decimal places
plot(result, strategy = "bidirection", process = "overview", num_digits = 3)
}

Run the code above in your browser using DataLab