Skip to content

Commit

Permalink
correctly handle density for lambda = 0 or mu = 0 in zero-truncated c…
Browse files Browse the repository at this point in the history
…ount distributions (#97)
  • Loading branch information
zeileis authored Jan 18, 2023
1 parent 7d2338c commit 67d27df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/ZTNegativeBinomial.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ dztnbinom <- function(x, mu, theta, size, log = FALSE) {
if(!missing(size)) theta <- size
rval <- dnbinom(x, mu = mu, size = theta, log = TRUE) - pnbinom(0, mu = mu, size = theta, lower.tail = FALSE, log.p = TRUE)
rval[x < 1] <- -Inf
rval[mu <= 0] <- 0
rval[mu <= 0] <- -Inf
rval[(mu <= 0) & (x == 1)] <- 0
if(log) rval else exp(rval)
}

Expand Down
3 changes: 2 additions & 1 deletion R/ZTPoisson.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
dztpois <- function(x, lambda, log = FALSE) {
rval <- dpois(x, lambda, log = TRUE) - ppois(0, lambda, lower.tail = FALSE, log.p = TRUE)
rval[x < 1] <- -Inf
rval[lambda <= 0] <- 0
rval[lambda <= 0] <- -Inf
rval[(lambda <= 0) & (x == 1)] <- 0
if(log) rval else exp(rval)
}

Expand Down

0 comments on commit 67d27df

Please sign in to comment.