# packages
remotes::install_cran("countreg", repos = "http://R-Forge.R-project.org")
#> Skipping install of 'countreg' from a cran remote, the SHA1 (0.2-1) has not changed since last install.
#> Use `force = TRUE` to force installation
library(countreg)
#> Loading required package: MASS
# Examples
dhpois(x = 0, lambda = 1, pi = 0.5, log = TRUE)
#> [1] -0.6931472
dhpois(x = 1, lambda = 1, pi = 0.5, log = TRUE)
#> [1] -1.234472
dhpois(x = c(0, 1), lambda = 1, pi = 0.5, log = TRUE)
#> [1] -0.6931472 -1.2344720
# The following doesn't work
dhpois(x = c(1, 0), lambda = 1, pi = 0.5, log = TRUE)
#> [1] -1.234472 NA
# The problem is that in the following function definition, the expression
# log(1 - pi)[x == 0L] is not properly defined when legnth(pi) == 1 and
# x == 0L occurs after the 1st element.
# function (x, lambda, pi, log = FALSE)
# {
# rval <- dpois(x, lambda = lambda, log = TRUE) -
# ppois(0, lambda = lambda, lower.tail = FALSE, log.p = TRUE) +
# log(pi)
# rval[x == 0L] <- log(1 - pi)[x == 0L]
# if (log)
# rval
# else exp(rval)
# }
Created on 2020-04-14 by the reprex package (v0.3.0)