Skip to contents

Computes \(\mathrm{Var}(K_J \mid \alpha)\) under a Dirichlet process prior.

Usage

var_K_given_alpha(J, alpha)

Arguments

J

Sample size (integer >= 1).

alpha

Concentration parameter (positive numeric, vectorized).

Value

Numeric vector of conditional variances (same length as alpha).

Details

The classical trigamma closed form is: $$v_J(\alpha) = \mu_J(\alpha) - \alpha^2\{\psi_1(\alpha) - \psi_1(\alpha+J)\}$$ where \(\psi_1(\cdot)\) is the trigamma function.

This is equivalent to the direct summation: $$v_J(\alpha) = \sum_{i=1}^{J} \frac{\alpha(i-1)}{(\alpha + i - 1)^2}$$

Key property: \(0 \leq v_J(\alpha) < \mu_J(\alpha)\) for all \(\alpha > 0\). The lower inequality is strict when J > 1; at J = 1, \(K_J=1\) deterministically and the variance is zero.

Limiting behavior:

  • \(\alpha \to 0^+\): \(v_J(\alpha) \to 0\)

  • \(\alpha \to \infty\): \(v_J(\alpha) \to 0\)

The implementation evaluates each Bernoulli variance contribution as a non-negative ratio term. It remains stable at both small and large alpha without clipping cancellation artifacts to zero.

Examples

var_K_given_alpha(50, 2.0)
#> [1] 4.535558
var_K_given_alpha(50, c(0.5, 1, 2, 5))
#> [1] 1.709074 2.874073 4.535558 7.386114

# Verify underdispersion
J <- 50; alpha <- 2.0
mean_K_given_alpha(J, alpha) > var_K_given_alpha(J, alpha)  # TRUE
#> [1] TRUE