# NOT RUN {
###################################################
# Example on synthetic data. #
# 5 percent of entries in theta are set to A = 7. #
###################################################
n <- 100
sparsity.level <- 5
A <- 7
# Initialize theta vector of all zeros
theta.true <- rep(0,n)
# Set (sparsity.level) percent of them to be A
q <- floor(n*(sparsity.level/100))
# Pick random indices of theta.true to equal A
signal.indices <- sample(1:n, size=q, replace=FALSE)
###################
# Generate data X #
###################
theta.true[signal.indices] <- A
X <- theta.true + rnorm(n,0,1)
#########################
# Run the DL model on X #
#########################
# For optimal performance, should set max.steps=10,000 and burnin=5000.
# Estimate tau from the empirical Bayes estimate of sparsity level
dl.model <- dl.normalmeans(X, tau.est="est.sparsity", sigma2=1, var.select="threshold",
max.steps=1000, burnin=500)
dl.model$theta.med # Posterior median estimates
dl.model$dl.classifications # Classifications
dl.model$tau.estimate # Estimate of sparsity level
# }
Run the code above in your browser using DataLab