# NOT RUN {
require(mvtnorm) # for multivariate normal distribution
n <- 100 # sample size
k <- 40 # number of variables
z <- as.vector(rmvnorm(1, mean = rep(0, n), sigma = diag(n)))
x <- matrix(NA, nrow = n, ncol = k)
for(i in 1:k)
{
x[, i] <- as.vector(rmvnorm(1, mean = rep(0, n), sigma = diag(n))) + z
} # this induce 0.5 correlation among the variables
beta <- c(rep(0, 10), rep(2, 10), rep(0, 10), rep(2, 10))
# vector of coefficients
sigma <- 1
sigma.square <- sigma^2
linear.pred <- x %*% beta
y <- as.numeric(t(rmvnorm(1, mean = linear.pred, sigma = diag(sigma.square, n))))
# response
answer <- sahpmlm(formula = y ~ x)
answer$final.model
answer$history
# }
# NOT RUN {
# With small effect size
beta <- c(rep(0, 10), rep(1, 10), rep(0, 10), rep(1, 10))
# vector of coefficients
linear.pred <- x %*% beta
y <- as.numeric(t(rmvnorm(1, mean = linear.pred, sigma = diag(sigma.square, n))))
# response
answer <- sahpmlm(formula = y ~ x)
answer$final.model # Might miss some of the true predictors
answer$history
# Able to recover all the predictors with 50 burnin
answer <- sahpmlm(formula = y ~ x, burnin = TRUE, nburnin = 50)
answer$final.model # Misses some of the true predictors
answer$history
# }
Run the code above in your browser using DataLab