Skip to contents

A Dirichlet law \(W = \mathrm{Dir}(\alpha)\) over the probability simplex, possibly truncated to a region. Paired with a multinomial_family() it induces a continuous mixture. dirichlet_dist is the abstract parent of dirichlet() and truncated_dirichlet().

print() on a truncated Dirichlet shows the concentration and the region it is truncated to.

Usage

dirichlet(alpha)

truncated_dirichlet(alpha, region, degree_slack = 0L, max_nodes = 1e+06)

dirichlet_dist(alpha = integer(0))

Arguments

alpha

Length-K vector of positive concentrations, K >= 2. truncated_dirichlet() requires whole numbers.

region

A region of the probability simplex in R^K, bounded and full-dimensional. truncated_dirichlet() only.

degree_slack

Raise the quadrature rule's degree by this much. The default of 0 is already exact; this exists for testing. truncated_dirichlet() only.

max_nodes

Refuse a rule with more nodes than this. truncated_dirichlet() only.

Value

A dirichlet or a truncated_dirichlet; both are dirichlet_dist objects.

Over the full probability simplex

dirichlet() is \(\mathrm{Dir}(\alpha)\) over the whole simplex. With a multinomial_family() it induces the Dirichlet-multinomial, evaluated exactly in closed form; alpha may be any positive reals.

Truncated to a region of the simplex

truncated_dirichlet() is \(\mathrm{Dir}(\alpha)\) conditioned on \(\theta \in A\) for a region A of the simplex, e.g. the complement of the null, giving a mixing measure supported on the alternative.

region is split into disjoint simplices by cells(disjoin(region)). Cells with fewer than K vertices have measure zero and are dropped with a warning; a region with no full-dimensional cell is refused.

The integrand is a monomial of degree |alpha| + n - K, so a Gauss-Jacobi rule of that degree on each cell is exact. This needs integer alpha: non-integer concentrations make the integrand singular on the boundary.

Examples

# `dirichlet_dist` is abstract; the two constructors subclass it:
S7::S7_inherits(dirichlet(alpha = c(4, 3, 2)), dirichlet_dist)
#> [1] TRUE

fam <- multinomial_family(n_trials = 6L, k = 3L)
Q <- fam(dirichlet(alpha = c(4, 3, 2)))
sum(exp(log_density(Q, enumerate_space(fam@sample_space))))
#> [1] 1

# A uniform prior gives each of the `choose(n + K - 1, K - 1)` outcomes
# equal mass.
flat <- fam(dirichlet(alpha = c(1, 1, 1)))
unique(round(exp(log_density(flat, enumerate_space(fam@sample_space))), 12))
#> [1] 0.03571429
1 / choose(6 + 3 - 1, 3 - 1)
#> [1] 0.03571429

# The plurality null
plurality <- simplex_region(vertices = rbind(
  c(0.5, 0.5, 0), c(0, 1, 0), c(0, 0, 1)
)) | simplex_region(vertices = rbind(
  c(0.5, 0, 0.5), c(0, 1, 0), c(0, 0, 1)
))
# and the region where candidate 1 wins outright
alt <- fam@parameter_space - plurality

W1 <- truncated_dirichlet(alpha = c(4, 3, 2), region = alt)

# Still a proper distribution, on the outcomes that region can produce.
sum(exp(log_density(fam(W1), enumerate_space(fam@sample_space))))
#> [1] 1