# 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 by 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=100
n=100
cov<-cov.nonsparse(p)
data<-sim.data(cov,n)
# an array of soft thresholding estimators for the covariance matrix
# apply thresholdings from 0 to 1 to the sample correlation matrix
s.cov<-softt(cov(t(data)),seq(0,1,by=0.05))
s.cov[,,5] # the soft thresholding estimator when the thresholding level is 0.2
Run the code above in your browser using DataLab