Transforms a log-likelihood by subtracting a penalty term. Useful for regularized estimation (e.g., LASSO, Ridge regression).
Examples
if (FALSE) { # \dontrun{
# Regression with L2 penalty (Ridge)
loglike <- function(theta) {
# ... likelihood calculation ...
}
# Add L2 penalty
loglike_penalized <- with_penalty(
loglike,
penalty = penalty_l2(),
lambda = 0.1
)
# Combine with stochastic subsampling
loglike_final <- loglike %>%
with_subsampling(data, 100) %>%
with_penalty(penalty_l1(), lambda = 0.01)
} # }