select_lambda: Selection of penalty parameter based on cross-validation

Description Usage Arguments Examples

Description

select_lambda selects the best regularization parameter from a grid of values based on minimal predictive negative log-likelihood.

Usage

1
select_lambda(X, lambda, fold = min(nrow(X), 10))

Arguments

X

n-by-p data matrix

lambda

vector of penalties for cross-validation

fold

number of folds for cross-validation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
n <- 30
p <- 30
set.seed(12345)
X <- matrix(rnorm(n*p),n,p)
alpha <- get_alpha(X)
lambda_max <- get_lambda_max(svd(X)$d**2,alpha,n)
lambda <- 10**(seq(-1,log10(lambda_max),length.out=100))
sol_path <- cernn(X,lambda,alpha)
df <- t(sol_path$e)

## Plot regularization paths of eigenvalues
matplot(x=log10(lambda),y=df,type='l',ylab='shrunken eigenvalue')
grand_mean <- (norm(scale(X,center=TRUE,scale=FALSE),'f')**2)/(n*p)
abline(h=grand_mean)

## Plot selected lambda
abline(v=log10(select_lambda(X,lambda)$lambda))

cernn documentation built on May 2, 2019, 6 a.m.

Related to select_lambda in cernn...