Package 'StealLikeBayes'

Title: A Compendium of Bayesian Statistical Routines Written in 'C++'
Description: This is a compendium of 'C++' routines useful for Bayesian statistics. We steal other people's 'C++' code, repurpose it, and export it so developers of 'R' packages can use it in their 'C++' code. We actually don't steal anything, or claim that Thomas Bayes did, but copy code that is compatible with our GPL 3 licence, fully acknowledging the authorship of the original code.
Authors: Tomasz Woźniak [aut, cre] (ORCID: <https://orcid.org/0000-0003-2212-2378>, contributions: contributions: rmvnorm1_precision_sampler, rgennorm, rgig1), Xiaolei Wang [aut] (ORCID: <https://orcid.org/0009-0005-6192-9061>, contributions: contributions: rhaar1), Longcan Li [aut] (ORCID: <https://orcid.org/0009-0007-2190-768X>, contributions: contributions: sample_variances_horseshoe), Jianying Shelly Xie [aut] (ORCID: <https://orcid.org/0009-0008-6451-6416>, contributions: contributions: sample_variances_normal_gamma), Filip Reierson [aut] (ORCID: <https://orcid.org/0009-0003-2393-5810>, contributions: contributions: rtmvnorm), Kenyon Ng [aut] (ORCID: <https://orcid.org/0000-0002-6315-9831>, contributions: contributions: rtmvnorm_hmc)
Maintainer: Tomasz Woźniak <[email protected]>
License: GPL (>= 3)
Version: 1.0.0.9000
Built: 2026-06-03 11:28:25 UTC
Source: https://github.com/bsvars/steallikebayes

Help Index


Samples random draws from a generalised normal distribution using the Gibbs sampler by Waggoner & Zha (2003a)

Description

Samples random numbers from a generalised normal distribution for a restricted N×NN\times N full rank matrix XX. The matrix is drawn row-by-row from their full conditional distributions using the Gibbs sampler by Waggoner & Zha (2003a). The density is proportional to

det(X)νNexp(12n=1NxnVnSnVnxn)det(X)^{\nu - N}\exp(-\frac{1}{2}\sum_{n=1}^{N}x_nV_nS_nV_n'x_n')

specified by the N×NN\times N scale matrices SnS_n, a positive scalar-valued shape parameter ν\nu, and rn×Nr_n\times N selection matrices VnV_n defining the restrictions. Zero restrictions may be imposed on th XX matrix row-by-row as

Xn.=xnVnX_{n.} = x_nV_n

where 1×rn1\times r_n vectors xnx_n collect the unrestricted elements of Xn.X_{n.} and the matrices VnV_n place them in appropriate spots of the 1×N1\times N row Xn.X_{n.}. The output may be normalised using the method by Waggoner & Zha (2003b) ensuring positive diagonal elements of the output matrices.

This method is useful for sampling the structural matrix of the structural vector autoregressive models identified by exclusion restrictions, sign and exclusion restrictions, heteroskedasticity, and instrumental variables.

Usage

rgennorm(n, X, S, nu, V, normalise = TRUE)

Arguments

n

a positive integer with the number of draws to be sampled. C++: a int object.

X

an N×NN\times N structural matrix with the starting values to initiate the Gibbs sampler. C++: an arma::mat matrix object.

S

an N×N×NN\times N\times N array with N×NN\times N row-specific precision matrices SnS_n. C++: an arma::cube object.

nu

a positive integer number with the shape parameter nunu. C++: an int object.

V

a list with NN elements each including rn×Nr_n\times N matrices VnV_n. C++: an arma::field<arma::mat> object.

normalise

a logical value of whether the output should be normalised following the method by Waggoner & Zha (2003b) ensuring positive signs of the diagonal elements of the sampled matrices. C++: an bool object.

Details

This function is based on C++ code from the R package bsvars by Woźniak (2024,2025) and is using objects and commands from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025).

Value

an N×N×nN\times N\times n-array with random draws from the generalised normal distribution. C++: an arma::cube object.

Author(s)

Tomasz Woźniak [email protected]

