# NOT RUN {
###################################################
# Example on synthetic data. #
# 5 percent of entries in a 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 horseshoe+ model on X #
#################################
# For optimal performance, should set max.steps=10,000 and burnin=5000.
# Estimate tau using truncated Cauchy prior
hsplus.model <- hsplus.normalmeans(X, tau.est="truncatedCauchy", tau=1/length(X),
sigma2=1, var.select="threshold",
max.steps=1000, burnin=500)
hsplus.model$theta.intervals # 95 percent credible intervals
hsplus.model$hsplus.classifications # Classifications
hsplus.model$tau.estimate # Estimate of sparsity level
# }
Run the code above in your browser using DataLab