dMVNcov: Density for the multivariate Normal distribution

dmultinormR Documentation

Density for the multivariate Normal distribution

Description

Density for the multivariate Normal distribution

Usage

      dmultinorm(vec.x, vec.mean = c(0, 0),
                 mat.cov = c(1, 1, 0),
                 log = FALSE)

Arguments

vec.x

For the R–multivariate Normal, an R–vector of quantiles.

vec.mean

The vector of means.

mat.cov

The vector of variances and covariances, arranged in that order. See below for further details.

log

Logical. If TRUE, the logged values are returned.

Details

This implementation of the multivariate (say R–dimensional) Normal density handles the variances and covariances, instead of correlation parameters.

For more than one observation, arrange all entries in matrices accordingly.

For each observation, mat.cov is a vector of length R \times (R + 1) / 2, where the first R entries are the variances \sigma^2{i}, i = 1, \ldots, R, and then the covariances arranged as per rows, that is, cov_{ij} i = 1, \ldots, R, j = i + 1, \ldots, R.

By default, it returns the density of two independent standard Normal distributions.

Value

The density of the multivariate Normal distribution.

Warning

For observations whose covariance matrix is not positive definite, NaN will be returned.

Author(s)

Victor Miranda

See Also

binormal.

Examples

###
### Two - dimensional Normal density.
###
set.seed(180228)
nn  <- 25
mean1 <- 1; mean2 <- 1.5; mean3 = 2
var1 <- exp(1.5); var2 <- exp(-1.5); var3 <- exp(1); cov12 = 0.75
dmvndata <- rbinorm(nn, mean1 = 1, mean2 = 1.5, var1 = var1, var2 = var2,
                    cov12 = cov12)

## Using dbinorm() from VGAM.
d2norm.data <- dbinorm(x1 = dmvndata[, 1], x2 = dmvndata[, 2],
                        mean1 = mean1, mean2 = mean2, var1 = var1, var2 = var2,
                        cov12 = cov12)
## Using dmultinorm().
d2norm.data2 <- dmultinorm(vec.x = dmvndata, vec.mean = c(mean1, mean2),
                        mat.cov = c(var1, var2, cov12))
summary(d2norm.data)
summary(d2norm.data2)
##
## 3--dimensional Normal.
##
dmvndata <- cbind(dmvndata, rnorm(nn, mean3, sqrt(var3)))

d2norm.data3 <- dmultinorm(dmvndata, vec.mean = c(mean1, mean2, mean3),
                       mat.cov = c(var1, var2, var3, cov12, 0, 0))

hist(d2norm.data3)
summary(d2norm.data3)


VGAMextra documentation built on Nov. 2, 2023, 5:59 p.m.