Learn R Programming

distributions3 (version 0.3.0)

random.SinhArcsinh: Draw a random sample from a Sinh-Arcsinh distribution

Description

Please see the documentation of SinhArcsinh() for some properties of the Sinh-Arcsinh distribution, as well as extensive examples showing to how calculate p-values and confidence intervals.

Usage

# S3 method for SinhArcsinh
random(x, n = 1L, drop = TRUE, cores = NULL, ...)

Value

In case of a single distribution object or n = 1, either a numeric vector of length n (if drop = TRUE, default) or a matrix with n columns (if drop = FALSE).

Arguments

x

A SinhArcsinh object created by a call to SinhArcsinh().

n

The number of samples to draw. Defaults to 1L.

drop

logical. Should the result be simplified to a vector if possible?

cores

NULL or positive integer. TODO(R): Just a development option. If not NULL we use the C code with cores threads.

...

Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors.

Examples

Run this code

## SinhArcsinh() by default uses nu = 1, tau = 1 which
## results in the standard normal distribution
set.seed(6020)
X <- SinhArcsinh() # Uses mu = 1, sigma = 0, nu = 1, tau = 1)
x <- random(X, 300)
qqnorm(x); qqline(x, col = 2, lwd = 2)
curve(pdf(X, x), xlim = c(-5, 5), main = paste(X, "density"))

## Calculation of central moments is based on numeric integration,
## thus not being identical to the standard normal distribution
c(mean = mean(x), sd = sd(x))

## Skewed Sinh-Arcsinh distribution
X <- SinhArcsinh(mu = 7, sigma = 2, nu = c(0.7, 1, 0.7), tau = c(1, 0.7, 0.7))
as.matrix(X)

## Visualization of density functions using different parameters for nu/tau
curve(pdf(X[1], x), xlim = c(0, 20), ylim = c(0, 0.2), main = "Density function")
curve(pdf(X[2], x), xlim = c(0, 20), col = 2, add = TRUE)
curve(pdf(X[3], x), xlim = c(0, 20), col = 4, add = TRUE)

## Visualization of distribution function using different parameters for nu/tau
curve(cdf(X[1], x), xlim = c(0, 20), ylim = 0:1, main = "Distribution function")
curve(cdf(X[2], x), xlim = c(0, 20), col = 2, add = TRUE)
curve(cdf(X[3], x), xlim = c(0, 20), col = 4, add = TRUE)

## Central moments
mean(X)
variance(X)
skewness(X)
kurtosis(X)

## Drawing random values
random(X, 10)

pdf(X, 2)
log_pdf(X, 2)

cdf(X, 4)
quantile(X, 0.7)

# note that the cdf() and quantile() functions are inverses
X <- SinhArcsinh(mu = 3, sigma = 2, nu = 0.9, tau = 1.2)
cdf(X, quantile(X, 0.7))
quantile(X, cdf(X, 7))

Run the code above in your browser using DataLab