library(MASS)
library(glmnet)
library(glasso)
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 without external information
fit <- covsel(x, lambda = 0.2)
## Covariance selection with external information
##-Not run-
#oneMat = edgelist2adj(file="edgelist.txt", vertex.names=1:p, mode="undirected")
#zeroMat = edgelist2adj(file="nonedgelist.txt", vertex.names=1:p, mode="undirected")
#fit2 <- covsel(x, zero=zeroMat, one=oneMat, lambda = 0.2)
Run the code above in your browser using DataLab