#' Soft-thresholding function
#'
#' @param a scalar
#' @param lambda non-negative thresholding parameter
#'
#' @return Soft-thresholded a
#' @export
#'
#' @examples
#' soft(3, 1)
#' soft(-3, 1)
#' soft(-3, 4)
soft <- function(a, lambda){
return(sign(a) * max(abs(a) - lambda, 0))
}
#' Hard-thresholding function
#'
#' @inheritParams soft
#'
#' @return Hard-thresholded a
#' @export
#'
#' @examples
#' hard(3, 1)
#' hard(-3, 1)
#' hard(-3, 4)
hard <- function(a, lambda){
return(sign(a) * max(abs(a), 0))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.