calc.beta: Calculate Beta Values

Description Usage Arguments Details Value Note Author(s)

Description

Obtain values from a Beta Distribution based on an input mean and variance. Note that the mean and variance are NOT the same as the Alpha and Beta inputs. I added a check - if Var is 0, then just the mean is returned (and no Beta distribution is applied). Note that the variance is not like a typical variance in that at low variance values close to the mean are much more likely, and at high values, values far from the mean are much more likely (and the mean itself will have a relatively low probability of being drawn.

Usage

1
calc.beta(num.out, mu, Var)

Arguments

num.out

The number of values to generate based on the beta distribution

mu

The desired mean for the distribution. Must be between 0 and 1.

Var

The desired variance for the distribution

Details

Derivation for constraint on variance based on the mean:
Mean must be > 0, Var must be > 0 (if Var == 0, then just the mean will be returned). Addionally, Var must be <= mean * (1 - mean) in order to ensure that alpha is positive alpha and beta, the parameter inputs to the beta distribution are constrained to be >= 0. Consequently, below, we solve for the equation that determines allowed values of Var depending on the value of the mean.
mean * ( (1 - mean) * mean * (1 / Var) - 1) = alpha
mean * ( (1 - mean) * mean * (1 / Var) - 1) >= 0 #alpha must be >= 0
mean * ( mean * (1/Var) - mean^2 * (1 / Var) - 1) >= 0 #expand
mean^2 / Var - mean^3 / Var - mean >= 0 #expand further
mean^2 - mean^3 - mean * Var >= 0 #multiply by Var. No change in direction of >= sign, because Var must be > 0
mean^2 - mean^3 >= mean * Var #Add mean * Var to both sides of equation
mean - mean^2 >= Var #divide by mean. No change in direction of >= sign because mean > 0
mean(1 - mean) >= Var #factor
Var <= mean(1 - mean) #Re-arrange to be more intuitive
Beta imposes the exact same constraint as alpha (can substitute alpha into the equation for beta then use algebra). Beta = alpha/mean - alpha Not shown here.

Value

Returns a vector of length num.out with values from the Beta distribution.

Note

From Jakob's ScriptA.2_BetaDistribution_2011_01_18.r

Author(s)

Jakob L. K. Gerstenlauer (main function) and Sasha Keyel (error messages)


akeyel/spatialdemography documentation built on May 12, 2019, 4:43 a.m.