intDensTri: Integrate a Gaussian/Student Density over a Triangle

View source: R/IntDensTri.R

intDensTriR Documentation

Integrate a Gaussian/Student Density over a Triangle

Description

Consider a univariate random variable X, two multivariate random variables Y and Z, and t1 and t2 two real numbers. This function can compute either P[|X|>t1,|X]>|Y1|,...,|X]>|Yp|] if zmin is not specified, P[|Z1|<t2,...,|Zq|<t2,|X|>t1,|X]>|Y1|,...,|X]>|Yp|] if zmin is specified.

Usage

intDensTri(
  mu,
  Sigma,
  df,
  n,
  x.min,
  z.max = NULL,
  type = "double",
  proba.min = 1e-06,
  prune = NULL,
  distribution = "pmvnorm"
)

Arguments

mu

[numeric vector] the expectation of the joint distribution.

Sigma

[matrix] the variance-covariance of the joint distribution.

df

[integer > 0] the degree of freedom of the joint Student's t distribution. Only used when distribution="pvmt".

n

[integer > 0] number of points for the numerical integration.

x.min

[numeric] the minimum value along the x axis.

z.max

[numeric vector, optional] the maximum value along the z axis. Define the dimension of Z.

type

[character] the type of mesh to be used. Can be \"raw\", \"double\", or \"fine\".

proba.min

[numeric 0-1] the probability used to find the maximum value along the x axis. Only used if prune is not specified.

prune

[integer >0] number of standard deviations after which the domain ends along the x axis.

distribution

[character] type of joint distribution. Can be "pmvnorm" (normal distribution) or "pvmt" (Student's t distribution)

Details

Argument type:

  • \"raw\": mesh with points inside the domain

  • \"double\": mesh with points outside the domain

  • \"fine\": mesh with points inside the domain plus additional rectangles trying to fill the missing domain.

Argument Sigma and mu: define the mean and variance-covariance of the random variables X, Y, Z (in this order). The length of the argument z.max is used to define the dimension of Z. The dimension of X is always 1.

Value

A numeric.

Examples

library(mvtnorm)

p <- 2
Sigma <- diag(p)
mu <- rep(0, p)

## bivariate normal distribution
z2 <- qmvt(0.975, mean = mu, sigma = Sigma, df = 1e3)$quantile

# compute integral
intDensTri(mu = mu, Sigma = Sigma, n=5, x.min=0, type = "fine")$value-1/2
intDensTri(mu = mu, Sigma = Sigma, n=30, x.min=0, type = "raw")$value-1/2
intDensTri(mu = mu, Sigma = Sigma, n=50, x.min=0, type = "raw")$value-1/2

intDensTri(mu = mu, Sigma = Sigma, df = 5, n=5, x.min=0, distribution = "pmvt")$value-1/2
res <- intDensTri(mu = mu, Sigma = Sigma, df = 5, n=10, x.min=0, distribution = "pmvt")
res$value-1/2
ggplot2::autoplot(res)

## trivariate normal distribution
## Not run: 
p <- 3
Sigma <- diag(p)
mu <- rep(0, p)

res2 <- intDensTri(mu = mu, Sigma = Sigma, n=5, x.min = 0, z.max = 10)
ggplot2::autoplot(res2)
ggplot2::autoplot(res2, coord.plot = c("x","z1"))
res2

## End(Not run)

#### when the distribution is far from 0
## Not run: 
eq1 <- intDensTri(mu = c(10,0), Sigma = diag(1,2), 
                  x.min = 2, n=10)
eq1$value-1
ggplot2::autoplot(eq1)

eq2 <- intDensTri(mu = c(10,0,0), Sigma = diag(1,3),
                  x.min=2, z.max = 10, type = "raw",
                  n=10)
ggplot2::autoplot(eq2, coord.plot = c("y1","z1"))
eq2$value-1

## more variables
p <- 5
Sigma <- diag(p)
mu <- rep(0, p)

res2 <- intDensTri(mu = mu, Sigma = Sigma, n=5, x.min = 1, z.max = c(2,2))
res2$grid

## End(Not run)


bozenne/lavaSearch2 documentation built on Feb. 13, 2024, 10:18 p.m.