bbm: Moment estimates of Beta-binomial parameters

View source: R/bbm.R

bbmR Documentation

Moment estimates of Beta-binomial parameters

Description

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).

Usage

bbm(obsmean = NULL, obssd = NULL, 
    obsskewness = NULL, obskurtosis = NULL, 
    size, x = NULL, N = NULL, 
    calcmoments = TRUE, vcov = TRUE,
    logitrho = FALSE)

Arguments

obsmean

numeric. Observed mean. Can be omitted if x is not NULL.

obssd

numeric. Observed standard deviation. Can be omitted if x is not NULL.

obsskewness

numeric. Observed skewness. Can be omitted if x is not NULL. Only used for the estimation of the asymptotic covariance matrix if calcmoments = FALSE.

obskurtosis

numeric. Observed kurtosis. Can be omitted if x is not NULL. Only used for the estimation of the asymptotic covariance matrix if calcmoments = FALSE.

size

integer. Number of trials.

x

numeric vector of raw data with at least four observations. Can be omitted if obsmean, obssd and N are supplied.

N

Number of observations.

calcmoments

logical. Should the third and fourth moments be calculated from the moment estimates? Defaults to TRUE.

vcov

logical. Should the asymptotic covariance matrix be computed? Defaults to TRUE.

logitrho

logical. Should the moment estimates be computed for logit(rho)? Defaults to FALSE, that is, the moment estimates are computed for rho without any transformation.

Details

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.

Value

Returns a list with components

coef

Estimates of parameters logit(\pi) and \rho (or logit(\rho) if logitrho is TRUE).

vcov

Asymptotic covariance matrix of the estimates.

Author(s)

Philipp Doebler <philipp.doebler@googlemail.com>

References

Moore, D. F. (1986). “Asymptotic properties of moment estimators for overdispersed counts and proportions”. Biometrika, 73 (3), 583–588.

See Also

betabinmoments

Examples

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)
  }


maid documentation built on March 31, 2023, 3:07 p.m.