# \donttest{
library(data.table)
# 1. Create a COMPLETE dummy dataset
# select_by_bma -> fit_one -> build_design requires ALL these columns:
DT <- data.table(
year = 2000:2020,
I = rpois(21, lambda = 4),
C = rpois(21, lambda = 3),
zI = rnorm(21),
zC = rnorm(21),
t_norm = seq(-1, 1, length.out = 21),
t_poly2 = seq(-1, 1, length.out = 21)^2,
Regime = factor(sample(c("A", "B"), 21, replace = TRUE)),
trans_PS = sample(0:1, 21, replace = TRUE),
trans_SF = sample(0:1, 21, replace = TRUE),
trans_FC = sample(0:1, 21, replace = TRUE),
log_exposure50 = rep(0, 21)
)
# 2. Run the function
# IMPORTANT: use_parallel = FALSE to avoid complexity/errors in CRAN checks
# We reduce the grid size (k_grid=0) for speed in this example
try({
result <- select_by_bma(
DT,
spec = "C",
k_grid = 0,
hs_grid = data.frame(hs_tau0=0.5, hs_slab_scale=1, hs_slab_df=4),
use_parallel = FALSE,
iter_warmup = 100, iter_sampling = 100, chains = 1 # Minimal MCMC for speed
)
if (!is.null(result$table)) {
print(result$table)
}
})
# }
Run the code above in your browser using DataLab