# arbitrary positive definite covariance matrix
cov.nonsparse<- function(p, rgen = rnorm, rgen.diag = rchisq, df = 5)
{
m <- matrix(rgen(p*p), p, p)
m[upper.tri(m)] <- 0
tmp <- m %*% t(m)
tmp.svd <- svd(tmp)
tmp.svd$d <- rgen.diag(p, df)
tmp.svd$u %*% diag(tmp.svd$d) %*% t(tmp.svd$u)
}
# simulate n x p data matrix by a given covariance matrix
sim.data <- function(sc, n, rgen = rnorm)
{
l <- t(chol(sc))
p <- dim(sc)[1]
z <- matrix(rgen(p * n), p, n)
t(l %*% z)
}
p=50
n=50
cov<-cov.nonsparse(p)
x<-sim.data(cov,n)
novelist.cov.cv(x, lambda=seq(0,1,by=0.1)) # NOVELIST estimator of the covariance matrix
novelist.inv.cv(x, lambda=seq(0,1,by=0.1)) # NOVELIST estimator of the precision matrix
Run the code above in your browser using DataLab