References

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Waggoner D.F., Zha T., (2003a). A Gibbs Sampler for Structural Vector Autoregressions. Journal of Economic Dynamics and Control, 28(2), 349-366, <doi:10.1016/S0165-1889(02)00168-9>.

Waggoner, D.F., Zha, T. (2003b). Likelihood Preserving Normalization in Multiple Equation Models. Journal of Econometrics, 114(2), 329-347. <doi:10.1016/S0304-4076(03)00087-3>

Woźniak T. (2024). bsvars: Bayesian Estimation of Structural Vector Autoregressive Models, R package version 3.2, <doi:10.32614/CRAN.package.bsvars>.

Woźniak T. (2025). Fast and Efficient Bayesian Analysis of Structural Vector Autoregressions Using the R Package bsvars. University of Melbourne Working Paper, 1–25. <doi:10.48550/arXiv.2410.15090>.

Examples

rgennorm(1, diag(2), array(diag(2), c(2,2,2)), 3, list(diag(2), matrix(1,1,2)))

Samples random draws from the generalized inverse Gaussian distribution

Description

Samples random numbers from the generalized inverse Gaussian distribution with density proportional to:

f(x)=xλ1e12(χ/x+ψx),f(x) = x^{\lambda - 1} e^{-\frac{1}{2}(\chi/x + \psi x)},

with the parameters having to satisfy the conditions:

λ>0,ψ>0,χ0,orλ=0,ψ>0,χ>0,orλ<0,ψ0,χ>0.% \begin{array}{l} \lambda > 0,\, \psi > 0, \chi \geq 0, \quad\mbox{or} \\ \lambda = 0,\, \psi > 0, \chi > 0, \quad\mbox{or} \\ \lambda < 0,\, \psi \geq 0, \chi > 0. \end{array}

The sampling algorithm proposed by Hörmann & Leydold (2013) is implemented. If the arguments do not satisfy the restrictions a std::logic_error exception is thrown in C++.

This method is useful for sampling variance coefficients that arise in problems with their likelihood in the form of th inverse gamma distribution and assuming a gamma prior.

Usage

rgig1(lambda, chi, psi)

Arguments

lambda

a real scalar representing parameter λ\lambda. C++: a double object.

chi

a real scalar representing parameter χ\chi. C++: a double object.

psi

a real scalar representing parameter ψ\psi. C++: a double object.

Details

This function is based on C++ code from the R package shrinkTVP by Knaus, Bitto-Nemling, Cadonna, Frühwirth-Schnatter (2021) and also uses functionality of the GIGrvg package by Leydold & Hörmann (2023). It uses random number generators from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025)

Value

random draw from the GIG distribution. C++: a double object.

Author(s)

Tomasz Woźniak [email protected]

References

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Hörmann W., Leydold J. (2013). Generating generalized inverse Gaussian random variates, Statistics and Computing 24, 547–557, <doi:10.1007/s11222-013-9387-3>.

Leydold J., Hörmann W. (2023). GIGrvg: Random Variate Generator for the GIG Distribution, R package version 0.8, <doi:10.32614/CRAN.package.GIGrvg>.

Knaus, P., Bitto-Nemling, A., Cadonna, A., & Frühwirth-Schnatter, S. (2021). Shrinkage in the Time-Varying Parameter Model Framework Using the R Package shrinkTVP. Journal of Statistical Software, 100(13), 1–32. <doi:10.18637/jss.v100.i13>.

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Examples

rgig1(1, 1, 1)

Sample random matrices from Haar distribution

Description

This function samples random orthogonal matrices from the Haar distribution, that is, the uniform distribution over the space of orthogonal matrices.

Usage

rhaar1(n)

Arguments

n

a positive integer scalar specifying the dimension of the orthogonal matrix. C++: an int scalar.

Details

This function is based on C++ code from the R package bsvarSIGNs by Wang X., Woźniak T. (2025a,2025b) and is using objects and commands from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025)

Value

An n×nn\times n matrix with a random draw of the orthogonal matrix from the Haar distribution. C++: an arma::mat object.

