glmnet_beta: ridge regression (standard)

Description Usage Arguments Details Value Examples

View source: R/glmnet_beta.R

Description

This function is used to return ridge regression estimators given by glmnet function (after adjustments).

Usage

1
glmnet_beta(X, Y, lambda)

Arguments

X

a design matrix containing all predictors.

Y

a response vector.

lambda

a lambda value specified, serving as the coefficient of the penalty terms.

Details

The direct glmnet function in the glmnet package has different minimization function, scaling, intercept settings from those of the textbook. This function returns the ridge regression estimator after adjustments to make the result similar to that of the textbook.

Thus, it can be used as a standard to check whether the self-defined function can return the ridge regression estimators rightly.

Value

ridge regression estimators.

Examples

1
2
3
4
5
6
7
8
#If do not have a design matrix and a response vector,
#firstly turn the formula and dataset into the required matrix
mf<-model.frame(Sepal.Width~.,iris)
mt<-attr(mf,"terms")
X <- model.matrix(mt, mf)
Y <- as.matrix(model.response(mf))
#call the function
glmnet_beta(X,Y,10)

Jiachen1027/bis557 documentation built on Oct. 30, 2019, 7:41 p.m.