[Stable]

The multivariate normal distribution is a generalization of the univariate normal distribution to higher dimensions. It is widely used in multivariate statistics and describes the joint distribution of multiple correlated continuous random variables.

dist_multivariate_normal(mu = 0, sigma = list(diag(1)))

Arguments

mu

A list of numeric vectors for the distribution's mean.

sigma

A list of matrices for the distribution's variance-covariance matrix.

Details

We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_multivariate_normal.html

In the following, let \(\mathbf{X}\) be a \(k\)-dimensional multivariate normal random variable with mean vector mu = \(\boldsymbol{\mu}\) and variance-covariance matrix sigma = \(\boldsymbol{\Sigma}\).

Support: \(\mathbf{x} \in \mathbb{R}^k\)

Mean: \(\boldsymbol{\mu}\)

Variance-covariance matrix: \(\boldsymbol{\Sigma}\)

Probability density function (p.d.f):

$$ f(\mathbf{x}) = \frac{1}{(2\pi)^{k/2} |\boldsymbol{\Sigma}|^{1/2}} \exp\left(-\frac{1}{2}(\mathbf{x} - \boldsymbol{\mu})^T \boldsymbol{\Sigma}^{-1}(\mathbf{x} - \boldsymbol{\mu})\right) $$

where \(|\boldsymbol{\Sigma}|\) is the determinant of \(\boldsymbol{\Sigma}\).

Cumulative distribution function (c.d.f):

$$ P(\mathbf{X} \le \mathbf{q}) = P(X_1 \le q_1, \ldots, X_k \le q_k) $$

The c.d.f. does not have a closed-form expression and is computed numerically.

Moment generating function (m.g.f):

$$ M(\mathbf{t}) = E(e^{\mathbf{t}^T \mathbf{X}}) = \exp\left(\mathbf{t}^T \boldsymbol{\mu} + \frac{1}{2}\mathbf{t}^T \boldsymbol{\Sigma} \mathbf{t}\right) $$

Examples

dist <- dist_multivariate_normal(mu = list(c(1,2)), sigma = list(matrix(c(4,2,2,3), ncol=2)))
dimnames(dist) <- c("x", "y")
dist
#> <distribution[1]>
#> [1] MVN[2]

mean(dist)
#>      x y
#> [1,] 1 2
variance(dist)
#>      x y
#> [1,] 4 3
support(dist)
#> <support_region[1]>
#> [1] R^2
generate(dist, 10)
#> [[1]]
#>                x          y
#>  [1,]  2.1274372  4.5484506
#>  [2,]  1.3709813  2.7054163
#>  [3,]  1.7008159  3.3783472
#>  [4,]  2.0927497  3.3748075
#>  [5,]  0.8216972  0.8778973
#>  [6,]  0.1403092  0.9021328
#>  [7,]  1.3033104  0.2652230
#>  [8,]  0.4606416  4.1785664
#>  [9,] -0.5336266 -0.6788724
#> [10,]  4.3835697  4.2351775
#> 

density(dist, cbind(2, 1))
#> [1] 0.02829422
density(dist, cbind(2, 1), log = TRUE)
#> [1] -3.565098

cdf(dist, 4)
#> [1] 0.8412602

quantile(dist, 0.7, kind = "equicoordinate")
#>             x        y
#> [1,] 3.188512 3.188512
quantile(dist, 0.7, kind = "marginal")
#>             x        y
#> [1,] 2.048801 2.908288