myRidge: Ridge Regression

Description Usage Arguments Value Examples

View source: R/Ridge.R

Description

This function performs ridge regression of Y on X.

Usage

1
myRidge(X, Y, lambda)

Arguments

X

an n x p matrix of explanatory variables.

Y

an n vector or matrix of dependent variables.

lambda

regularization parameter for lambda >= 0

Value

Returns a vector of betas, the ridge regression solution with p + 1 elements

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(12837)
X = runif(50)
X = matrix(sort(X), nrow = 50)
sigma = .1
Y =X^2 + rnorm(50)*sigma
lambda = 0
beta_r <- myRidge(X, Y, lambda)
Yhat <- cbind(rep(1, length(X)), X)%*%beta_r
plot(X, Y, col = 'indianred')
par(new =TRUE
plot(X, Yhat, type = 'l', col='slateblue')
abline(coef(lm(Y~X)))

stacyste/RegressionPkg documentation built on Nov. 24, 2019, 5:12 p.m.