Title: | Evaluate Arbitrary Negative Binomial Convolutions |
---|---|
Description: | Three distinct methods are implemented for evaluating the sums of arbitrary negative binomial distributions. These methods are: Furman's exact probability mass function (Furman (2007) <doi:10.1016/j.spl.2006.06.007>), saddlepoint approximation, and a method of moments approximation. Functions are provided to calculate the density function, the distribution function and the quantile function of the convolutions in question given said evaluation methods. Functions for generating random deviates from negative binomial convolutions and for directly calculating the mean, variance, skewness, and excess kurtosis of said convolutions are also provided. |
Authors: | Gregory Bedwell [aut, cre, cph] |
Maintainer: | Gregory Bedwell <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.1 |
Built: | 2024-11-16 16:15:23 UTC |
Source: | https://github.com/gbedwell/nbconv |
Calculates the probability mass function for the convolution of arbitrary negative binomial random variables.
dnbconv( counts, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
dnbconv( counts, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
counts |
Integer vector of counts over which the convolution is evaluated. |
mus |
Numeric vector of individual mean values |
ps |
Numeric vector of individual probabilities of success. |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
method |
The method by which to evaluate the PMF. One of "exact", "moments", or "saddlepoint". |
n.terms |
The number of terms to include in the series representation of the exact PMF. Defaults to 1000. |
n.cores |
The number of CPU cores to use in the evaluation. Allows parallelization. |
tolerance |
The acceptable difference between the sum of the K distribution and 1. Defaults to 1E-3. |
normalize |
Boolean. If TRUE, the PMF is normalized to sum to 1. |
A numeric vector of probability densities.
dnbconv(counts = 0:500, mus = c(100, 10), phis = c(5, 8), method = "exact")
dnbconv(counts = 0:500, mus = c(100, 10), phis = c(5, 8), method = "exact")
Implements Furman's exact PMF for the evaluation of the sum of arbitrary NB random variables. Called by other functions. Not intended to be run alone.
nb_sum_exact(phis, ps, n.terms = 1000, counts, n.cores = 1, tolerance = 0.001)
nb_sum_exact(phis, ps, n.terms = 1000, counts, n.cores = 1, tolerance = 0.001)
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
ps |
Numeric vector of individual probabilities of success. |
n.terms |
The number of terms to include in the series representation of the exact PMF. Defaults to 1000. |
counts |
Integer vector of counts over which the convolution is evaluated. |
n.cores |
The number of CPU cores to use in the evaluation. Allows parallelization. |
tolerance |
The acceptable difference between the sum of the K distribution and 1. Defaults to 1E-3. |
A numeric vector of probability densities.
nb_sum_exact(ps = c(0.05, 0.44), phis = c(5, 8), counts = 0:500)
nb_sum_exact(ps = c(0.05, 0.44), phis = c(5, 8), counts = 0:500)
Implements the method of moments approximation for the sum of arbitrary NB random variables. Called by other functions. Not intended to be run alone.
nb_sum_moments(mus, phis, counts)
nb_sum_moments(mus, phis, counts)
mus |
Numeric vector of individual mean values |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
counts |
Integer vector of counts over which the convolution is evaluated. |
A numeric vector of probability densities.
nb_sum_moments(mus = c(100, 10), phis = c(5, 8), counts = 0:500)
nb_sum_moments(mus = c(100, 10), phis = c(5, 8), counts = 0:500)
Implements the saddlepoint approximation for the sum of arbitrary NB random variables. Called by other functions. Not intended to be run alone.
nb_sum_saddlepoint(mus, phis, counts, normalize = TRUE, n.cores = 1)
nb_sum_saddlepoint(mus, phis, counts, normalize = TRUE, n.cores = 1)
mus |
Numeric vector of individual mean values |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
counts |
Integer vector of counts over which the convolution is evaluated. |
normalize |
Boolean. If TRUE, the PMF is normalized to sum to 1. |
n.cores |
The number of CPU cores to use in the evaluation. Allows parallelization. |
A numeric vector of probability densities.
nb_sum_saddlepoint(mus = c(100, 10), phis = c(5, 8), counts = 0:500)
nb_sum_saddlepoint(mus = c(100, 10), phis = c(5, 8), counts = 0:500)
Calculates distribution parameters for the convolution of arbitrary negative binomial random variables.
nbconv_params(mus, phis, ps)
nbconv_params(mus, phis, ps)
mus |
Numeric vector of individual mean values |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
ps |
Numeric vector of individual probabilities of success. |
A named numeric vector of distribution parameters.
nbconv_params(mus = c(100, 10), phis = c(5, 8))
nbconv_params(mus = c(100, 10), phis = c(5, 8))
Calculates the CDF for the convolution of arbitrary negative binomial random variables.
pnbconv( quants, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
pnbconv( quants, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
quants |
Integer vector of quantiles. |
mus |
Numeric vector of individual mean values |
ps |
Numeric vector of individual probabilities of success. |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
method |
The method by which to evaluate the PMF. One of "exact", "moments", or "saddlepoint". |
n.terms |
The number of terms to include in the series representation of the exact PMF. Defaults to 1000. |
n.cores |
The number of CPU cores to use in the evaluation. Allows parallelization. |
tolerance |
The acceptable difference between the sum of the K distribution and 1. |
normalize |
Boolean. If TRUE, the PMF is normalized to sum to 1. |
A numeric vector of cumulative probability densities.
pnbconv(quants = 200, mus = c(100, 10), phis = c(5, 8), method = "exact")
pnbconv(quants = 200, mus = c(100, 10), phis = c(5, 8), method = "exact")
Calculates the quantile function for the convolution of arbitrary negative binomial random variables.
qnbconv( probs, counts, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
qnbconv( probs, counts, mus, ps, phis, method = c("exact", "moments", "saddlepoint"), n.terms = 1000, n.cores = 1, tolerance = 0.001, normalize = TRUE )
probs |
Numeric vector of target (cumulative) probabilities. |
counts |
Integer vector of counts over which the PMF is evaluated. |
mus |
Numeric vector of individual mean values |
ps |
Numeric vector of individual probabilities of success. |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
method |
The method by which to evaluate the PMF. One of "exact", "moments", or "saddlepoint". |
n.terms |
The number of terms to include in the series representation of the exact PMF. Defaults to 1000. |
n.cores |
The number of CPU cores to use in the evaluation. Allows parallelization. |
tolerance |
The acceptable difference between the sum of the K distribution and 1. Defaults to 1E-3. |
normalize |
Boolean. If TRUE, the PMF is normalized to sum to 1. |
A numeric vector of quantiles.
qnbconv(probs = c(0.05, 0.25, 0.5, 0.75, 0.95), counts = 0:500, mus = c(100, 10), phis = c(5, 8), method = "exact")
qnbconv(probs = c(0.05, 0.25, 0.5, 0.75, 0.95), counts = 0:500, mus = c(100, 10), phis = c(5, 8), method = "exact")
Generates random samples from the convolution of arbitrary negative binomial random variables.
rnbconv(mus, phis, ps, n.samp, n.cores = 1)
rnbconv(mus, phis, ps, n.samp, n.cores = 1)
mus |
Numeric vector of individual mean values |
phis |
Numeric vector of individual dispersion parameters. Equivalent to 'size' in dnbinom. |
ps |
Numeric vector of individual probabilities of success. |
n.samp |
The number of samples per distribution |
n.cores |
The number of cores to use in the evaluation. Allows parallelization. |
A numeric vector of random deviates.
rnbconv(mus = c(100, 10), phis = c(5, 8), n.samp = 10)
rnbconv(mus = c(100, 10), phis = c(5, 8), n.samp = 10)