spexvb-tutorial

library(spexvb)

spexvb

This is a package to performParameter Expanded Variational Bayes for Linear Regression with High-dimensional Variable Selection and Spike-and-slab Priors

Installation

You can install the released version of spexvb from CRAN with:

install.packages("spexvb")

Example

Here is an example for conducting analysis using spexvb:

library(spexvb)
library(doParallel)
#> Loading required package: foreach
#> Loading required package: iterators
#> Loading required package: parallel
cl <- makeCluster(min(2, parallel::detectCores())) 
registerDoParallel( cl)


# 1. Simulate high-dimensional data (n=100, p=500)
set.seed(17)
n <- 100
p <- 500
X <- matrix(rnorm(n * p), n, p)
true_beta <- c(rep(3, 5), rep(0, p - 5)) # 5 active predictors
Y <- X %*% true_beta + rnorm(n)

# 2. Perform 5-fold CV to find optimal tau_alpha and fit final model
fit <- cv.spexvb.fit(
  k = 5,
  X = X, 
  Y = Y,
  tau_alpha = c(0, 10^(3:6)), # Precision for expansion parameter alpha
  standardize = TRUE,
  intercept = TRUE
)
#> Best tau_alpha selected by CV: 0

# 4. Visualize results
plot(true_beta, main = "True Coefficients", ylab = "Value")

plot(fit$beta, main = "Estimated Coefficients", ylab = "Value")
abline(h = 0, col = "red", lty = 2)


stopCluster(cl)