Learn R Programming

VGAM (version 1.1-1)

Gentbinom: Generally-Truncated-Binomial Distribution

Description

Density, distribution function, and random generation for the generally-truncated binomial distribution.

Usage

dgentbinom(x, size, prob, truncate = 0, log = FALSE)
pgentbinom(q, size, prob, truncate = 0)
rgentbinom(n, size, prob, truncate = 0, maxits = 10000)

Arguments

x, q

vector of quantiles.

n

number of observations. Fed into rbinom.

size, prob, log

See rbinom.

truncate

vector of integers from the set 0:size; the truncated values. Must have unique values only. A NULL is acceptable and means an empty set.

maxits

Maximum number of iterations; used to avoid an infinite loop. If exceeded, random variates of NAs are returned.

Value

dgentbinom gives the density, pgentbinom gives the distribution function, rgentbinom generates random deviates.

Warning

The function can run slowly for certain combinations of size, prob and truncate, e.g., rgentbinom(100, size = 10, prob = 0.1, trunc = 0:4). Failure to obtain random variates will result in some NA values instead.

Details

The generally-truncated binomial distribution is a binomial distribution with the probability of certain (truncated) values being zero. The other probabilities are scaled to add to unity.

See Also

gentbinomial, Genabinom, Genibinom, dposbinom, rbinom, gentpoisson.

Examples

Run this code
# NOT RUN {
size <- 10; prob <- 0.5
y <- rgentbinom(n = 1000, size, prob, truncate = 3:5)
table(y)
tvec <- c(4, 5, 7)  # Truncate these values
(ii <- dgentbinom(0:7, size, prob, truncate = tvec))
table(rgentbinom(100, size, prob, truncate = tvec))

# }
# NOT RUN {
 x <- 0:size
barplot(rbind(dgentbinom(x, size, prob, truncate = tvec),
              dbinom(x, size, prob)),
        beside = TRUE, col = c("blue", "orange"),
        main = paste("Gen-trunc Binomial(", size, ", ", prob,
                     ", truncate = c(", paste(tvec, collapse = ", "),
                     ")) vs",
        " Binomial(", size, ", ", prob, ")", sep = ""),
        sub = "Generally-truncated binomial is blue; Binomial is orange",
        names.arg = as.character(x), las = 1, lwd = 2) 
# }

Run the code above in your browser using DataLab