Skip to contents

For random variable \(X \sim TBinom(n,p)\), which follows the (zero)-truncated binomial distribution as defined by dtruncbinom() (i.e., binomial distribution with support for zero removed), calc_moments_truncbinom() computes \(\textrm{E}(X)\), \(\textrm{E}(X^2)\), \(\textrm{Var}(X)\), and \(\textrm{E}(1/X)\).

Usage

calc_moments_truncbinom(size, prob)

Arguments

size

scalar number of trials (n); must be 1 or more

prob

scalar probability of success on each trial (p); must be nonzero

Value

vector containing \(\textrm{E}(X)\), \(\textrm{E}(X^2)\), \(\textrm{Var}(X)\), and \(\textrm{E}(1/x)\)

Details

Note that moments are computed directly using the probability mass function since there is not a simple closed form for \(\textrm{E}(1/x)\). This may lead to slow computation for extremely large numbers of trials.

See also

dtruncbinom() for computing TBinom densities

Examples

calc_moments_truncbinom(30, .1)
#>          E_X       E_X_sq          V_X E_one_over_X 
#>     3.132803    12.217932     2.403477     0.428114 
calc_moments_truncbinom(30, .2)
#>          E_X       E_X_sq          V_X E_one_over_X 
#>    6.0074368   40.8505706    4.7612731    0.1991115