Author(s)

Xiaolei Wang [email protected]

References

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Stewart, G. W. (1980). The efficient generation of random orthogonal matrices with an application to condition estimators. SIAM Journal on Numerical Analysis, 17(3), 403-409. <doi:10.1137/0717034>

Wang X., Woźniak T. (2025a). bsvarSIGNs: Bayesian SVARs with Sign, Zero, and Narrative Restrictions. R package version 2.0, <doi:0.32614/CRAN.package.bsvarSIGNs>.

Wang X., Woźniak T. (2025b). Bayesian Analyses of Structural Vector Autoregressions with Sign, Zero, and Narrative Restrictions Using the R Package bsvarSIGNs, <doi:10.48550/arXiv.2501.16711>.

Examples

rhaar1(3)

Samples random draws from a multivariate normal distribution using the precision sampler by Chan & Jeliazkov (2009)

Description

Samples random numbers from an NN-variate normal distribution specified by the N×NN\times N precision matrix PP and N×1N\times 1 location vector LL as per:

N(P1L,P1)N(P^{-1}L, P^{-1})

where the precision matrix PP is bi-diagonal with the diagonal elements given in the vector argument precision_diag and the off-diagonal element is given in the scalar argument precision_offdiag, and the location vector LL is provided in the vector argument location.

This method is useful for the simulation smoother of the linear Gaussian state-space models with the state variable specified by the autoregressive dynamics with one lag, AR(1). See Woźniak (2021) for more details.

Usage

rmvnorm1_precision_sampler(location, precision_diag, precision_offdiag)

Arguments

location

an NN-vector with the location parameter LL. C++: an arma::vec vector object.

precision_diag

an NN-vector with the diagonal elements of the precision matrix PP. C++: an arma::vec vector object.

precision_offdiag

a numeric scalar with the off-diagonal element of the precision matrix PP. C++: a double scalar.

Details

This function is based on C++ code from the R package stochvol by Hosszejni & Kastner (2025) and Kastner G. (2016) and is using objects and commands from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025)

Value

an NN-vector with random draws from the multivariate normal distribution. C++: an arma::vec vector object.

Author(s)

Tomasz Woźniak [email protected]

References

Chan J.C.C., Jeliazkov I. (2009). Efficient simulation and integrated likelihood estimation in state space models. International Journal of Mathematical Modelling and Numerical Optimisation, 1(1/2), <doi:10.1504/IJMMNO.2009.030090>.

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Hosszejni D., Kastner G. (2025). stochvol: Efficient Bayesian Inference for Stochastic Volatility (SV) Models. R package version 3.2.8, <doi:10.32614/CRAN.package.stochvol>

Kastner G. (2016). Dealing with Stochastic Volatility in Time Series Using the R Package stochvol. Journal of Statistical Software, 69(5), 1–30. <doi:10.18637/jss.v069.i05>.

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Woźniak T. (2021). Simulation Smoother using RcppArmadillo, RcppGallery https://gallery.rcpp.org/articles/simulation-smoother-using-rcpparmadillo/

Examples

rmvnorm1_precision_sampler(rep(0, 100), rep(1, 100), -0.5)

Sample Random Draws From the Truncated Multivariate Normal Using the Algorithm Proposed by Yifang Li and Sujit K. Ghosh (2015)

Description

Samples random numbers from a truncated multivariate normal distribution with parameters mean vector, covariance matrix, and linear inequality constraints of the form lBxul \leq Bx \leq u, where BB is a constraint matrix and ll and uu are lower and upper bounds. The function uses a Gibbs sampling algorithm to generate draws from the constrained distribution.

The truncated multivariate normal is important for research in Bayesian statistics, econometrics, and any field requiring parameter estimation subject to inequality constraints. Common applications include censored regression models, portfolio optimization with constraints, and prior distributions with bounded support.

Usage

rtmvnorm(mean, sigma, blc, lower, upper, init, burn = 10)

Arguments

mean

an n×pn\times p matrix of means. n is the number of draws to be sampled. p is the dimension of the draws. C++: an arma::mat object.

