#' Soft-thresholding function
#'
#' function to do soft-thresholding of a scalar
#' @param a scalar to be thresholded at level \code{lambda}
#' @param lambda threshold value, should not be non-negative
#'
#' @return Soft-thresholding value of a
#' @export
#'
#' @examples
#' soft(3,1)
soft = function(a,lambda){
return(sign(a)*max(abs(a) - lambda, 0))
}
#' Hard-thresholding value of a
#'
#' @param a scalar to be thresholded at level \code{lambda}
#' @param lambda threshold value, should not be non-negative
#'
#' @return Hard-thresholding value of a
#' @export
#'
#' @examples hard(3,1)
hard = function(a, lambda){
return((abs(a)>=lambda) * a)
}
lasso = function(xtrain,ytrain,xtest){
out = glmnet(xtrain,ytrain)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.