Skip to contents

Formula: p ~ Dir(alpha); y ~ Multinomial(n, p)

Usage

Diripr(counts, alpha = 1)

Arguments

counts

Observed category counts, non-negative.

alpha

Dirichlet prior; a scalar is recycled.

Value

List with estimate, post_mean, post_var, post_alpha, log_marginal, n, K, method.

Details

The posterior is Dir(alpha + y), so the posterior mean of p_j is (y_j + alpha_j) / (n + sum alpha) and the marginal likelihood is the Polya distribution n! Gamma(A)/Gamma(n+A) prod Gamma(y_j+a_j)/(y_j! Gamma(a_j)). With two categories this is exactly the beta-binomial.

References

Gelman et al. (2013), Bayesian Data Analysis, 3rd ed., CRC, ch. 3.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
Diripr(V)
#> $estimate
#> [1] 0.04545455
#> 
#> $post_mean
#> [1] 0.04545455 0.06818182 0.09090909 0.11363636 0.13636364 0.15909091 0.18181818
#> [8] 0.20454545
#> 
#> $post_var
#> [1] 0.0009641873 0.0014118457 0.0018365473 0.0022382920 0.0026170799
#> [6] 0.0029729109 0.0033057851 0.0036157025
#> 
#> $post_alpha
#> [1] 2 3 4 5 6 7 8 9
#> 
#> $log_marginal
#> [1] -17.28823
#> 
#> $n
#> [1] 36
#> 
#> $K
#> [1] 8
#> 
#> $method
#> [1] "Dirichlet-multinomial conjugate model"
#> 
#> attr(,"class")
#> [1] "morie_rich_result" "list"