Package 'multChernoff'

Title: Finite-Sample Tail Bound of Likelihood Ratio Test under Multinomial Sampling
Description: Computes a finite-sample tail bound for the log-likelihood ratio test (LRT) statistic under multinomial sampling. The resulting bound is used to compute finite-sample conservative p-values and critical values when the standard chi-squared asymptotics can be unreliable. The package also supports multiple independent multinomial trials.
Authors: Richard Guo [aut, cre, cph], Ivana Liu [aut]
Maintainer: Richard Guo <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2026-05-23 08:59:02 UTC
Source: https://github.com/richardkwo/multchernoff

Help Index


Critical value x such that P(2LRT>x)pP(2 LRT > x) \le p

Description

The LRT is the log-likelihood ratio test statistic, which can be written as

LRT=nKL(p^p).LRT = n \, KL(\hat{p} \| p).

By the Wilks' theorem, for a fixed k-dimensional probability vector, it holds that

2×LRTdχk12.2 \times LRT \to_{d} \chi^2_{k-1}.

This function returns a finite-sample counterpart to qchisq(p, k-1, lower.tail=FALSE). The LRT is also extended to multiple independent multinomial trials. For example, for a (k1,n1)(k_1, n_1)-trial and a (k2,n2)(k_2, n_2)-trial, we have

LRT=n1KL(p^1p1)+n2KL(p^2p2).LRT = n_1 \, KL(\hat{p}_1 \| p_1) + n_2 \, KL(\hat{p}_2 \| p_2).

Usage

criticalValue(k, n, p = 0.05, verbose = FALSE)

Arguments

k

number of categories (a vector for independent multinomial draws)

n

sample size (a vector for independent multinomial draws)

p

significance level (e.g., 0.05)

verbose

draw the minimizer if TRUE

Value

A finite-sample critical value xx such that the bound on P(2×LRT>x)P(2 \times LRT > x) is at most p.

Note

For independent multinomial samples, k and n must be of the same length.

See Also

tailProbBound, mgfBound

Examples

n <- 1:40
crit <- sapply(n, function(.n) criticalValue(20, .n, p=0.01))
plot(n, crit)
# chi-squared asymptotic by Wilks' theorem
abline(h=qchisq(0.01, df=20-1, lower.tail = FALSE))
criticalValue(10, 40, p=0.05)
# two independent multinomial trials (k=3, n=4) and (k=12, n=20)
criticalValue(c(3, 4), c(12, 20), p=0.05)

An upper bound on the moment generating function of LRT

Description

The LRT is the log-likelihood ratio test statistic, which can be written as

LRT=nKL(p^p),LRT = n \, KL(\hat{p} \| p),

namely the Kullback-Leibler divergence from the empirical probabilities to the true probabilities multiplied by the sample size. G(λ;k,n)G(\lambda; k,n) is a polynomial in λ\lambda such that

MGF(λ;LRT):=Ep[exp(λ×LRT)]G(λ;k,n)MGF(\lambda; LRT) := E_{p}[\exp(\lambda \times LRT)] \leq G(\lambda; k,n)

holds for every λ[0,1]\lambda \in [0,1] and every pp.

Usage

mgfBound(k, n, lambda)

Arguments

k

number of categories

n

sample size

lambda

number between 0 and 1

Value

A numeric upper bound on the MGF of LRT evaluated at lambda.

See Also

tailProbBound, criticalValue

Examples

mgfBound(k = 5, n = 20, lambda = 0.5)
mgfBound(k = 5, n = 20, lambda = 0)  # always 1 at lambda = 0

Tail bound on P(2 LRT > x).

Description

The LRT is the log-likelihood ratio test statistic, which can be written as

LRT=nKL(p^p).LRT = n \, KL(\hat{p} \| p).

By the Wilks' theorem, for a fixed k-dimensional probability vector, it holds that

2×LRTdχk12.2 \times LRT \to_{d} \chi^2_{k-1}.

This function returns a finite-sample counterpart to pchisq(x, k-1, lower.tail=FALSE). The LRT is also extended to multiple independent multinomial trials. For example, for a (k1,n1)(k_1, n_1)-trial and a (k2,n2)(k_2, n_2)-trial, we have

LRT=n1KL(p^1p1)+n2KL(p^2p2).LRT = n_1 \, KL(\hat{p}_1 \| p_1) + n_2 \, KL(\hat{p}_2 \| p_2).

Usage

tailProbBound(x, k, n, verbose = FALSE)

Arguments

x

the value of 2×LRT2 \times LRT

k

number of categories (a vector for independent multinomial draws)

n

sample size (a vector for independent multinomial draws)

verbose

draw the minimizer if TRUE

Value

An upper bound on P(2 LRT > x), which can be used as a conservative p-value.

Note

For independent multinomial samples, k and n must be of the same length.

See Also

criticalValue, mgfBound

Examples

tailProbBound(20, 7, 50)
pchisq(20, 6, lower.tail=FALSE) # compare with the standard chi-square asymptotic
# two independent multinomial trials (k=3, n=4) and (k=12, n=20)
tailProbBound(12, c(3, 4), c(12, 20))
pchisq(12, 5, lower.tail=FALSE) # compare with the standard chi-square asymptotic