Computes the unconditional variance via the law of total variance: $$ \text{Var}[Y] = q \cdot V_{\text{ZT}} + q (1 - q) \cdot (E_{\text{ZT}})^2, $$ where \(E_{\text{ZT}} = n\mu / (1 - p_0)\) is the zero-truncated mean and \(V_{\text{ZT}}\) is the zero-truncated variance.
Details
The zero-truncated variance is derived from the untruncated moments: $$ V_{\text{ZT}} = \frac{E_{\text{BB}}[Y^2]}{1 - p_0} - \left(\frac{E_{\text{BB}}[Y]}{1 - p_0}\right)^2, $$ where $$ E_{\text{BB}}[Y^2] = \text{Var}_{\text{BB}} + (n\mu)^2 = n\mu(1 - \mu) \frac{n + \kappa}{1 + \kappa} + n^2 \mu^2. $$
The result is clamped to be non-negative via pmax(., 0).
References
Ghosal, S., Ghosh, S., and Moores, M. (2020). “Hierarchical beta-binomial models for batch effects in cytometry data.” Journal of the Royal Statistical Society: Series A, 183(4), 1579–1601.
See also
Other distributions:
compute_p0(),
compute_ztbb_mean(),
dbetabinom(),
dhurdle_betabinom(),
dztbetabinom(),
hurdle_mean(),
pbetabinom(),
rbetabinom(),
rhurdle_betabinom(),
rztbetabinom()