[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,]  1.72340813 0.1571887
#>  [2,]  1.69471640 4.6441797
#>  [3,]  0.27844771 2.8569465
#>  [4,] -0.07639097 4.1211581
#>  [5,] -1.39452068 0.5380995
#>  [6,]  0.84342061 2.8863907
#>  [7,]  0.44545093 1.2595624
#>  [8,]  0.50802622 2.2513664
#>  [9,]  2.39871326 3.4221763
#> [10,]  2.85401629 3.2158769
#> 

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

cdf(dist, 4)
#> Warning: Using a vector for the `q` argument of a multivariate distribution was
#> deprecated in distributional 0.9.0.
#>  Please use a matrix with one column for each of the 2 variates (such as `q =
#>   cbind(...)`) instead.
#> [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