extbetabinomUC.RdDensity, distribution function, quantile function and random generation for the extended beta-binomial distribution.
dextbetabinom(x, size, prob, rho = 0,
log = FALSE, forbycol = TRUE)
pextbetabinom(q, size, prob, rho = 0,
lower.tail = TRUE, forbycol = TRUE)
qextbetabinom(p, size, prob, rho = 0,
forbycol = TRUE)
rextbetabinom(n, size, prob, rho = 0)vector of quantiles.
vector of probabilities.
number of trials.
number of observations.
Same as runif.
the probability of success \(\mu\). Must be in the unit closed interval \([0,1]\).
the correlation parameter \(\rho\),
which
may be negative for underdispersion or
else be in the interval \([0, 1)\)
for overdispersion.
The default value of 0 corresponds to the
usual binomial distribution with
probability prob.
Same meaning as runif.
Logical.
A for loop cycles over either the rows or
columns and this argument determines which.
The rows are 1:length(x) and the
columns are 0:max(size).
The best choice is data set dependent.
dextbetabinom gives the density,
pextbetabinom gives the
distribution function,
qextbetabinom gives the quantile function
and
rextbetabinom generates random
deviates.
The extended beta-binomial distribution allows for a slightly negative correlation parameter between binary responses within a cluster (e.g., a litter). An exchangeable error structure with correlation \(\rho\) is assumed.
Currently most of the code is quite slow.
Speed improvements are a future project.
Use forbycol optimally.
Setting rho = 1 is not recommended
as NaN is returned,
however the code may be
modified in the future to handle this
special case.
set.seed(1); rextbetabinom(10, 100, 0.5)
#> [1] 52 46 60 49 52 51 63 52 47 38
set.seed(1); rbinom(10, 100, 0.5) # Same
#> [1] 52 46 60 49 52 51 63 52 47 38
if (FALSE) N <- 9; xx <- 0:N; prob <- 0.5; rho <- -0.02
#> Error: object 'N' not found
dy <- dextbetabinom(xx, N, prob, rho)
#> Error: object 'xx' not found
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)
#> Error: object 'dy' not found
sum(dy * xx) # Check expected values are equal
#> Error: object 'dy' not found
sum(dbinom(xx, size = N, prob = prob) * xx)
#> Error: object 'xx' not found
cumsum(dy) - pextbetabinom(xx, N, prob, rho) # 0?
#> Error: object 'dy' not found
# \dontrun{}