Fits a Bayesian linear regression with regularized Horseshoe prior using Stan via cmdstanr. This version includes improved numerical stability and automatic prior calibration.
fit_horseshoe(
y,
X,
var_names = NULL,
p0 = NULL,
slab_scale = 3,
slab_df = 4,
tau_scale = NULL,
use_qr = FALSE,
standardize = TRUE,
X_new = NULL,
iter_warmup = 1000,
iter_sampling = 1000,
chains = 4,
adapt_delta = 0.95,
max_treedepth = 12,
seed = 123,
verbose = TRUE
)A list of class "signaly_horseshoe" with posterior summaries, diagnostics, and model fit object.
Numeric vector of the response variable.
Matrix or data frame of predictor variables.
Optional character vector of variable names.
Expected number of non-zero coefficients. Default: P/3.
Scale for the regularizing slab. Default: 3.
Degrees of freedom for the slab. Default: 4.
Scale multiplier for the global shrinkage prior. Default: NULL (auto-calibrated based on data characteristics). Increase this value (e.g., 10-20) if the model over-shrinks.
Use QR decomposition? Default: FALSE.
Standardize predictors internally? Default: TRUE.
Optional matrix for out-of-sample prediction.
Warmup iterations per chain. Default: 1000.
Sampling iterations per chain. Default: 1000.
Number of MCMC chains. Default: 4.
Target acceptance probability. Default: 0.95.
Maximum tree depth. Default: 12.
Random seed.
Print progress messages?
The regularized Horseshoe prior (Piironen & Vehtari, 2017) provides adaptive shrinkage that can distinguish between relevant and irrelevant predictors.
Variable Selection Methods:
After fitting, variables can be selected using different criteria:
select_by_credible_interval: Selects variables whose
credible interval excludes zero. Recommended - most robust method.
select_by_shrinkage: Selects based on kappa (shrinkage factor).
May underselect when tau is very small.
select_by_magnitude: Selects based on coefficient magnitude.
Note on kappa-based selection:
The shrinkage factor kappa depends on the global shrinkage parameter tau.
In some datasets, the posterior of tau may concentrate near zero, causing
all kappa values to be close to 1 even for truly relevant variables.
When this happens, the coefficient estimates (beta) remain valid, but
kappa-based selection will fail. The function automatically warns when
this occurs and recommends using select_by_credible_interval() instead.