Calculate parameters required in a Dirichlet distribution
dirichlet_params.Rddirichlet_params calculates the 'alpha' values of a Dirichlet distribution from the mean values
and one variance value.
Value
The corresponding alpha values for the Dirichlet distribution. If the alpha values are
negative the variance should be decreased. A warning is issued in this case.
Details
Input mean vector must contain mean values for each component of the Dirichlet distribution.
If one value is missing (signaled with a NA) it is calculated from the sum of all other mean values.
In turn, only one variance value must be introduced and all other elements in the variance
vector must have an NA.
Examples
# Mean and variance values as input.
m <- c(.3, .23,.27, .2)
v <- c(NA, .1, NA, NA)
alpha <- dirichlet_params(m, v)
# Calculate mean values from alpha.
print(alpha/sum(alpha))
#> [1] 0.30 0.23 0.27 0.20
# Calculate variance values from alpha.
alpha0 <- sum(alpha)
beta <- alpha / alpha0
print(beta*(1-beta)/(1+alpha0))
#> [1] 0.11857708 0.10000000 0.11129305 0.09034444