dmvnorm: Density of multivariate Gaussian distribution

Description Usage Arguments Value See Also Examples

View source: R/util.R

Description

Efficiently computes the densities of observations for a generic multivariate Gaussian distribution

Usage

1

Arguments

data

A numeric vector, matrix, or data frame of observations. Categorical variables are not allowed. If a matrix or data frame, rows correspond to observations and columns correspond to variables.

mean

A vector of means for each variable.

sigma

A positive definite covariance matrix.

log

A logical value indicating whether or not the logarithm of the densities should be returned.

Value

A numeric vector whose ith component is the density of the ith observation in data in the MVN mixture specified by parameters.

See Also

dnorm, dens

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# univariate
ngrid <- 101
x <- seq(-5, 5, length = ngrid)
dens <- dmvnorm(x, mean = 1, sigma = 5)
plot(x, dens, type = "l")

# bivariate
ngrid <- 101
x1 <- x2 <- seq(-5, 5, length = ngrid)
mu <- c(1,0)
sigma <- matrix(c(1,0.5,0.5,2), 2, 2)
dens <- dmvnorm(as.matrix(expand.grid(x1, x2)), mu, sigma)
dens <- matrix(dens, ngrid, ngrid)
image(x1, x2, dens)
contour(x1, x2, dens, add = TRUE)

Japrin/mclust documentation built on Nov. 18, 2019, 5:21 a.m.