pbetaDiff: Differentiate Regularized Incomplete Beta Function.

View source: R/RcppExports.R

pbetaDiffR Documentation

Differentiate Regularized Incomplete Beta Function.

Description

Calculate derivatives of the regularized incomplete beta function that is a cumulative distribution function of the beta distribution.

Usage

pbetaDiff(x, p = 10, q = 0.5, n = 10L, is_validation = TRUE, control = NULL)

Arguments

x

numeric vector of values between 0 and 1. It is similar to q argument of pbeta function.

p

similar to shape1 argument of pbeta function.

q

similar to shape2 argument of pbeta function.

n

positive integer representing the number of iterations used to calculate the derivatives. Greater values provide higher accuracy by the cost of more computational resources.

is_validation

logical; if TRUE then input arguments are validated. Set to FALSE to slightly increase the performance of the function.

control

list of control parameters. Currently not intended for the users.

Details

The function implements differentiation algorithm of R. Boik and J. Robinson-Cox (1998). Currently only first-order derivatives are considered.

Value

The function returns a list which has the following elements:

  • dx - numeric vector of derivatives respect to each element of x.

  • dp - numeric vector of derivatives respect to p for each element of x.

  • dq - numeric vector of derivatives respect to q for each element of x.

References

Boik, R. J. and Robinson-Cox, J. F. (1998). Derivatives of the Incomplete Beta Function. Journal of Statistical Software, 3 (1), pages 1-20.

Examples

# Some values from Table 1 of R. Boik and J. Robinson-Cox (1998)
pbetaDiff(x = 0.001,  p = 1.5, q = 11)
pbetaDiff(x = 0.5,  p = 1.5, q = 11)

# Compare analytical and numeric derivatives
delta <- 1e-6
x <- c(0.01, 0.25, 0.5, 0.75, 0.99)
p <- 5
q <- 10
out <- pbetaDiff(x = x, p = p, q = q)
p0 <- pbeta(q = x, shape1 = p, shape2 = q)

# Derivatives respect to x
p1 <- pbeta(q = x + delta, shape1 = p, shape2 = q)
data.frame(numeric = (p1 - p0) / delta, analytical = out$dx)
  
# Derivatives respect to p
p1 <- pbeta(q = x, shape1 = p + delta, shape2 = q)
data.frame(numeric = (p1 - p0) / delta, analytical = out$dp)

# Derivatives respect to q
p1 <- pbeta(q = x, shape1 = p, shape2 = q + delta)
data.frame(numeric = (p1 - p0) / delta, analytical = out$dq)


mnorm documentation built on May 29, 2024, 2:05 a.m.

Related to pbetaDiff in mnorm...