Package 'dng'

Title: Distributions and Gradients
Description: Provides density, distribution function, quantile function and random generation for the split normal and split-t distributions, and computes their mean, variance, skewness and kurtosis for the two distributions (Li, F, Villani, M. and Kohn, R. (2010) <doi:10.1016/j.jspi.2010.04.031>).
Authors: Feng Li [aut, cre] (ORCID: <https://orcid.org/0000-0002-4248-9778>), Jiayue Zeng [aut]
Maintainer: Feng Li <[email protected]>
License: GPL (>= 2)
Version: 1.1
Built: 2026-10-16 01:39:31 UTC
Source: https://github.com/feng-li/dng

Help Index


Generalized hypergeometric function

Description

Evaluate generalized hypergeometric functions by their defining series.

Usage

ghypergeo(a, b, z, k)

Arguments

a

matrix of upper hypergeometric parameters.

b

matrix of lower hypergeometric parameters.

z

vector of hypergeometric function arguments.

k

maximum number of hypergeometric series terms. Non-positive values use 100000 terms.

Details

Only the convergent defining series and terminating polynomials are supported; analytic continuation outside the series domain is not performed. Invalid parameters, failure to converge within k terms, and severe cancellation return NaN, with a warning. The split-t gradients do not depend on this routine.

Value

A one-column numeric matrix of generalized hypergeometric function values. Rows of a, rows of b, and values of z are recycled to the longest input length. Empty input rows or an empty z return a matrix with zero rows. Missing values propagate.

See Also

gsplitt()


Split-normal distribution

Description

Density, distribution, quantile, random generation, and parameter gradients for the split-normal distribution.

Usage

dsplitn(x, mu, sigma, lmd, log = FALSE, logarithm = NULL)

gsplitn(y, par, parCaller, denscaller)

psplitn(q, mu, sigma, lmd)

qsplitn(p, mu, sigma, lmd)

rsplitn(n, mu, sigma, lmd)

Arguments

x

vector of quantiles.

mu

vector of finite location parameters (the modes of the densities).

sigma

vector of finite positive left-side scale parameters.

lmd

vector of finite positive skewness parameters. If 1, reduced to symmetric normal distribution.

log

logical scalar; if TRUE, return log-densities. Defaults to FALSE.

logarithm

optional logical scalar retained for backward compatibility. When non-NULL, overrides log.

y

vector of quantiles for gradient evaluation.

par

list with mu, sigma, and lmd parameter vectors.

parCaller

character scalar naming the parameter to differentiate: "mu", "sigma", or "lmd".

denscaller

character vector selecting gradients to compute. Use "u" for the CDF gradient and "d" for the log-density gradient.

q

vector of quantiles.

p

vector of probability.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

Details

The density is

f(y)=2(1+λ)σφ(z),f(y) = \frac{2}{(1+\lambda)\sigma}\varphi(z),

where φ\varphi is the standard normal density, z=(y−μ)/σz=(y-\mu)/\sigma for y≤μy\leq\mu, and z=(y−μ)/(σλ)z=(y-\mu)/(\sigma\lambda) otherwise. The scale σ\sigma describes the left side; it is the overall standard deviation only when λ=1\lambda=1. Random values are sampled from a mixture of negative and positive half-normal distributions, with left-side probability 1/(1+λ)1/(1+\lambda).

Value

dsplitn gives the density; psplitn gives the percentile; qsplitn gives the quantile; and rsplitn gives the random variables. gsplitn returns a list with elements u and d containing gradients of the CDF and log-density. Unrequested gradient components are NaN; an empty denscaller selects both. Missing inputs propagate. Invalid parameters or probabilities return NaN, with a warning.

Numerical arguments are recycled to their longest length, or the length specified by n for random generation. An empty numerical input gives an empty result, except random generation returns n NaNs with a warning for an empty parameter vector. log and logarithm must be logical scalars.

Functions

  • gsplitn(): Gradients for the split-normal CDF and log-density.

  • psplitn(): Percentile for the split-normal distribution.

  • qsplitn(): Quantile for the split-normal distribution.

  • rsplitn(): Random variables from the split-normal distribution.

Author(s)

Feng Li, Jiayue Zeng

References

Villani, M., & Larsson, R. (2006) The Multivariate Split Normal Distribution and Asymmetric Principal Components Analysis. Sveriges Riksbank Working Paper Series, No. 175.

See Also

splitn_mean(), splitn_var(),splitn_skewness() and splitn_kurtosis() for numerical characteristics of the split-normal distribution.

Examples

n <- 3
mu <- c(0,1,2)
sigma <- c(1,2,3)
lmd <- c(1,2,3)

q0 <- rsplitn(n, mu, sigma, lmd)
d0 <- dsplitn(q0, mu, sigma, lmd, log = FALSE)
p0 <- psplitn(q0, mu, sigma, lmd)
q1 <- qsplitn(p0,mu, sigma, lmd)
all.equal(q0, q1)

Moments of the split normal distribution

Description

Computing the mean, variance, skewness and kurtosis for the split-normal distribution.

Usage

splitn_kurtosis(lmd)

splitn_mean(mu, sigma, lmd)

splitn_skewness(sigma, lmd)

splitn_var(sigma, lmd)

Arguments

lmd

vector of finite positive skewness parameters. If 1, reduce to normal distribution.

mu

vector of finite location parameters (the modes of the densities).

sigma

vector of finite positive left-side scale parameters.

Value

splitn_mean gives the mean. splitn_var gives the variance. splitn_skewness gives the skewness. splitn_kurtosis gives excess kurtosis (zero for the normal distribution). All results are vectors, recycled to the longest numerical input. Empty inputs return an empty vector; missing values propagate. Invalid parameters return NaN, with a warning. Skewness and excess kurtosis do not depend on the positive scale.

Functions

  • splitn_kurtosis(): Kurtosis for the split-normal distribution.

  • splitn_skewness(): Skewness for the split-normal distribution.

  • splitn_var(): Variance for the split-normal distribution.

Author(s)

Feng Li, Jiayue Zeng

References

Villani, M., & Larsson, R. (2006) The Multivariate Split Normal Distribution and Asymmetric Principal Components Analysis. Sveriges Riksbank Working Paper Series, No. 175.

See Also

psplitn() dsplitn() qsplitn() and rsplitn() for the split-normal distribution.

Examples

mu <- c(0,1,2)
sigma <- c(0.5,1,2)
lmd <- c(1,2,3)

mean0 <- splitn_mean(mu, sigma, lmd)
var0 <- splitn_var(sigma, lmd)
skewness0 <- splitn_skewness(sigma, lmd)
kurtosis0 <- splitn_kurtosis(lmd)

Split-t distribution

Description

Density, distribution, quantile, random generation, and parameter gradients for the split Student-t distribution.

Usage

dsplitt(x, mu, df, phi, lmd, log = FALSE, logarithm = NULL)

gsplitt(y, par, parCaller, denscaller)

psplitt(q, mu, df, phi, lmd)

qsplitt(p, mu, df, phi, lmd)

rsplitt(n, mu, df, phi, lmd)

Arguments

x

vector of quantiles.

mu

vector of finite location parameters (the modes of the densities).

df

degrees of freedom (> 0, can be non-integer). df = Inf is also allowed.

phi

vector of finite positive left-side scale parameters.

lmd

vector of finite positive skewness parameters. If 1, reduced to the symmetric student t distribution.

log

logical scalar; if TRUE, return log-densities. Defaults to FALSE.

logarithm

optional logical scalar retained for backward compatibility. When non-NULL, overrides log.

y

vector of quantiles for gradient evaluation.

par

list with mu, df, phi, and lmd parameter vectors.

parCaller

character scalar naming the parameter to differentiate: "mu", "df", "phi", or "lmd".

denscaller

character vector selecting gradients to compute. Use "u" for the CDF gradient and "d" for the log-density gradient.

q

vector of quantiles.

p

vector of probability.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

Details

The density is

f(y)=2(1+λ)ϕtν(z),f(y) = \frac{2}{(1+\lambda)\phi}t_\nu(z),

where tνt_\nu is the standard Student-t density, z=(y−μ)/ϕz=(y-\mu)/\phi for y≤μy\leq\mu, and z=(y−μ)/(ϕλ)z=(y-\mu)/(\phi\lambda) otherwise. With df = Inf the distribution is split-normal with sigma = phi. Random values are sampled from negative and positive half-t distributions, with left-side probability 1/(1+λ)1/(1+\lambda).

The CDF derivative with respect to df is evaluated by integrating the analytic density score using R's QUADPACK routines. Failure to converge returns NaN, with a warning. At df = Inf, the derivatives with respect to df are zero.

Value

dsplitt gives the density; psplitt gives the percentile; qsplitt gives the quantile; and rsplitt gives the random variables. gsplitt returns a list with elements u and d containing gradients of the CDF and log-density. Unrequested gradient components are NaN; an empty denscaller selects both. Missing inputs propagate. Invalid parameters or probabilities return NaN, with a warning.

Numerical arguments are recycled to their longest length, or the length specified by n for random generation. An empty numerical input gives an empty result, except random generation returns n NaNs with a warning for an empty parameter vector. log and logarithm must be logical scalars.

Functions

  • gsplitt(): Gradients for the split-t CDF and log-density.

  • psplitt(): Percentile for the split-t distribution.

  • qsplitt(): Quantile for the split-t distribution.

  • rsplitt(): Random variables from the split-t distribution.

Author(s)

Feng Li, Jiayue Zeng

References

Li, F., Villani, M., & Kohn, R. (2010). Flexible modeling of conditional distributions using smooth mixtures of asymmetric student t densities. Journal of Statistical Planning & Inference, 140(12), 3638-3654.

See Also

splitt_mean(), splitt_var(),splitt_skewness() and splitt_kurtosis() for numerical characteristics of the Split-t distribution.

Examples

n <- 3
mu <- c(0,1,2)
df <- rep(10,3)
phi <- c(0.5,1,2)
lmd <- c(1,2,3)

q0 <- rsplitt(n, mu, df, phi, lmd)
d0 <- dsplitt(q0, mu, df, phi, lmd, log = FALSE)
p0 <- psplitt(q0, mu, df, phi, lmd)
q1 <- qsplitt(p0,mu, df, phi, lmd)
all.equal(q0, q1)

Moments of the split-t distribution

Description

Computing the mean, variance, skewness and kurtosis for the split student-t distribution.

Usage

splitt_kurtosis(df, phi, lmd)

splitt_mean(mu, df, phi, lmd)

splitt_skewness(df, phi, lmd)

splitt_var(df, phi, lmd)

Arguments

df

degrees of freedom (> 0, can be non-integer). df = Inf is allowed.

phi

vector of finite positive left-side scale parameters.

lmd

vector of finite positive skewness parameters. If 1, reduced to symmetric student t distribution.

mu

vector of finite location parameters (the modes of the densities).

Value

splitt_mean gives the mean. splitt_var gives the variance. splitt_skewness gives the skewness. splitt_kurtosis gives excess kurtosis. All results are vectors, recycled to the longest numerical input. Empty inputs return an empty vector; missing values propagate. With df = Inf, results equal the split-normal moments.

The mean requires df > 1. Variance is NaN for df <= 1 and Inf for 1 < df <= 2. Skewness and excess kurtosis require df > 3 and df > 4, respectively. Undefined moments and invalid parameters return NaN, with a warning.

Functions

  • splitt_kurtosis(): Kurtosis for the split-t distribution.

  • splitt_skewness(): Skewness for the split-t distribution.

  • splitt_var(): Variance for the split-t distribution.

Author(s)

Feng Li, Jiayue Zeng

References

Li, F., Villani, M., & Kohn, R. (2010). Flexible modeling of conditional distributions using smooth mixtures of asymmetric student t densities. Journal of Statistical Planning & Inference, 140(12), 3638-3654.

See Also

dsplitt(), psplitt(), qsplitt() and rsplitt() for the split-t distribution.

Examples

mu <- c(0,1,2)
df <- rep(10,3)
phi <- c(0.5,1,2)
lmd <- c(1,2,3)

mean0 <- splitt_mean(mu, df, phi, lmd)
var0 <- splitt_var(df, phi, lmd)
skewness0 <- splitt_skewness(df, phi, lmd)
kurtosis0 <- splitt_kurtosis(df, phi, lmd)