set.seed(123)
n = 200 # Sample size
p = 500 # Number of genes
s = 50 # Number of true signals
# The first s genes are true markers, and others are noise
Sigma = matrix(0, p, p)
Sigma[1:s, 1:s] = 0.9
diag(Sigma) = 1
# Simulate data from the covariance matrix
x = matrix(rnorm(n * p), n) %*% chol(Sigma)
# Sample correlation matrix
S = cor(x)
# Indices of prior marker genes
# Note that we have omitted 10 true markers, and included 10 false markers
gr = c(1:(s - 10), (s + 11):(s + 20))
# Run the algorithm
res = pca_pen(S, gr, lambda = 0.1, verbose = 1)
# See if we can recover the true correlation structure
image(res$projection, asp = 1)
Run the code above in your browser using DataLab