O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – ridge regression for the linear regression model

The linearRidge function from ridge package and lm.ridge from the MASS package are two good options for developing the ridge regression models.

  1. Though the OF object may still be there in your session, let us again load it by using data(OF).
  2. Load the MASS and ridge package by using library(MASS); library(ridge).
  3. For a polynomial regression model of degree 3 and various values of lambda, including 0, 0.5, 1, 1.5, 2, 5, 10, and 30, obtain the ridge regression coefficients with the following single line R code:
    LR <-linearRidge(Y~poly(X,3),data=as.data.frame(OF),lambda =c(0, 0.5,1,1.5,2,5,10,30))
    LR

    The function linearRidge from the ridge package performs the ridge regression for a linear ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required