| dmvnorm_cpp | R Documentation |
The function dmvnorm() computes the density of a multivariate normal
distribution.
The function pmvnorm() computes the cumulative distribution function of a
multivariate normal distribution, or the probability of a rectangle if
lower is specified.
The function rmvnorm() samples from a multivariate normal distribution.
The functions with suffix _cpp perform no input checks, hence are faster.
The univariate normal distribution is available as the special case p = 1.
dmvnorm_cpp(x, mean, Sigma, log = FALSE)
pmvnorm_cpp(
x,
mean,
Sigma,
abseps = 0.001,
lower = NULL,
method = "genz",
draws = 500L
)
rmvnorm_cpp(mean, Sigma, log = FALSE)
dmvnorm(x, mean, Sigma, log = FALSE)
pmvnorm(
x,
mean,
Sigma,
abseps = 0.001,
lower = NULL,
method = "genz",
draws = 500
)
rmvnorm(n = 1, mean, Sigma, log = FALSE)
x |
[ |
mean |
[ For the functions without suffix |
Sigma |
[ For For the functions without suffix |
log |
[ |
abseps |
[ |
lower |
[ For the functions without suffix |
method |
[ |
draws |
[ |
n |
[ |
For p <= 3, pmvnorm() computes the probability exactly: the bivariate
case uses the algorithm of Genz (2004) and the trivariate case integrates
the bivariate probability conditional on the third component.
For p > 3, the argument method selects the approximation:
"genz" calls mvtnorm::pmvnorm with the randomized Quasi-Monte-Carlo
procedure by Genz and Bretz. The argument abseps controls the accuracy
of the Gaussian integral approximation.
"ghk" uses the Geweke-Hajivassiliou-Keane simulator on draws
quasi-random Halton points. The result is deterministic and smooth in
x, mean, and Sigma, which makes it suitable for likelihood
evaluations, and its accuracy increases with draws.
For dmvnorm(): The density value.
For pmvnorm(): The value of the distribution function or the rectangle
probability.
For rmvnorm(): If n = 1 a vector of length p (note
that it is a column vector for rmvnorm_cpp()), else
a matrix of dimension n times p with samples as rows.
Other simulation helpers:
Simulator,
correlated_regressors(),
ddirichlet_cpp(),
dmixnorm_cpp(),
dtnorm_cpp(),
dwishart_cpp(),
gaussian_tv(),
simulate_markov_chain()
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)
# compute CDF
pmvnorm(x = x, mean = mean, Sigma = Sigma)
# compute rectangle probability
pmvnorm(x = x, mean = mean, Sigma = Sigma, lower = -1)
# simulate in higher dimensions
pmvnorm(x = rep(0, 5), mean = 0, Sigma = diag(5), method = "ghk")
# sample
rmvnorm(n = 3, mean = mean, Sigma = Sigma)
rmvnorm(mean = mean, Sigma = Sigma, log = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.