Learn R Programming

LassoHiDFastGibbs (version 0.1.5)

penalized_nested_Gibbs: Penalized nested Gibbs sampler for Bayesian linear regression

Description

Runs the nested Gibbs sampler for a Gaussian linear model \(y = X\beta + \epsilon\) with either a lasso or horseshoe penalty (shrinkage prior) on \(\beta\). The algorithm supports both \(n \ge p\) and \(p > n\) regimes.

Usage

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
)

Value

A list with components:

mBeta

Matrix of sampled \(\beta\) draws (rows correspond to stored draws).

vsigma2

Vector of sampled \(\sigma^2\) draws.

vlambda2

Vector of sampled \(\lambda^2\) draws.

lm_penalized_nested_gibbs().

Arguments

vy

Numeric response vector of length \(n\).

mX

Numeric design matrix of dimension \(n \times p\).

penalty_type

Character string: either "lasso" or "horseshoe".

a, b

Hyperparameters for the inverse-gamma prior on \(\sigma^2\).

u, v

Hyperparameters for the prior on \(\lambda^2\).

nsamples

Integer number of outer MCMC iterations.

lambda_init

Initial value for \(\lambda\).

va_init

Optional initial values for the local shrinkage parameters (length \(p\)). If NULL, a vector of ones is used.

verbose

Print progress every verbose iterations (0 = silent).

lower, upper

Bounds for the slice sampler used for \(\lambda^2\).

s_beta

Integer: number of inner updates of \(\beta\) per outer iteration.

s_siglam

Integer: number of inner updates of \((\sigma^2,\lambda^2)\) per \(\beta\) update.

Examples

Run this code
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)

Run the code above in your browser using DataLab