MultiNormal-dist: The Multivariate Normal distribution.

MultiNormal-distR Documentation

The Multivariate Normal distribution.

Description

Density and random sampling for the Multivariate Normal distribution.

Usage

dmNorm(x, mu, Sigma, log = FALSE)

rmNorm(n, mu, Sigma)

Arguments

x

Argument to the density function. A vector of length q or an ⁠n x q⁠ matrix.

mu

Mean vector(s). Either a vector of length q or an ⁠n x q⁠ matrix. If missing defaults to a vector of zeros.

Sigma

Covariance matrix or matrices. Either a ⁠q x q⁠ matrix or a ⁠q x q x n⁠ array. If missing defaults to the identity matrix.

log

Logical; whether or not to compute the log-density.

n

Integer number of random samples to generate.

Value

A vector for densities, or a ⁠n x q⁠ matrix for random sampling.

Examples

# Parameter specification
q <- 4 # number of dimensions
mu <- 1:q # mean vector
V <- toeplitz(exp(-seq(1:q))) # variance matrix

# Random sample
n <- 100
X <- rmNorm(n, mu, V)

# Calculate log density for each sampled vector
dmNorm(X, mu, V, log = TRUE)

mniw documentation built on Sept. 23, 2024, 1:09 a.m.