set.seed(1); rextbetabinom(10, 100, 0.5)
set.seed(1); rbinom(10, 100, 0.5) # Same
if (FALSE) N <- 9; xx <- 0:N; prob <- 0.5; rho <- -0.02
dy <- dextbetabinom(xx, N, prob, rho)
barplot(rbind(dy, dbinom(xx, size = N, prob)),
beside = TRUE, col = c("blue","green"), las = 1,
main = paste0("Beta-binom(size=", N,
", prob=", prob, ", rho=", rho, ") (blue) vs\n",
" Binom(size=", N, ", prob=", prob, ") (green)"),
names.arg = as.character(xx), cex.main = 0.8)
sum(dy * xx) # Check expected values are equal
sum(dbinom(xx, size = N, prob = prob) * xx)
cumsum(dy) - pextbetabinom(xx, N, prob, rho) # 0?
Run the code above in your browser using DataLab