| Title: | Fast High-Dimensional Gibbs Samplers for Bayesian Lasso Regression |
|---|---|
| Description: | Provides fast and scalable Gibbs sampling algorithms for Bayesian Lasso regression model in high-dimensional settings. The package implements efficient partially collapsed and nested Gibbs samplers for Bayesian Lasso, with a focus on computational efficiency when the number of predictors is large relative to the sample size. Methods are described at Davoudabadi and Ormerod (2026) <https://github.com/MJDavoudabadi/LassoHiDFastGibbs>. |
| Authors: | John Ormerod [aut] (ORCID: <https://orcid.org/0000-0002-4650-7507>), Mohammad Javad Davoudabadi [aut, cre, cph], Garth Tarr [aut] (ORCID: <https://orcid.org/0000-0002-6605-7478>), Samuel Mueller [aut] (ORCID: <https://orcid.org/0000-0002-3087-8127>), Jonathon Tidswell [ctb] (Contributed code to src/lasso_distribution.cpp (originally from BayesianLasso package)) |
| Maintainer: | Mohammad Javad Davoudabadi <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.5 |
| Built: | 2026-05-25 10:28:54 UTC |
| Source: | https://github.com/mjdavoudabadi/lassohidfastgibbs |
Implements a two-block Gibbs sampler for the Bayesian lasso regression model
in which the regression coefficients are updated jointly with the global
shrinkage parameter in one block, while the noise variance and
local shrinkage parameters are updated conditionally in separate steps.
blasso_gibbs_2block_bl( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(nsamples/5)), lower = 1e-12, upper = 5000 )blasso_gibbs_2block_bl( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(nsamples/5)), lower = 1e-12, upper = 5000 )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
a, b
|
Hyperparameters for the inverse-gamma prior on sigma^2. |
u, v
|
Hyperparameters for the prior on lambda^2. |
nsamples |
Integer number of MCMC iterations. |
lambda_init |
Initial value for lambda. |
sigma2_init |
Initial value for sigma^2. |
va_init |
Optional initial values for local shrinkage parameters (length p). |
verbose |
Print progress every |
lower, upper
|
Bounds used by the slice sampler for lambda^2. |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 30; p <- 6 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- blasso_gibbs_2block_bl( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)set.seed(1) n <- 30; p <- 6 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- blasso_gibbs_2block_bl( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)
Implements a two-block Gibbs sampler for the Bayesian lasso regression model
in which the regression coefficients are updated jointly with the noise variance
in one block, while the global shrinkage parameter and
local shrinkage parameters are updated conditionally in separate steps.
blasso_gibbs_2block_bs( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(nsamples/5)) )blasso_gibbs_2block_bs( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(nsamples/5)) )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
a, b
|
Hyperparameters for the inverse-gamma prior on sigma^2. |
u, v
|
Hyperparameters for the prior on lambda^2. |
nsamples |
Integer number of MCMC iterations. |
lambda_init |
Initial value for lambda. |
sigma2_init |
Initial value for sigma^2. |
verbose |
Print progress every |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 30; p <- 6 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- blasso_gibbs_2block_bs( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)set.seed(1) n <- 30; p <- 6 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- blasso_gibbs_2block_bs( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)
Lasso-specific Partially-collapsed Gibbs (PCG) variant with the local scales (va) collapsed in the
update.
blasso_pcg_lambda2_va( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )blasso_pcg_lambda2_va( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
verbose |
Print progress every |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- blasso_pcg_lambda2_va( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) summary(out$vlambda2)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- blasso_pcg_lambda2_va( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) summary(out$vlambda2)
Lasso-specific Partially-collapsed Gibbs (PCG) variant with the local scales (va) collapsed in the
update.
blasso_pcg_sigma2_va( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )blasso_pcg_sigma2_va( vy, mX, a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
va_init |
Optional initial local-scale vector (length p). If |
verbose |
Print progress every |
lower, upper
|
Bounds used by the slice sampler. |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- blasso_pcg_sigma2_va( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) summary(out$vsigma2)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- blasso_pcg_sigma2_va( vy = y, mX = X, a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) summary(out$vsigma2)
Provides fast and scalable Gibbs sampling algorithms for Bayesian Lasso regression model in high-dimensional settings. The package implements efficient partially collapsed and nested Gibbs samplers for Bayesian Lasso, with a focus on computational efficiency when the number of predictors is large relative to the sample size.
Maintainer: Mohammad Javad Davoudabadi [email protected] [copyright holder]
Authors:
John Ormerod [email protected] (ORCID)
Garth Tarr [email protected] (ORCID)
Samuel Mueller [email protected] (ORCID)
Other contributors:
Jonathon Tidswell (Contributed code to src/lasso_distribution.cpp (originally from BayesianLasso package)) [contributor]
Useful links:
Report bugs at https://github.com/MJDavoudabadi/LassoHiDFastGibbs/issues
This function centers and (optionally) scales the response vector and each column of the design matrix using the population variance. It is used to prepare data for Bayesian Lasso regression.
normalize(y, X, scale = TRUE)normalize(y, X, scale = TRUE)
y |
A numeric response vector. |
X |
A numeric matrix or data frame of covariates (design matrix). |
scale |
Logical; if |
A list with the following elements:
vy: Normalized response vector.
mX: Normalized design matrix.
mu.y: Mean of the response vector.
sigma2.y: Population variance of the response vector.
mu.x: Vector of column means of X.
sigma2.x: Vector of population variances for columns of X.
set.seed(1) X <- matrix(rnorm(100 * 10), 100, 10) beta <- c(2, -3, rep(0, 8)) y <- as.vector(X %*% beta + rnorm(100)) norm_result <- normalize(y, X)set.seed(1) X <- matrix(rnorm(100 * 10), 100, 10) beta <- c(2, -3, rep(0, 8)) y <- as.vector(X %*% beta + rnorm(100)) norm_result <- normalize(y, X)
Runs the nested Gibbs sampler for a Gaussian linear model
with either a lasso or horseshoe penalty
(shrinkage prior) on . The algorithm supports both
and regimes.
penalized_nested_Gibbs( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000, s_beta = 1L, s_siglam = 1L )penalized_nested_Gibbs( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000, s_beta = 1L, s_siglam = 1L )
vy |
Numeric response vector of length |
mX |
Numeric design matrix of dimension |
penalty_type |
Character string: either |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Integer number of outer MCMC iterations. |
lambda_init |
Initial value for |
va_init |
Optional initial values for the local shrinkage parameters
(length |
verbose |
Print progress every |
lower, upper
|
Bounds for the slice sampler used for |
s_beta |
Integer: number of inner updates of |
s_siglam |
Integer: number of inner updates of |
A list with components:
Matrix of sampled draws (rows correspond to stored draws).
Vector of sampled draws.
Vector of sampled draws.
lm_penalized_nested_gibbs().
set.seed(1) n <- 50; p <- 10 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- penalized_nested_Gibbs( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, va_init = NULL, verbose = 0, lower = 1e-12, upper = 5000, s_beta = 1, s_siglam = 1 ) str(out)set.seed(1) n <- 50; p <- 10 X <- matrix(rnorm(n * p), n, p) y <- rnorm(n) out <- penalized_nested_Gibbs( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, va_init = NULL, verbose = 0, lower = 1e-12, upper = 5000, s_beta = 1, s_siglam = 1 ) str(out)
Partially-collapsed Gibbs (PCG) sampler variant that updates in a dedicated block and samples
using a collapsed step over .
penalized_pcg_beta_sigma2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )penalized_pcg_beta_sigma2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
penalty_type |
Character string: |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
verbose |
Print progress every |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_beta_sigma2( vy = y, mX = X, penalty_type = "horseshoe", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) summary(out$mBeta)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_beta_sigma2( vy = y, mX = X, penalty_type = "horseshoe", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) summary(out$mBeta)
Partially-collapsed Gibbs (PCG) sampler for a Gaussian linear model with a
shrinkage prior/penalty on regression coefficients. This variant samples
using a collapsed step over (see implementation).
penalized_pcg_lambda2_sigma2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )penalized_pcg_lambda2_sigma2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, verbose = max(1L, floor(as.integer(nsamples)/10)) )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
penalty_type |
Character string: |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
verbose |
Print progress every |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_lambda2_sigma2( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_lambda2_sigma2( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, verbose = 0 ) str(out)
Partially-collapsed Gibbs (PCG) sampler variant that samples using a collapsed step over
. Requires initial values for local scales va_init.
penalized_pcg_sigma2_beta( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )penalized_pcg_sigma2_beta( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
penalty_type |
Character string: |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
va_init |
Optional initial local-scale vector (length p). If |
verbose |
Print progress every |
lower, upper
|
Bounds used by the slice sampler. |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_sigma2_beta( vy = y, mX = X, penalty_type = "horseshoe", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) summary(out$vsigma2)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_sigma2_beta( vy = y, mX = X, penalty_type = "horseshoe", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) summary(out$vsigma2)
Partially-collapsed Gibbs (PCG) sampler variant that samples using a collapsed step over
(see implementation). Requires initial values for local scales
va_init; if omitted, it is set to a vector of ones.
penalized_pcg_sigma2_lambda2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )penalized_pcg_sigma2_lambda2( vy, mX, penalty_type = c("lasso", "horseshoe"), a, b, u, v, nsamples, lambda_init = 1, sigma2_init = 1, va_init = NULL, verbose = max(1L, floor(as.integer(nsamples)/10)), lower = 1e-12, upper = 5000 )
vy |
Numeric response vector of length n. |
mX |
Numeric design matrix of dimension n x p. |
penalty_type |
Character string: |
a, b
|
Hyperparameters for the inverse-gamma prior on |
u, v
|
Hyperparameters for the prior on |
nsamples |
Number of MCMC iterations. |
lambda_init |
Initial value for |
sigma2_init |
Initial value for |
va_init |
Optional initial local-scale vector (length p). If |
verbose |
Print progress every |
lower, upper
|
Bounds used by the slice sampler. |
A list with components:
Matrix of beta draws (nsamples x p).
Vector of sigma^2 draws (length nsamples).
Vector of lambda^2 draws (length nsamples).
set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_sigma2_lambda2( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) str(out)set.seed(1) n <- 40; p <- 6 X <- matrix(rnorm(n * p), n, p) beta <- c(1.2, 2, -1, 0.5, 0.75, 2.5) y <- X %*% beta + rnorm(n) out <- penalized_pcg_sigma2_lambda2( vy = y, mX = X, penalty_type = "lasso", a = 1, b = 1, u = 1, v = 1, nsamples = 200, lambda_init = 1, sigma2_init = 1, va_init = rep(1, p), verbose = 0 ) str(out)