# NOT RUN {
###################################################
# Example on synthetic data. #
# 5 percent of entries in theta are set to A = 7. #
###################################################
n <- 40
sparsity.level <- 5 # 5 percent of entries will be nonzero
A <- 5
# 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))
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 NBP model on X #
##########################
# For optimal performance, should set max.steps=10,000 and burnin=5000.
# Estimate sparsity parameter 'a' with a uniform prior.
nbp.model <- nbp.normalmeans(X, a.est="uniform", sigma2=1, var.select="threshold",
max.steps=1000, burnin=500)
nbp.model$theta.hat # Posterior mean estimates
nbp.model$theta.intervals # Posterior credible intervals
nbp.model$nbp.classifications # Classifications
nbp.model$a.estimate # Estimate of sparsity level
# }
Run the code above in your browser using DataLab