Learn R Programming

VGAM (version 1.1-1)

Gentpois: Generally-Truncated Poisson Distribution

Description

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

Usage

dgentpois(x, lambda, truncate = 0, max.support = Inf, log = FALSE)
pgentpois(q, lambda, truncate = 0, max.support = Inf)
rgentpois(n, lambda, truncate = 0, max.support = Inf, maxits = 10000)

Arguments

x, q

vector of quantiles.

n

number of observations. Fed into rpois.

lambda

vector of positive means (of an ordinary Poisson distribution). Short vectors are recycled.

truncate

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

max.support

numeric; the maximum support value so that any value larger has been truncated. This argument is necessary because truncate = (max.support + 1):Inf is impractical, so this is the way to truncate the upper tail of the distribution. Note that max(truncate) < max.support must be satisfied otherwise an error message will be issued.

log

logical; see dpois.

maxits

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

Value

dgentpois gives the density, pgentpois gives the distribution function, rgentpois generates random deviates.

Warning

The function can run slowly for certain combinations of lambda and truncate, e.g., rgentpois(100, 1, trunc = 0:5). Failure to obtain random variates will result in some NA values instead.

Details

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

See Also

gentpoisson, Genapois, Genipois, dpospois, rpois.

Examples

Run this code
# NOT RUN {
lambda <- 2; y <- rgentpois(n = 1000, lambda, truncate = 3:5)
table(y)
tvec <- 2:4  # Truncate these values
(ii <- dgentpois(0:7, lambda, truncate = tvec))
table(rgentpois(100, lambda, truncate = tvec))

# }
# NOT RUN {
 x <- 0:7
barplot(rbind(dgentpois(x, lambda, truncate = tvec),
              dpois(x, lambda)),
        beside = TRUE, col = c("blue", "orange"),
        main = paste("Gen-truncated Pois(lambda = ", lambda, ", ",
                     "truncate = c(", paste(tvec, collapse = ","),
                     ")) vs",
        " Pois(", lambda, ")", sep = ""),
        sub = "Generally-truncated Poisson is blue; Poisson is orange",
        names.arg = as.character(x), las = 1, lwd = 2) 
# }

Run the code above in your browser using DataLab