dmnorm: Probability density prediction

View source: R/dmnorm.R

dmnormR Documentation

Probability density prediction

Description

Prediction of the probability density of multivariate observations. Function dmnorm assumes a multivariate gaussian distribution for the reference (= training) observations. Function dkerngauss returns a non parametric estimate using a (multiplicative) multivariate gaussian kernel estimator.

Usage


dmnorm(Xr = NULL, Xu, mu = NULL, sigma = NULL, diag = FALSE)

dkerngauss(Xr, Xu, H = NULL, hs = NULL, a = .5)

Arguments

Xr

A n x p matrix or data frame of reference (= training) observations. For dmnorm, Xr is not used if arguments mu and sigma are not NULL.

Xu

A m x p matrix or data frame of new (= test) observations for which the probability density has to be predicted.

Specific arguments for dmnorm:

mu

A p vector representing the mean of the gaussian distribution. If NULL (default), this is colMeans(Xr).

sigma

The p x p covariance matrix of the gaussian distribution. If NULL (default), this is cov(Xr).

diag

Logical indicating if the estimated covariance matrix is forced to be diagonal (default to FALSE). Ignored if sigma is not NULL.

Specific arguments for dkerngauss:

H

The p x p bandwidth matrix for the kernel estimator. If NULL (default): if hs is NULL, see the code.

hs

A scalar representing a same bandwidth for all the p dimensions (matrix H is made diagonal with the value hs). Ignored if H is not NULL.

a

A scaling scalar used if H and hs are NULL. See the code.

Value

A data.frame, see the examples.

Examples


data(iris)

Xr <- iris[, 1:4]
yr <- iris[, 5]

fm <- fda(Xr, yr)
Tr <- fm$Tr

m <- 50
x1 <- seq(min(Tr[, 1]), max(Tr[, 1]), length.out = m)
x2 <- seq(min(Tr[, 2]), max(Tr[, 2]), length.out = m)
Tu <- expand.grid(x1, x2)
headm(Tu)

## Parametric

z <- dmnorm(Tr[yr == "setosa", ], Tu)$fit$fit
mfit1 <- matrix(z, nrow = m)
z <- dmnorm(Tr[yr == "versicolor", ], Tu)$fit$fit
mfit2 <- matrix(z, nrow = m)
z <- dmnorm(Tr[yr == "virginica", ], Tu)$fit$fit
mfit3 <- matrix(z, nrow = m)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(2, 2))
contour(x1, x2, mfit1)
abline(h = 0, v = 0, lty = 2)
contour(x1, x2, mfit2)
abline(h = 0, v = 0, lty = 2)
contour(x1, x2, mfit3)
abline(h = 0, v = 0, lty = 2)
par(oldpar)

## Non-parametric

hs <- .5
z <- dkerngauss(Tr[yr == "setosa", ], Tu, hs = hs)$fit$fit
mfit1 <- matrix(z, nrow = m)
z <- dkerngauss(Tr[yr == "versicolor", ], Tu, hs = hs)$fit$fit
mfit2 <- matrix(z, nrow = m)
z <- dkerngauss(Tr[yr == "virginica", ], Tu, hs = hs)$fit$fit
mfit3 <- matrix(z, nrow = m)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(2, 2))
contour(x1, x2, mfit1)
abline(h = 0, v = 0, lty = 2)
contour(x1, x2, mfit2)
abline(h = 0, v = 0, lty = 2)
contour(x1, x2, mfit3)
abline(h = 0, v = 0, lty = 2)
par(oldpar)


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.