R/soft.R

#' 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)
}
jiayiwang1017/Test_package documentation built on May 28, 2019, 6:32 p.m.