mvdist: Multivariate random number generators

mvdistR Documentation

Multivariate random number generators

Description

Random generation for common multivariate distributions. All functions return an ⁠n x d⁠ matrix with column names, and accept an optional seed.

  • r_mvnorm(): multivariate normal N(\mu, \Sigma).

  • r_mvt(): multivariate Student-t with df degrees of freedom and scale matrix sigma.

  • r_mvlnorm(): multivariate log-normal: exp() of a multivariate normal with parameters meanlog, sigmalog.

  • r_mvskewnorm(): multivariate skew-normal of Azzalini and Dalla Valle (1996) with location xi, scale matrix omega and shape alpha.

  • r_dirichlet(): Dirichlet distribution on the simplex, generated by normalising gamma draws. Draws are computed on the log scale (with the Y U^{1/a} boost for shapes below 1), so very small concentration parameters do not underflow to 0/0; as \alpha \to 0 the draws approach the vertices of the simplex.

  • r_mvmixture(): finite mixture of multivariate normals.

Usage

r_mvnorm(n, mean = NULL, sigma, seed = NULL)

r_mvt(n, df, mean = NULL, sigma, seed = NULL)

r_mvlnorm(n, meanlog = NULL, sigmalog, seed = NULL)

r_mvskewnorm(n, xi = NULL, omega, alpha, seed = NULL)

r_dirichlet(n, alpha, seed = NULL)

r_mvmixture(n, weights, means, sigmas, return_component = FALSE, seed = NULL)

Arguments

n

Number of draws.

mean, xi

Mean / location vector (finite; defaults to zero).

sigma, omega

Covariance (scale) matrix: square, finite, symmetric and positive semi-definite. omega must also have a strictly positive diagonal, because the skew-normal is parameterised through the correlation matrix \bar\Omega = \omega^{-1}\Omega\omega^{-1}. sigma may be singular (positive semi-definite), giving a degenerate normal or t distribution; omega must be positive definite, as in the standard definition of the skew-normal density.

seed

Optional random seed.

df

Degrees of freedom (Inf gives the normal distribution).

meanlog, sigmalog

Mean vector and covariance matrix on the log scale.

alpha

Shape (skewness) vector for r_mvskewnorm(); concentration vector for r_dirichlet().

weights

Mixture weights (normalised internally).

means

List of component mean vectors.

sigmas

List of component covariance matrices.

return_component

Should r_mvmixture() add the component label as attribute "component"?

Value

A numeric matrix with n rows.

References

Azzalini, A. and Dalla Valle, A. (1996). The multivariate skew-normal distribution. Biometrika, 83(4), 715–726. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/83.4.715")}

Examples

S <- make_corr(3, "ar1", 0.6)
x <- r_mvnorm(1000, mean = c(0, 1, 2), sigma = S, seed = 1)
round(cor(x), 2)

t3 <- r_mvt(500, df = 3, sigma = S)
sn <- r_mvskewnorm(500, omega = S, alpha = c(5, 0, -5))
dir <- r_dirichlet(5, alpha = c(1, 2, 3))
rowSums(dir)

mix <- r_mvmixture(500, weights = c(0.3, 0.7),
                   means = list(c(-2, -2), c(2, 2)),
                   sigmas = list(diag(2), diag(2)))

SynthesizerPlus documentation built on Oct. 16, 2026, 5:10 p.m.