Skip to contents

Formula: l_p = l(beta; y) - lambda sum_c beta_c'beta_c (ridge) or - lambda sum_c sum_j |beta_cj| (lasso)

Usage

Mnpenlik(X, y, beta0, beta, lam, penalty = "ridge")

Arguments

X

Design matrix without an intercept column.

y

Observed category index per record, 1-based.

beta0

Category intercepts.

beta

Category slope coefficients.

lam

Penalty strength lambda.

penalty

'ridge' or 'lasso'.

Value

List with loglik, penalty, penalized_loglik, n.

References

Montesinos Lopez, Montesinos Lopez and Crossa (2022), Multivariate Statistical Machine Learning Methods for Genomic Prediction, Springer, doi:10.1007/978-3-030-89010-0. Chapter 7, Eq. (7.7) p. 226 for the ridge penalty and Eq. (7.10) p. 227 for the lasso penalty. The book states on p. 226 that only the slopes are penalized, never the intercepts.

Examples

set.seed(4)
X <- matrix(rnorm(40), 20, 2)
y <- sample(1:3, 20, TRUE)
Mnpenlik(X, y, beta0 = c(0, 0, 0), beta = matrix(0, 3, 2), lam = 1)$penalized_loglik   # 20 log(1/3) at zero
#> [1] -27.72589