dmvnorm_cpp {oeli}R Documentation

Multivariate normal distribution

Description

The function dmvnorm() computes the density of a multivariate normal distribution.

The function rmvnorm() samples from a multivariate normal distribution.

The functions with suffix ⁠_cpp⁠ perform no input checks, hence are faster.

Usage

dmvnorm_cpp(x, mean, Sigma, log = FALSE)

rmvnorm_cpp(mean, Sigma, log = FALSE)

dmvnorm(x, mean, Sigma, log = FALSE)

rmvnorm(n = 1, mean, Sigma, log = FALSE)

Arguments

x

[numeric()]
A quantile vector of length p.

mean

[numeric()]
The mean vector of length p.

Sigma

[matrix()]
The covariance matrix of dimension p.

log

[logical(1)]
Return the logarithm of the density value?

n

[integer(1)]
An integer, the number of samples.

Value

For dmvnorm(): The density value.

For rmvnorm(): If n = 1 a vector of length p, else a matrix of dimension n times p with samples as rows.

See Also

Other simulation helpers: correlated_regressors(), ddirichlet_cpp(), dtnorm_cpp(), dwishart_cpp(), simulate_markov_chain()

Examples

x <- c(0, 0)
mean <- c(0, 0)
Sigma <- diag(2)

# compute density
dmvnorm(x = x, mean = mean, Sigma = Sigma)
dmvnorm(x = x, mean = mean, Sigma = Sigma, log = TRUE)

# sample
rmvnorm(n = 3, mean = mean, Sigma = Sigma)
rmvnorm(mean = mean, Sigma = Sigma, log = TRUE)

[Package oeli version 0.6.0 Index]