[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 = 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.5890439  3.5939243
#>  [2,]  2.4802413  2.2973921
#>  [3,] -0.6194837  1.9712223
#>  [4,]  4.5637796  4.3904932
#>  [5,] -0.7759594 -0.7793593
#>  [6,] -2.2377047  1.3302668
#>  [7,]  3.2063897  2.3456605
#>  [8,] -1.7804529  1.7332559
#>  [9,]  1.3969992  0.8448695
#> [10,]  1.9580538  1.4063092
#> 

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