View source: R/exalStaticLDVB.R
| exalStaticLDVB | R Documentation |
The function applies a mean-field variational approximation to static
Extended Asymmetric Laplace (exAL) regression. Closed-form block updates are
combined with a Laplace-Delta approximation for the joint
(\sigma,\gamma) block, yielding the package's static LDVB routine.
exalStaticLDVB(
y,
X,
p0,
max_iter = 1000,
tol = 1e-04,
b0 = NULL,
V0 = NULL,
beta_prior = c("ridge", "rhs", "rhs_ns"),
beta_prior_controls = NULL,
a_sigma = 1,
b_sigma = 1,
gamma_bounds = c(L.fn(p0), U.fn(p0)),
log_prior_gamma = NULL,
init = NULL,
dqlm.ind = FALSE,
al.ind = NULL,
n.samp = 200,
n_samp_xi = 200,
ld_controls = NULL,
vb_control = NULL,
verbose = TRUE
)
y |
Numeric vector (length n). |
X |
Numeric matrix (n x p). |
p0 |
Target quantile in (0,1). |
max_iter |
Integer; maximum LDVB iterations (default 1000). |
tol |
Numeric; convergence tolerance based on relative ELBO changes (default 1e-4). |
b0, V0 |
Prior mean and covariance for |
beta_prior |
Coefficient prior type: |
beta_prior_controls |
Optional list of prior-specific controls. For
RHS-family priors (that is, when |
a_sigma, b_sigma |
Prior for |
gamma_bounds |
Two-vector (L, U) support for |
log_prior_gamma |
Function |
init |
Optional list with starting values: |
dqlm.ind |
Logical; if |
al.ind |
Optional static-model alias for |
n.samp |
Number of samples to draw from the approximated posterior
distribution after convergence. Default is |
n_samp_xi |
Integer; retained for backward compatibility in the Laplace-Delta block. Under the current delta-only implementation this value is ignored. |
ld_controls |
Optional list of controls for the Laplace-Delta block.
Supported keys include |
vb_control |
Optional normalized VB control list, usually from
|
verbose |
Logical; print progress. |
Mean-field factorization:
q(\beta)\ \prod_{i=1}^n q(v_i)\ q(s_i)\ q(\sigma,\gamma).
This factorization induces a blockwise coordinate-ascent variational
inference scheme. The (\sigma,\gamma) block is the only nonconjugate
component, so LDVB approximates it in transformed coordinates
\eta=\mathrm{logit}((\gamma-L)/(U-L)) and \ell=\log\sigma.
The xi expectations needed by the remaining block updates are then
computed with a second-order Delta approximation. The xi expectations
used in the updates can be computed either from a
deterministic second-order Delta approximation in (\eta,\ell) or from a
Gaussian Monte Carlo sample. The Laplace-Delta controls also allow bounded
optimization in the transformed (\eta,\ell) block to better mimic the
stabilized RHS-family readout implementation. For RHS-family priors, the
prior block uses tau warmup/freeze scheduling to avoid the
early-collapse regime where global shrinkage drives all slope coefficients
toward zero before the likelihood-side variational factors stabilize.
An object of class "exalStaticLDVB" containing:
qbeta: list with m, V.
samp.beta: posterior sample from q(\beta) with
n.samp rows.
qv: list with chi (length n), psi (scalar),
E_v and E_inv_v (moments).
qs: list with mu (length n), tau2 (length n),
E_s, E_s2.
qsiggam: list with eta_hat, ell_hat,
Sigma (2x2), approximate means
gamma_mean, sigma_mean, and the xi expectations.
samp.sigma, samp.gamma: posterior samples from the
variational approximation for the scale and skewness parameters. In
the AL special case (dqlm.ind = TRUE), samp.gamma is a
vector of zeros.
converged, iter, run.time, and
misc (including p0, bounds L,U, dimensions, and ELBO trace).
beta_prior: prior metadata and, for RHS-family priors,
posterior summaries of the shrinkage hyperparameters, including
warmup/freeze-aware tau summaries and collapse diagnostics
(collapse_flag, tau_near_zero, beta_collapse,
and warning when triggered). For "rhs_ns", the state
also tracks lambda2, nu, tau2, xi, and
zeta2 with the corresponding inverse moments.
diagnostics: ELBO and joint-convergence diagnostics
including a standardized VB iteration trace at
diagnostics$vb_trace (iteration-wise ELBO / sigma / gamma /
convergence deltas), state/sigma/gamma/ELBO deltas, stopping reason,
and Laplace-Delta block trace diagnostics, including
replicated-xi controls, automatic stabilization /
cycle-detection fields, and final local-mode quality checks. For RHS
fits this also includes diagnostics$rhs with the resolved
preflight configuration and collapse diagnostics.
set.seed(123)
n <- 60
X <- cbind(1, seq(-1, 1, length.out = n))
y <- as.numeric(X %*% c(0.2, -0.1) + rnorm(n, sd = 0.15))
fit <- exalStaticLDVB(y = y, X = X, p0 = 0.5, max_iter = 60, tol = 1e-3, verbose = FALSE)
fit$converged
head(fit$diagnostics$vb_trace)
fit_rhs <- exalStaticLDVB(
y = y, X = X, p0 = 0.5,
beta_prior = "rhs",
beta_prior_controls = list(tau0 = 0.5, nu = 3, s2 = 1, shrink_intercept = FALSE),
max_iter = 50, tol = 5e-3, verbose = FALSE
)
fit_rhs$beta_prior$type
fit_rhs_ns <- exalStaticLDVB(
y = y, X = X, p0 = 0.5,
beta_prior = "rhs_ns",
beta_prior_controls = list(tau0 = 0.5, a_zeta = 1.5, b_zeta = 1, zeta2_fixed = 1),
max_iter = 50, tol = 5e-3, verbose = FALSE
)
fit_rhs_ns$beta_prior$type
fit_al <- exalStaticLDVB(
y = y, X = X, p0 = 0.5,
al.ind = TRUE,
max_iter = 50, tol = 5e-3, verbose = FALSE
)
fit_al$dqlm.ind
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.