ridge_regression: Ridge Regression

Description Usage Arguments Value Examples

View source: R/ridge_regression.R

Description

This is a function to implement a ridge regression function taking into account colinear (or nearly colinear) regression variables.

Usage

1
ridge_regression(X, Y, lambda)

Arguments

X

The input design matrix.

Y

The input response vector.

lambda

The input penalty parameter.

Value

A list of estimated coefficients.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
n <- 1000
p <- 5
beta <- c(1,-1,0,0,2)
set.seed(2)
X <- matrix(rnorm(n*p), nrow=n, ncol = p)
alpha <- 0.05
X[,1] <- X[,1]*alpha+X[,2]*(1 - alpha)
set.seed(1)
Y <- X %*% beta + rnorm(n)
model <- ridge_regression(X, Y, lambda=0.5)
model$coefficients

lyran92/bis557 documentation built on Dec. 21, 2020, 10:03 p.m.