Learn R Programming

StealLikeBayes (version 1.0)

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

Description

Samples random numbers from an \(N\)-variate normal distribution specified by the \(N\times N\) precision matrix \(P\) and \(N\times 1\) location vector \(L\) as per: $$N(P^{-1}L, P^{-1})$$ where the precision matrix \(P\) 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 \(L\) 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

rnorm1_precision_sampler(location, precision_diag, precision_offdiag)

Value

an \(N\)-vector with random draws from the multivariate normal distribution. C++: an arma:vec vector object.

Arguments

location

an \(N\)-vector with the location parameter \(L\). C++: an arma:vec vector object.

precision_diag

an \(N\)-vector with the diagonal elements of the precision matrix \(P\). C++: an arma:vec vector object.

precision_offdiag

a numeric scalar with the off-diagonal element of the precision matrix \(P\). C++: a double scalar.

Author

Tomasz Woźniak wozniak.tom@pm.me

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)

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

Run this code
rnorm1_precision_sampler(rep(0, 100), rep(1, 100), -0.5)

Run the code above in your browser using DataLab