rmvn_prec: Sample from a multivariate normal given its precision matrix

View source: R/utility.R

rmvn_precR Documentation

Sample from a multivariate normal given its precision matrix

Description

Draws from N(mu, Q^-1) through a sparse Cholesky factorisation of the precision, Q = P' L L' P, as x = mu + P' L^-T z with z standard normal. Nothing is inverted, and the Cholesky factor keeps the sparsity of Q, so the cost is that of the factorisation rather than of a dense inverse followed by a dense n-by-n Cholesky of it. A dense precision is simply a sparse matrix with no zeros, and costs no more this way than the old route did.

Usage

rmvn_prec(n, mu, prec_mat)

Arguments

n

Number of samples

mu

Mean vector

prec_mat

Precision matrix, sparse or dense

Details

If prec_mat is not positive definite – a fit that has not converged, or a singular Hessian – there is no Cholesky factor to be had, and this falls back on prec_to_cov, which uses a generalised inverse and warns.

Value

Matrix with one row for each sample and one column for each element of mu


hmmTMB documentation built on Nov. 10, 2026, 5:09 p.m.