## A toy example is given below to save your time, which will still take ~10s.
## The full example can be run to get BETTER results, which will take more than 80s,
## by letting nmc=5000 (default).
n = 30;
p = n;
beta1 = rep(0.1, p);
beta2 = c(rep(0.2, p / 2), rep(0, p / 2));
beta3 = c(rep(0.15, 3 * p / 4), rep(0, ceiling(p / 4)));
beta4 = c(rep(1, p / 4), rep(0, ceiling(3 * p / 4)));
beta5 = c(rep(3, ceiling(p / 20)), rep(0 , 19 * p / 20));
betas = list(beta1, beta3, beta2, beta4, beta5);
set.seed(123);
X = matrix(rnorm(n * p), n, p);
Y = c(X %*% betas[[1]] + rnorm(n));
# \donttest{
## A toy example with p=30, total Gibbs steps=1100
system.time({mod = GLP_gs(Y, X, nmc = 100);})
mod$beta; ## estimated beta after the Majority voting
hist(mod$Gibbs_res$betamat[1,]); ## histogram of the beta_1
hist(mod$Gibbs_res$q); ## histogram of the q
hist(log(mod$Gibbs_res$lambdasq)); ## histogram of the log(lambda^2)
hist(mod$Gibbs_res$R_2); ## histogram of the R^2 for each iteration in Gibbs sampler
plot(mod$Gibbs_res$q, type = "l"); ## trace plot of the q
## joint posterior of model density and shrinkage
plot(log(mod$Gibbs_res$q / (1 - mod$Gibbs_res$q)), -log(mod$Gibbs_res$lambdasq),
xlab = "logit(q)", ylab = "-log(lambda^2)",
main = "Joint Posterior of Model Density and Shrinkage"); # }
Run the code above in your browser using DataLab