sigma

a p×pp\times p covariance matrix for the draws. C++: an arma::mat object.

blc

an m×pm\times p matrix of coefficients for linear inequality constraints. C++: an arma::mat object.

lower

an n×mn\times m matrix of lower truncation bounds. C++: an arma::mat object.

upper

an n×mn\times m matrix of upper truncation bounds. C++: an arma::mat object.

init

an n×pn\times p matrix of initial values for the algorithm. C++: an arma::mat object.

burn

number of iterations used as burn-in. Defaults is 10. C++: an arma::uword object.

Details

This function is based on C++ code from the R package tmvtnsim by Lu (2025) and is using objects and commands from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025).

Value

An n×pn\times p matrix of draws from the specified truncated multivariate normal. C++: an arma::mat object.

Author(s)

Filip Reierson [email protected]

References

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Li, Y., Ghosh, S.K. Efficient sampling methods for truncated multivariate normal and student-t distributions subject to linear inequality constraints. J Stat Theory Pract 9, 712–732 (2015). <doi:10.1080/15598608.2014.996690>

Lu K. (2025). tmvtnsim: Truncated Multivariate Normal and t Distribution Simulation. R package version 0.1.4, <doi:10.32614/CRAN.package.tmvtnsim>

Examples

rtmvnorm(mean = matrix(c(0, 0), nrow = 1), sigma = diag(2), 
         blc = diag(2), lower = matrix(c(-Inf, -Inf), nrow = 1), 
         upper = matrix(c(1, 1), nrow = 1), init = matrix(c(0, 0), 
         nrow = 1), burn = 10)

Generate Truncated Multivariate Normal Samples via Hamiltonian Monte Carlo

Description

Generate pp-dimensional truncated multivariate normal samples that satisfy an inequality constraint

F×x+g0,F \times x + g \ge 0,

where xx is a column vector of the generated sample. The sampler is an exact Hamiltonian Monte Carlo (HMC) sampler as described in Pakman and Paninski (2014).

Usage

rtmvnorm_hmc(n, mean, cov, initial, Fmat, g, burn)

Arguments

n

a positive integer with the number of samples. C++: an int object.

mean

a pp-dimensional mean vector. C++: an Eigen::VectorXd object.

cov

a p×pp \times p covariance matrix of the normal distribution. C++: an Eigen::MatrixXd object.

initial

a pp-dimensional initial value vector for the Markov chain. C++: an Eigen::VectorXd object.

Fmat

an m×pm \times p constraint matrix FF defining linear inequalities, where mm is the number of constraints. C++: an Eigen::MatrixXd object.

g

an mm-dimensional constraint vector defining linear inequalities. C++: an Eigen::VectorXd object.

burn

a non-negative integer with the number of burn-in iterations before collecting samples. C++: an int object.

Details

The function generates samples from a truncated multivariate normal distribution with mean mean and covariance cov, subject to linear constraints defined by Fmat and g.

The user should supply an initial value that strictly satisfies the inequality constraints, although the generated samples only satisfy them weakly.

No check for symmetry is performed on the covariance matrix.

It is advisable to use a small burn-in period (e.g., 10) to allow the Markov chain to reach stationarity.

This function is a wrapper around a C++ implementation adapted from the 'tnorm' R package by Kenyon Ng.

Value

An n×pn \times p matrix with each row corresponding to a sample. C++: an Eigen::MatrixXd object.

References

Pakman, A. and Paninski, L. (2014). Exact Hamiltonian Monte Carlo for Truncated Multivariate Gaussians. Journal of Computational and Graphical Statistics, 23(2), 518–542. <doi:10.1080/10618600.2013.788448>

Ng, K. (2024). tnorm: Generate Multivariate Truncated Normal Samples. R package version 0.0.1. <https://github.com/weiyaw/tnorm>

Bates, D. and Eddelbuettel, D. (2013). Fast and Elegant Numerical Linear Algebra Using the RcppEigen Package. Journal of Statistical Software, 52(5), 1–24. <doi:10.18637/jss.v052.i05>

