getNegBinFromCI {bootComb}R Documentation

Find the best-fit negative binomial distribution for a given confidence interval.

Description

Finds the best-fit negative binomial distribution for a given confidence interval; returns the corresponding probability mass, distribution, quantile and sampling functions. The use of this function within the bootComb package is limited: this is a discrete distribution but since users provide confidence intervals, the corresponding parameters will be best approximated by continuous distributions.

Usage

getNegBinFromCI(
  qLow,
  qUpp,
  alpha = 0.05,
  initPars = c(10, 0.5),
  maxiter = 1000
)

Arguments

qLow

The observed lower quantile.

qUpp

The observed upper quantile.

alpha

The confidence level; i.e. the desired coverage is 1-alpha. Defaults to 0.05.

initPars

A vector of length 2 giving the initial parameter values (size & prob) to start the optimisation; defaults to c(10,0.5).

maxiter

Maximum number of iterations for optim. Defaults to 1e3. Set to higher values if convergence problems are reported.

Value

A list with 5 elements:

r

The sampling function.

d

The probability mass function.

p

The distribution function.

q

The quantile function.

pars

A vector of length 2 giving the mean and standard deviation for the best-fit negatove binomial distribution (size and prob as in rnbinom, dnbinom, pnbinom, qnbinom).

See Also

identifyNegBinPars, optim, dnbinom

Examples

n<-getNegBinFromCI(qLow=1.96,qUpp=19.12)
print(n$pars) # the fitted parameter values (size & prob)
n$r(10) # 10 random values from the fitted negative binomial distribution
n$d(8) # the probability mass at x=8 for the negative binomial distribution
n$p(12) # the cumulative probability at x=12 for the fitted negative binomial distribution
n$q(c(0.25,0.5,0.75)) # the 25th, 50th (median) and 75th percentiles of the fitted distribution
x<-0:30
y<-n$d(x)
barplot(height=y,names.arg=x,xlab="",ylab="probability mass") # bar plot of the fitted neg. bin. pmf


[Package bootComb version 1.1.2 Index]