Nothing
#' @rdname penalization
#'
#' @description
#' - `pen_glmnet(x, y, family)`: LASSO penalized models.
#'
#' @export
pen_glmnet <- function(x, y, family) {
stopifnot( family %in% c("gaussian", "binomial", "cox") )
suppressWarnings(
egg <- cv.glmnet(
x = x,
y = y,
family = family,
standardize = FALSE,
intercept = FALSE,
type.measure = "deviance",
nfolds = 10
)
)
class(egg) <- c("penaltyglmnet", class(egg))
return(egg)
}
#' @title Extract Coefficients from Lasso Penalized Models
#'
#' @param object Object.
#' @param ... Additional arguments (not used).
#'
#' @return Named vector of non-zero coefficients of under cross-validation error.
#'
#' @exportS3Method
coef.penaltyglmnet <- function(object, ...) {
idx <- object[["index"]]['min', 'Lambda']
b0 <- object[["glmnet.fit"]][["beta"]][, idx, drop=TRUE]
return(b0[abs(b0) >= 1e-4])
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.