penalty_function | R Documentation |
These are built-in penalty functions. They are implemented purely in R.
penalty_lasso(x, params, derivative = FALSE)
penalty_scad(x, params, derivative = FALSE)
penalty_mcp(x, params, derivative = FALSE)
x |
input numeric vector |
params |
numerical vector, parameters needed for the corresponding penalty function. Refer to the following sections for more details. |
derivative |
boolen, whether the derivatives at |
A numerical vector storing the penalty function's value at x
if
derivative = FALSE
. Otherwise the derivative of the penalty function at
x
For lasso,
f(x, \lambda) = \lambda |x|
where \lambda
= param[1]
.
For SCAD and MCP, \lambda
= param[1]
and \gamma
= param[2]
x <- seq(from = -10, to = 10, by = 0.001)
lasso <- penalty_lasso(x, 1.0)
dlasso <- penalty_lasso(x, 1.0, TRUE)
scad <- penalty_scad(x, c(1.5, 3.7))
dscad <- penalty_scad(x, c(1.5, 3.7), TRUE)
mcp <- penalty_mcp(x, c(1.5, 2.7))
dmcp <- penalty_mcp(x, c(1.5, 2.7), TRUE)
matplot(x, cbind(lasso, scad, mcp), type = "l", ylab = "penalty")
legend(-10, 2.5, legend = c("lasso", "scad", "mcp"), col = 1 : 3, lty = 1 : 3)
matplot(x, cbind(dlasso, dscad, dmcp), type = "l", ylab = "derivative")
legend(-10, 1.5, legend = c("lasso", "scad", "mcp"), col = 1 : 3, lty = 1 : 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.