Learn R Programming

ExtremalDep (version 1.0.0)

ellipse: Level sets for bivariate normal, student-t and skew-normal distributions probability densities.

Description

Level sets of the bivariate normal, student-t and skew-normal distributions probability densities for a given probability.

Usage

ellipse(
  center = c(0, 0),
  alpha = c(0, 0),
  sigma = diag(2),
  df = 1,
  prob = 0.01,
  npoints = 250,
  pos = FALSE
)

Value

Returns a bivariate vector of \(250\) rows if pos = FALSE, and half otherwise.

Arguments

center

A vector of length 2 corresponding to the location of the distribution.

alpha

A vector of length 2 corresponding to the skewness of the skew-normal distribution.

sigma

A 2 by 2 variance-covariance matrix.

df

An integer corresponding to the degree of freedom of the student-t distribution.

prob

The probability level. See details.

npoints

The maximum number of points at which it is evaluated.

pos

If pos = TRUE only the region on the positive quadrant is kept.

Details

The level sets are defined as

\(R(f_\alpha) = \{ x: f(x) \geq f_\alpha \}\)

where \(f_\alpha\) is the largest constant such that

\(P(X \in R(f_\alpha)) \geq 1 - \alpha\).

Here we consider \(f(x)\) to be the bivariate normal, student-t or skew-normal density.

Examples

Run this code
library(mvtnorm)

# Data simulation (Bivariate-t on positive quadrant)
rho <- 0.5
sigma <- matrix(c(1, rho, rho, 1), ncol = 2)
df <- 2

set.seed(101)
n <- 1500
data <- rmvt(5 * n, sigma = sigma, df = df)
data <- data[data[, 1] > 0 & data[, 2] > 0, ]
data <- data[1:n, ]

P <- c(1 / 750, 1 / 1500, 1 / 3000)

ell1 <- ellipse(prob = 1 - P[1], sigma = sigma, df = df, pos = TRUE)
ell2 <- ellipse(prob = 1 - P[2], sigma = sigma, df = df, pos = TRUE)
ell3 <- ellipse(prob = 1 - P[3], sigma = sigma, df = df, pos = TRUE)

plot(
  data,
  xlim = c(0, max(data[, 1], ell1[, 1], ell2[, 1], ell3[, 1])),
  ylim = c(0, max(data[, 2], ell1[, 2], ell2[, 2], ell3[, 2])),
  pch = 19
)
points(ell1, type = "l", lwd = 2, lty = 1)
points(ell2, type = "l", lwd = 2, lty = 1)
points(ell3, type = "l", lwd = 2, lty = 1)

Run the code above in your browser using DataLab