bbm | R Documentation |
Moment estimates are computed from raw data or from observed mean, standard deviation and sample size. The asymptotic covariance matrix of the estimates is computed following Moore (1986).
bbm(obsmean = NULL, obssd = NULL,
obsskewness = NULL, obskurtosis = NULL,
size, x = NULL, N = NULL,
calcmoments = TRUE, vcov = TRUE,
logitrho = FALSE)
obsmean |
numeric. Observed mean. Can be omitted if |
obssd |
numeric. Observed standard deviation. Can be omitted if |
obsskewness |
numeric. Observed skewness. Can be omitted if |
obskurtosis |
numeric. Observed kurtosis. Can be omitted if |
size |
integer. Number of trials. |
x |
numeric vector of raw data with at least four observations. Can be omitted if |
N |
Number of observations. |
calcmoments |
logical. Should the third and fourth moments be calculated from the moment estimates? Defaults to |
vcov |
logical. Should the asymptotic covariance matrix be computed? Defaults to |
logitrho |
logical. Should the moment estimates be computed for logit(rho)? Defaults to |
The Beta-Binomial distribution is parametrized using the parameters \pi
and \rho
and assumes n
(= size
) trials. The mean is n\pi
and the variance n\pi(1-\pi) + n(n-1)\rho \pi(1-\pi)
in this parametrization. Following Moore (1986), logit(\pi)
, \rho
(or logit(\rho)
if logitrho
is TRUE
) and their asymptotic covariance matrix are estimated.
If the user specifies observed skewness and kurtosis or supplies raw data (and sets calcoments = FALSE
in either case), observed skewness and kurtotis are used in the estimation of the asymptotic covariance matrix. Otherwise theoretical skewness and kurtosis are calculated from the moment estimates using standard formulae for the skewness and kurtosis of the Beta-binomial parameters. Calculating moments is recommended and hence the default.
Returns a list with components
coef |
Estimates of parameters |
vcov |
Asymptotic covariance matrix of the estimates. |
Philipp Doebler <philipp.doebler@googlemail.com>
Moore, D. F. (1986). “Asymptotic properties of moment estimators for overdispersed counts and proportions”. Biometrika, 73 (3), 583–588.
betabinmoments
if (require("VGAM")) {
# simulate 100 data with 12 trials each, mean 6 = 12*0.5
# and some overdispersion
x <- VGAM::rbetabinom(100, 12, 0.5, 0.1)
# recover parameters with moment estimation
pars <- bbm(x = x, size = 12)
pars$coef[1] # should be close to 0 = logit(0.5)
1/(1+exp(-pars$coef[1])) # inverse logit
pars$coef[2] # estimate of rho
# use observed moments for calculation
# of asymptotic covariance matrix now:
pars2 <- bbm(x=x, size = 12, calcmoments = FALSE)
# compare calculated and observed moments
round(pars$vcov, 5)
round(pars2$vcov, 5)
} else {
# assume 100 data with 12 trials, mean 6 and observed standard deviation of 2.5
bbm(obsmean = 6, obssd = 2.5, size = 12, N = 100)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.