Fast and Stable Algorithms for Computing and Sampling from the Noncentral Hypergeometric Distribution

Article excerpt

**********

Although the noncentral hypergeometric distribution underlies conditional inference for 2 x 2 tables, major statistical packages lack support for this distribution. This article introduces fast and stable algorithms for computing the noncentral hypergeometric distribution and for sampling from it. The algorithms avoid the expensive and explosive combinatorial numbers by using a recursive relation. The algorithms also take advantage of the sharp concentration of the distribution around its mode to save computing time. A modified inverse method substantially reduces the number of searches in generating a random deviate. The algorithms are implemented in a Java class, Hypergeometric, available on the World Wide Web.

KEY WORDS: Inverse method; Recursive methods; 2 x 2 table.

1. INTRODUCTION

The noncentral hypergeometric distribution underlies conditional inference of 2 x 2 tables. Consider, for example, a clinical trial that compares two treatments. Let the number of subjects allocated to the two treatment groups be [n.sub.1] and [n.sub.2], respectively, and the number of subjects with a positive outcome be [Y.sub.1] and [Y.sub.2]. A natural model is then [Y.sub.i] ~ Binomial([n.sub.i], [[pi].sub.i]), i = 1, 2. For this design, the odds ratio

[psi] = [[pi].sub.1](1 - [[pi].sub.2])/[[pi].sub.2](1 - [[pi].sub.1]),

is often used to measure the relationship between treatment out come and treatment group. Let [m.sub.1] be the sum of the observed value of [Y.sub.1] and [Y.sub.2]. The conditional inference is based on the conditional distribution of [Y.sub.1] given [Y.sub.1] + [Y.sub.2] = [m.sub.1]

[p.sub.i] [equivalent to] Pr([Y.sub.1] = i\[Y.sub.1] + [Y.sub.2] = [m.sub.1])

[MATHEMATICAL EXPRESSION NOT REPRODUCIBLE IN ASCII]

where l = max(0, [m.sub.1] - [n.sub.2]) and u = min([n.sub.1], [m.sub.1]). For the special case of [psi] = 1, that is, [[pi].sub.1] = [[pi].sub.2], the noncentral distribution reduces to the familiar (central) hypergeometric distribution, on which Fisher's exact test is based. The same formulation applies to conditional inference of 2 x 2 tables where each cell follows a Poisson distribution. See, for example, Fisher (1935), Breslow and Day (1980), Agresti (1992), and McCullagh and Nelder (1989, chap. 7). The noncentral hypergeometric distribution thus has wide applications in medical, epidemiological, and social studies.

This article studies efficient algorithms for computing and sampling from the noncentral hypergeometric distribution. The proposed algorithms are implemented in a Java class Hypergeometric that provides methods (routines) for computing the probability mass, the cumulative distribution, the mean and variance, and for generating random deviates. The routines for computing the mean and variance are useful for estimating the odds ratio via maximum likelihood (McCullagh and Nelder 1989, chap. 7), and the routines for the probability mass and cumulative distribution facilitate the construction of confidence intervals and power calculation of associated tests (Vollset, Hirji, and Elash-hoff 1991). The routines for generating random deviates can be used in simulation-based methods for inference in more complicated problems (McDonald, Smith, and Forster 1999). The algorithms use a recursive relation to avoid the expensive and explosive combinatorial numbers. The algorithms also take advantage of the sharp concentratio n of the distribution around its mode in order to save computing time. A modified inverse method is developed for generating random deviates. We hope to dispel the perception that, except when the margins are small, the computation of the distribution is difficult (see McCullagh and Nelder 1989, p. 259; Breslow and Cologne 1986; McDonald, Smith, and Forster 1999). These perceived difficulties led to the development of special algorithms for computing the mean and variance of the distribution that avoid computing the probability distribution (Satten and Kupper 1990; Liao 1992). …