cv_gflasso: k-fold Cross Validation for GFLasso

View source: R/cv_gflasso.R

cv_gflassoR Documentation

k-fold Cross Validation for GFLasso

Description

k-fold Cross Validation for GFLasso

Usage

cv_gflasso(X, Y, R, additionalOpts = list(), k = 5, times = 1,
  params = seq(0, 1, by = 0.1), nCores = NULL, seed = 100,
  err_fun = rmse, err_opt = "min")

Arguments

X

The data matrix, scaled and centered as necessary.

Y

The matrix of regression responses, scaled and centered as necessary.

R

The matrix of (thresholded) correlations between columns of Y.

additionalOpts

Additional options to pass alongside lambda and gamma. See merge_proxgrad_opts().

k

Number of folds.

times

Number of repetitions. Total number of metric estimates = no. folds x no. times.

params

The grid of lambda and gamma values to cross-validate.

nCores

The number of CPU cores to be used.

seed

Arbitrary number to ensure reproducibility. Defaults to 100.

err_fun

A function that computes the metric (error/goodness-of-fit) between vectors of predicted and true responses. Defaults to rmse(pred, y) = sqrt(mean((pred - y) ^ 2)).

err_opt

Specify whether do minimize ('min') or maximize ('max') 'err_fun'. Default is 'min'.

Value

cvMatrix A matrix of errors across a grid of lambda (row) and gamma (column) values.

Examples

X <- matrix(rnorm(100 * 10), 100, 10)
u <- matrix(rnorm(10), 10, 1)
B <- u %*% t(u) + matrix(rnorm(10 * 10, 0, 0.1), 10, 10)
Y <- X %*% B + matrix(rnorm(100 * 10), 100, 10)
R <- ifelse(cor(Y) > .8, 1, 0)
system.time(testCV <- cv_gflasso(scale(X), scale(Y), R, nCores = 1))
system.time(testCV <- cv_gflasso(scale(X), scale(Y), R, nCores = 2))
cv_plot_gflasso(testCV)

krisrs1128/gflasso documentation built on Nov. 11, 2023, 4:24 a.m.