Package 'sinib'

Title: Sum of Independent Non-Identical Binomial Random Variables
Description: Density function, distribution function, quantile function and random number generation for the sum of independent non-identical binomial distribution with parameters size and prob. For more see: Boxiang Liu and Thomas Quertermous (2018) The R Journal <https://journal.r-project.org/archive/2018/RJ-2018-011/index.html>.
Authors: Boxiang Liu
Maintainer: Boxiang Liu <[email protected]>
License: GPL-3
Version: 1.0.1
Built: 2024-10-27 05:50:16 UTC
Source: https://github.com/boxiangliu/sinib

Help Index


Sum of Independent Non-Identical Binomial Random Variables

Description

Density function, distribution function, quantile function and random number generation for the sum of independent non-identical binomial distribution with parameters size and prob. For more see: Boxiang Liu and Thomas Quertermous (2018) The R Journal <https://journal.r-project.org/archive/2018/RJ-2018-011/index.html>.

Author(s)

Boxiang Liu

Maintainer: Boxiang Liu <[email protected]>


Distribution of Sum of Independent Non-Identical Binomial Random Variables

Description

Density function, distribution function, quantile function, and random number generation for the sum of independent non-identical binomial random variables

Usage

psinib(q, size, prob, lower.tail = TRUE, log.p = FALSE)

dsinib(x, size, prob, log = FALSE)

rsinib(n, size, prob)

qsinib(p, size, prob)

Arguments

size

integer vector of number of trials (see detail).

prob

numeric vector of success probabilities (see detail).

lower.tail

logical; if TRUE, probabilities are P[S<=s]P[S<=s], otherwise, P[S>s]P[S>s].

x, q

integer vector of quantiles.

log, log.p

logical; if TRUE, probabilities p are given as log(p).

n

numeric scalar to indicate number of observations.

p

numeric vector of probabilities.

Details

Suppose S is a random variable formed by summing R independent non-identical random variables XrX_r, r=1,...,Rr = 1,...,R.

S=r=1RXrS = \sum_{r=1}^R X_r

size and prob should both be vectors of length R. The first elements of size and prob specifies X1X_1, the second elements specifies X2X_2, so on and so forth. The probability F(S)F(S) is calculated using Daniels' second-order continuity-corrected saddlepoint approximation. The density p(S)p(S) is calculated using second-order saddlepoint mass approximation with Butler's normalization.

Value

qsinib gives the cumulative distribution of sum of independent non-identical random variables.

Source

See Eisinga et al (2012) Saddlepoint approximations for the sum of independent non-identically distributed binomial random variables. Available from http://onlinelibrary.wiley.com/doi/10.1111/stan.12002/full

Examples

# Calculating the density and probability:
size <- c(12, 14, 4, 2, 20, 17, 11, 1, 8, 11)
prob <- c(0.074, 0.039, 0.095, 0.039, 0.053, 0.043, 0.067, 0.018, 0.099, 0.045)
q <- x <- seq(1, 19, 2)
dsinib(x, size, prob)
psinib(q, size, prob)

# Generating random samples:
rsinib(100, size, prob)

# Calculating quantiles:
p <- psinib(q, size, prob) 
qsinib(p, size, prob)