# NOT RUN {
size <- 10; prob <- 0.2; pstr1 <- 0.4; x <- (-1):size
(ii <- doiposbinom(x, size, prob, pstr1 = pstr1))
table(roiposbinom(100, size, prob, pstr1 = pstr1))
round(doiposbinom(x , size, prob, pstr1 = pstr1) * 100) # Should be similar
# }
# NOT RUN {
x <- 0:size
par(mfrow = c(2, 1)) # One-Inflated Positive Binomial
barplot(rbind(doiposbinom(x, size, prob, pstr1 = pstr1),
dposbinom(x, size, prob)),
beside = TRUE, col = c("blue", "orange"),
main = paste("OIPB(", size, ",", prob, ", pstr1 = ", pstr1, ") (blue) vs",
" PosBinomial(", size, ",", prob, ") (orange)", sep = ""),
names.arg = as.character(x))
# Zero-deflated Pos Binomial
deflat.limit <- -dposbinom(1, size, prob) / (1 - dposbinom(1, size, prob))
deflat.limit <- size * prob / (1 + (size-1) * prob - 1 / (1-prob)^(size-1))
newpstr1 <- round(deflat.limit, 3) + 0.001 # A little from the boundary
barplot(rbind(doiposbinom(x, size, prob, pstr1 = newpstr1),
dposbinom(x, size, prob)),
beside = TRUE, col = c("blue","orange"),
main = paste("ODPB(", size, ",", prob, ", pstr1 = ", newpstr1, ") (blue) vs",
" PosBinomial(", size, ",", prob, ") (orange)", sep = ""),
names.arg = as.character(x))
# }
Run the code above in your browser using DataLab