zibinom: The Zero Inflated Binomial Distribution

Description Usage Arguments Details Value See Also Examples

View source: R/xzibinom.R

Description

Density, distribution function, quantile function and random generation for the zero inflated binomial distribution with parameters (rho, size, prob).

Usage

1
2
3
4
5
6
7
dzibinom(x, rho, size, prob, log = FALSE)

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

qzibinom(p, rho, size, prob, lower.tail = TRUE, log.p = FALSE)

rzibinom(n, rho, size, prob)

Arguments

x

A non-negative integer-valued vector of quantiles.

q

A numeric vector of quantiles.

p

A vector of probabilities.

n

Number of random values to return, a length-one positive integer-valued vector.

rho

A length-one vector of zero inflation parameter on [0,1].

size

A length-one vector of number of trials (zero or more).

prob

A length-one vector of probability of success on each trial.

log, log.p

A length-one logical vector; if TRUE, probabilities p are given as log(p).

lower.tail

A length-one logical vector; if TRUE (the default), probabilities are P(X ≤ x), otherwise, P(X > x).

Details

The probability mass function of X is given by

P(X=x) = rho I(x = 0) + (1 - rho) P(Y=x), x=0,1,2,...,

where Y is distributed binomial(size, prob).

Value

dzibinom gives the (log) density, pzibinom gives the (log) distribution function, qzibinom gives the quantile function, and rzibinom generates random deviates.

Invalid arguments rise an error.

See Also

Binomial for the binomial distribution.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Example 1: dzibinom
dzibinom(x = 0:10, rho = 0.1, size = 5, prob = 0.5)

# Example 2: pzibinom
pzibinom(q = 2, rho = 0.1, size = 5, prob = 0.5)

# Example 3: qzibinom
qzibinom(p = pzibinom(2, 0.1, 5, 0.5), rho = 0.1, size = 5, prob = 0.5)

# Example 4: rzibinom
n <- 1e+5
rho <- 0.2
size <- 5
prob <- 0.5
mean(rzibinom(n, rho, size, prob)) # Sample mean
(size * prob) * (1 - rho) # Theoretical mean

Example output

 [1] 0.128125 0.140625 0.281250 0.281250 0.140625 0.028125 0.000000 0.000000
 [9] 0.000000 0.000000 0.000000
[1] 0.55
[1] 2
[1] 2.00435
[1] 2

attrCUSUM documentation built on May 2, 2019, 9:25 a.m.