Examples

rtmvnorm_hmc(1, c(0, 0), diag(2), c(0, 2), diag(2), c(1, -1), 1)

Samples variances from the horseshoe prior using Gruber & Kastner (2024)

Description

Performs one Gibbs sampling iteration for the **exported hyper-parameters** #' of the horseshoe prior variance parameters: local variances (λj2\lambda_j^2, argument theta), global variance (τ2\tau^2, argument zeta), and their corresponding auxiliary variables (νj\nu_j and ϖ\varpi, arguments nu and varpi). The horseshoe prior Carvalho, Polson, Scott (2010) is a continuous shrinkage prior for Bayesian variable selection with the hierarchical structure:

βjN(0,λj2τ2)\beta_j \sim N(0, \lambda_j^2 \tau^2)

λjC+(0,1)\lambda_j \sim C^+(0, 1)

τC+(0,1)\tau \sim C^+(0, 1)

where C+(0,1)C^+(0, 1) denotes the half-Cauchy distribution, λj2\lambda_j^2 are the local shrinkage parameters (argument theta), and τ2\tau^2 is the global shrinkage parameter (argument zeta). The prior variance for coefficient jj is Vi,j=λj2τ2V_{i,j} = \lambda_j^2 \tau^2.

The half-Cauchy distributions are represented using auxiliary variables νj\nu_j and ϖ\varpi to facilitate Gibbs sampling. This implementation allows updating only a subset of coefficients specified by the indices in argument ind.

Usage

sample_variances_horseshoe(coefs, theta, zeta, nu, varpi)

Arguments

coefs

a pp-vector with the current coefficient values βj\beta_j. C++: an arma::vec vector object.

theta

a pp-vector with the local variance parameters λj2\lambda_j^2, updated by reference. C++: an arma::vec vector object.

zeta

a numeric scalar with the global variance parameter τ2\tau^2, updated by reference. C++: a double scalar.

nu

a pp-vector with auxiliary variables for the local shrinkage, updated by reference. C++: an arma::vec vector object.

varpi

a numeric scalar with the auxiliary variable for the global shrinkage, updated by reference. C++: a double scalar.

Details

This function is based on C++ code from the R package bayesianVARs by Gruber & Kastner (2024) and is using objects and commands from the armadillo library. Thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025).

Value

A **list** of C++ objects of class Rcpp::List containing the updated variance parameters. The elements are:

  • V_i: A pp-vector of the total prior variances λj2τ2\lambda_j^2 \tau^2. R: a **numeric vector**. C++: an arma::vec object.

  • theta: The updated pp-vector of local variances λj2\lambda_j^2. R: a **numeric vector**. C++: an arma::vec object.

  • zeta: The updated scalar global variance τ2\tau^2. R: a **positive scalar**. C++: a double scalar.

  • nu: The updated pp-vector of local auxiliary variables νj\nu_j. R: a **numeric vector**. C++: an arma::vec object.

  • varpi: The updated scalar global auxiliary variable ϖ\varpi. R: a **positive scalar**. C++: a double scalar.

Author(s)

Longcan Li [email protected]

References

Carvalho C.M., Polson N.G., Scott J.G. (2010). The horseshoe estimator for sparse signals. Biometrika, 97(2), 465-480. <doi:10.1093/biomet/asq017>

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Gruber L.,Kastner G. (2024). bayesianVARs: MCMC Estimation of Bayesian Vector Autoregressions. R package version 0.1.5, <doi:10.32614/CRAN.package.bayesianVARs>

Makalic E., Schmidt D.F. (2016). A Simple Sampler for the Horseshoe Estimator. IEEE Signal Processing Letters, 23(1), 179-182. <doi:10.1109/LSP.2015.2503725>

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Examples

sample_variances_horseshoe( rep(0, 2), rep(0, 2), 1, rep(1, 2), 1)

Samples variances of the Normal-Gamma prior distribution by Brown & Griffin (2010).

Description

