Description Usage Arguments Details Value Examples
This function is used to return ridge regression estimators given by glmnet function (after adjustments).
1 | glmnet_beta(X, Y, lambda)
|
X |
a design matrix containing all predictors. |
Y |
a response vector. |
lambda |
a lambda value specified, serving as the coefficient of the penalty terms. |
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.
ridge regression estimators.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.