Learn R Programming

netgsa (version 2.0)

cv.covsel: Cross-validation for covsel

Description

Performs k-fold cross validation for covsel.

Usage

cv.covsel(X, zero = NULL, one = NULL, lambda, nfolds = NULL, verbose = FALSE)

Arguments

X
The $n \times p$ data matrix as in covsel.
zero
(Optional) indices of entries of the matrix to be constrained to be zero. The input should be a matrix of $p \times p$, with 1 at entries to be constrained to be zero and 0 elsewhere. The matrix must be symmetric.
one
(Optional) indices of entries of the matrix to be kept regardless of the regularization parameter for lasso. The input is similar to that of zero and needs to be symmetric.
lambda
(Non-negative) user-supplied lambda sequence.
nfolds
Number of folds. Default is 5-fold cross validation.
verbose
Whether to print out information as estimation proceeds. Default=FALSE.

Value

  • A list with components
  • lambdaThe values of lambda used.
  • cveThe mean cross-validated error(s), a vector of length(lambda).

Details

The function splits the data X into nfolds and runs covsel nfolds times to compute the fit with each of the folds omitted. The error is accumulated and the average error over the folds is computed.

References

Ma, J., Shojaie, A. & Michailidis, G. (2014). Network-based pathway enrichment analysis with incomplete network information, submitted. http://arxiv.org/abs/1411.7919.

See Also

covsel

Examples

Run this code
library(MASS)
library(glmnet)
library(cvTools)
set.seed(1)

## Generate the covariance matrix for the AR(1) process 
phi <- 0.5
p <- 50
n <- 50
Sigma <- diag(rep(1,p))
Sigma <- phi^(abs(row(Sigma)-col(Sigma)))/(1-phi^2)

## The inverse covariance matrix is sparse
Omega <- solve(Sigma)

## Generate multivariate normal data
x <- mvrnorm(n, mu=rep(0, p), Sigma=Omega)

## Covariance selection with external information
cv.fit <- cv.covsel(x, lambda=seq(0.1,0.3,0.1), nfolds=5)

Run the code above in your browser using DataLab