#'ridge regression (self-defined)
#'
#'This function is used to return ridge regression estimators.
#'
#'@param X a design matrix containing all predictors.
#'@param Y a response vector.
#'@param lambda a lambda value specified, serving as the coefficient of the penalty terms.
#'
#'@return ridge regression estimators.
#'
#'@examples
#'
#' #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
#' lm_ridge_beta(X,Y,10)
#'
#'@export
lm_ridge_beta<-function(X,Y,lambda)
{
p<-ncol(X)
beta1<-solve(t(X) %*% X + lambda * diag(p)) %*% t(X) %*% Y
beta1
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.