This function samples variances as well as the hyper-parameters ϑi\vartheta_i and ζ\zeta from a Normal-Gamma prior distribution. The prior distribution has a hierarchical structure where each element xix_i of a kk-vector XX follows:

xiN(0,ϑiζj),ϑiG(aj,aj/2), and ζj1G(b,c)x_i \sim N(0,\vartheta_i \zeta_j), \vartheta_i \sim G(a_j, a_j / 2) \text{, and } \zeta_j^{-1} \sim G(b,c)

for i=j=1,,ki=j=1,\dots,k. The hyperparameter aja_j follows an i.i.d. discrete hyperprior with Pr(aj=a~r)=pr\Pr(a_j = \tilde{a}_r) = p_r, where a~=(a~1,,a~R)\tilde{a} = (\tilde{a}_1, \dots, \tilde{a}_R)' is the vector of strictly positive support points. See Brown & Griffin (2010) and Gruber & Kastner (2025) for further details.

Usage

sample_variances_normal_gamma(
  x,
  theta_tilde,
  zeta,
  a,
  a_vec,
  varrho0,
  varrho1,
  hyper,
  tol = 1e-06
)

Arguments

x

A starting values vector of the variances. C++: an arma::vec vector object.

theta_tilde

A starting values vector of ϑi\vartheta_i. C++:an arma::vec vector object.

zeta

A starting value of ζj\zeta_j. C++: an double object.

a

Prior shape parameter of the Gamma distribution for ϑi\vartheta_i. C++: an double object.

a_vec

Multinomial grid for updating shape parameter of the Gamma distribution.C++: an arma::vec vector object.

varrho0

Prior shape parameter of the Gamma distribution for ζj\zeta_j. C++: an double object.

varrho1

Prior scale parameter of the Gamma distribution for ζj\zeta_j. C++: an double object.

hyper

A logical value. TRUE or FALSE. C++: an bool object

tol

The numerical tolerance, default is '1e-06'. C++: an double object.

Details

This function is based on C++ code from the R package bayesianVARs by Gruber (2025) and is using objects and commands from the armadillo library by Sanderson & Curtin (2025) thanks to the RcppArmadillo package by Eddelbuettel, Francois, Bates, Ni, & Sanderson (2025).

Value

A **list** of C++ objects of class Rcpp::List containing the updated variance parameters. The elements are:

  • V_i A vector of variances of the Normal-Gamma prior distribution. R: a **numeric vector**. C++: an arma::vec object.

  • theta_tilde An updated vector of ϑi\vartheta_i. R: a **numeric vector**. C++: an arma::vec object.

  • zeta: An updated vector of ζj\zeta_j. R: a **positive scalar**. C++: an double object.

Author(s)

Jianying Shelly Xie [email protected]

References

Gruber, L. (2025). bayesianVARs: MCMC Estimation of Bayesian Vectorautoregressions. R package version 0.1.5.9000, <doi: 10.32614/CRAN.package.bayesianVARs>.

Gruber, L., & Kastner, G. (2025). Forecasting macroeconomic data with Bayesian VARs: Sparse or dense? It depends!. International Journal of Forecasting, 41(4), 1589-1619, <doi:org/10.1016/j.ijforecast.2025.02.001>.

Philip J. Brown., Jim E. Griffin (2010). Inference with normal-gamma prior distributions in regression problems. Bayesian Analysis, 5(1), 171-188, <doi:org/10.1214/10-BA507>.

Eddelbuettel D., Francois R., Bates D., Ni B., Sanderson C. (2025). RcppArmadillo: 'Rcpp' Integration for the 'Armadillo' Templated Linear Algebra Library. R package version 15.0.2-2. <doi:10.32614/CRAN.package.RcppArmadillo>

Sanderson C., Curtin R. (2025). Armadillo: An Efficient Framework for Numerical Linear Algebra. International Conference on Computer and Automation Engineering, 303-307, <doi:10.1109/ICCAE64891.2025.10980539>

Examples

sample_variances_normal_gamma(rep(0,2), rep(1,2), 1, 1, rep(1,2), 1, 1, TRUE, 1e-6)