Learn R Programming

distr6 (version 1.1.0)

MultivariateNormal: Multivariate Normal Distribution Class

Description

Mathematical and statistical functions for the Multivariate Normal distribution, which is commonly used to generalise the Normal distribution to higher dimensions, and is commonly associated with Gaussian Processes.

Value

Returns an R6 object inheriting from class SDistribution.

Constructor

MultivariateNormal$new(mean = rep(0,2), cov = c(1,0,0,1), prec = NULL, decorators = NULL, verbose = FALSE)

Constructor Arguments

Argument Type Details
mean numeric vector of means.
cov numeric vector or matrix. See details.
prec numeric vector or matrix. See details.

decorators Decorator decorators to add functionality. See details.

Constructor Details

The Multivariate Normal distribution is parameterised with mean as a vector of numerics and either cov or prec as positive semi-definite matrices. These are related via, $$prec = cov^{-1}$$ If prec is given then cov is ignored. The covariance matrix can either be supplied as a matrix or as a vector that can be coerced via matrix(cov, nrow = K, byrow = FALSE).

Public Variables

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

Accessor Methods Link
decorators() decorators
traits() traits
valueSupport() valueSupport
variateForm() variateForm
type() type
properties() properties
support() support
symmetry() symmetry
sup() sup
inf() inf
dmax() dmax
dmin() dmin
skewnessType() skewnessType
kurtosisType() kurtosisType

Statistical Methods

Link
pdf(x1, ..., log = FALSE, simplify = TRUE) pdf
cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) cdf
quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) quantile.Distribution
rand(n, simplify = TRUE) rand
mean() mean.Distribution
variance() variance
stdev() stdev
prec() prec
cor() cor
skewness() skewness
kurtosis(excess = TRUE) kurtosis
entropy(base = 2) entropy
mgf(t) mgf
cf(t) cf
pgf(z) pgf
median() median.Distribution
iqr() iqr

Parameter Methods

Link
parameters(id) parameters
getParameterValue(id, error = "warn") getParameterValue
setParameterValue(..., lst = NULL, error = "warn") setParameterValue

Validation Methods

Link
liesInSupport(x, all = TRUE, bound = FALSE) liesInSupport
liesInType(x, all = TRUE, bound = FALSE) liesInType

Representation Methods

Link
strprint(n = 2) strprint
print(n = 2) print
summary(full = T) summary.Distribution
plot() Coming Soon.
qqplot() Coming Soon.

Details

The Multivariate Normal distribution parameterised with mean, \(\mu\), and covariance matrix, \(\Sigma\), is defined by the pdf, $$f(x_1,...,x_k) = (2 * \pi)^{-k/2}det(\Sigma)^{-1/2}exp(-1/2(x-\mu)^T\Sigma^{-1}(x-\mu))$$ for \(\mu \epsilon R^{k}\) and \(\Sigma \epsilon R^{k x k}\).

The distribution is supported on the Reals and only when the covariance matrix is positive-definite.

skewness and kurtosis are omitted as no closed form analytic expression could be found, decorate with CoreStatistics for numerical results. cdf and quantile are omitted as no closed form analytic expression could be found, decorate with FunctionImputation for a numerical imputation.

The parameter K is automatically updated by counting the length of the mean vector and once constructed this cannot be changed. If a mean vector of length greater than K is given then this is truncated to the correct length. If a mean vector of length less than K is given then this replicated and truncated to the correct length. Similarly cov and prec are internally coerced with matrix(cov, nrow = K, byrow = FALSE). Sampling is performed via the Cholesky decomposition using chol.

References

McLaughlin, M. P. (2001). A compendium of common probability distributions (pp. 2014-01). Michael P. McLaughlin.

Gentle, J.E. (2009). Computational Statistics. Statistics and Computing. New York: Springer. pp. 315<U+2013>316. doi:10.1007/978-0-387-98144-4. ISBN 978-0-387-98143-7.

See Also

listDistributions for all available distributions. chol for the implementation of the Cholesky decomposition. Normal for a special case of the Multivariate Normal distribution. CoreStatistics for numerical results. FunctionImputation to numerically impute d/p/q/r.

Examples

Run this code
# NOT RUN {
# Different parameterisations
MultivariateNormal$new(mean = c(0,0,0), cov = matrix(c(3,-1,-1,-1,1,0,-1,0,1), byrow=TRUE,nrow=3))
MultivariateNormal$new(mean = c(0,0,0), cov = c(3,-1,-1,-1,1,0,-1,0,1)) # Equivalently
MultivariateNormal$new(mean = c(0,0,0), prec = c(3,-1,-1,-1,1,0,-1,0,1))

# Default is bivariate standard normal
x <- MultivariateNormal$new()

# Update parameters
x$setParameterValue(mean = c(1, 2))
# When any parameter is updated, all others are too!
x$setParameterValue(prec = c(1,0,0,1))
x$parameters()

# d/p/q/r
# Note the difference from R stats
x$pdf(1, 2)
# This allows vectorisation:
x$pdf(1:3, 2:4)
x$rand(4)

# Statistics
x$mean()
x$variance()

summary(x)

# }

Run the code above in your browser using DataLab