This package is for bonus lab. The main content is about ridge regression.In this vignette,there will be comparison between results from this package and results from "lm.ridge" in "MASS" package.
library(bonuslab) library(MASS)
The example below is to introduce how these functions work
ridgereg()
takes three parameter,
object : a formula object ;
data : a data.frame object
lambda : a number
QR()
function is to calculate coefficients.
We can also set a lm.ridge object to start compare.
rid <- ridgereg(Petal.Length~Sepal.Width+Sepal.Length, data=iris,1) rid$QR() massrid <- lm.ridge(Petal.Length~Sepal.Width+Sepal.Length, data=iris,lambda = 1)
The print()
prints out the vector containing coefficients.
rid$print()
The pred()
returns the predicted values.
head(rid$pred())
The coef()
returns the coefficients as a named vector.In this section, we will
do a comparison.
# this answer comes from my onw ridge regression object rid$coef() # following coefficient comes from MASS package lm.ridge massrid
As we can see,there is only little difference between them.According to "bonuslab.pdf", this difference is because of applying different calculating methods.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.