# Making simulation data.
set.seed(123)
N <- 200
p <- 100
true_beta <- c(rep(1, 10), rep(0, 90))
X <- matrix(1, nrow = N, ncol = p) # Design matrix X.
for (i in 1:p) {
X[, i] <- stats::rnorm(N, mean = 0, sd = 1)
}
y <- vector(mode = "numeric", length = N) # Response variable y.
e <- rnorm(N, mean = 0, sd = 2) # error term e.
for (i in 1:10) {
y <- y + true_beta[i] * X[, i]
}
y <- y + e
# Run with auto.threshold set to TRUE
result1 <- approx_horseshoe(y, X, burn = 0, iter = 100,
auto.threshold = TRUE)
# Run with fixed custom threshold
result2 <- approx_horseshoe(y, X, burn = 0, iter = 100,
auto.threshold = FALSE, threshold = 1/(5 * p))
# posterior mean
betahat <- result1$BetaHat
# Lower bound of the 95% credible interval
leftCI <- result1$LeftCI
# Upper bound of the 95% credible interval
RightCI <- result1$RightCI
Run the code above in your browser using DataLab