Learn R Programming

broom (version 0.3.4)

ridgelm_tidiers: Tidying methods for ridgelm objects from the MASS package

Description

These methods tidies the coefficients of a ridge regression model chosen at each value of lambda into a data frame, or constructs a one-row glance of the model's choices of lambda (the ridge constant)

Usage

## S3 method for class 'ridgelm':
tidy(x, ...)

## S3 method for class 'ridgelm': glance(x, ...)

Arguments

x
An object of class "ridgelm"
...
extra arguments (not used)

Value

  • All tidying methods return a data.frame without rownames. The structure depends on the method chosen.

    tidy.ridgelm returns one row for each combination of choice of lambda and term in the formula, with columns:

  • lambdachoice of lambda
  • GCVgeneralized cross validation value for this lambda
  • termthe term in the ridge regression model being estimated
  • estimateestimate of coefficient using this lambda
  • glance.ridgelm returns a one-row data.frame with the columns
  • kHKBmodified HKB estimate of the ridge constant
  • kLWmodified L-W estimate of the ridge constant
  • lambdaGCVchoice of lambda that minimizes GCV
  • This is similar to the output of select.ridgelm, but it is returned rather than printed.

Examples

Run this code
names(longley)[1] <- "y"
fit1 <- MASS::lm.ridge(y ~ ., longley)
tidy(fit1)

fit2 <- MASS::lm.ridge(y ~ ., longley, lambda = seq(0.001, .05, .001))
td2 <- tidy(fit2)
g2 <- glance(fit2)

# coefficient plot
library(ggplot2)
ggplot(td2, aes(lambda, estimate, color = term)) + geom_line()

# GCV plot
ggplot(td2, aes(lambda, GCV)) + geom_line()

# add line for the GCV minimizing estimate
ggplot(td2, aes(lambda, GCV)) + geom_line() +
    geom_vline(xintercept = g2$lambdaGCV, col = "red", lty = 2)

Run the code above in your browser using DataLab