Bayesian Chi-Square Test

Statistics
Introduced by
I. J. Good; extended by Gunel, Dickey, and Wagenmakers et al.
Year
1967
Type
Bayesian nonparametric association test
Family
Classical statistics

What does it do?

The Bayesian chi-square test assesses whether categorical variables in a contingency table are associated, using a Bayes factor instead of a p-value.

The Bayes factor BF10 is the ratio of the marginal likelihoods of the observed counts under an association model and under an independence model. Because it can favour either hypothesis, it can give positive evidence for independence, which a non-significant p-value cannot. The same name is used for other Bayesian chi-square procedures, for example the econometric test of Li, Liu and Yu (2015); this entry covers only independence in contingency tables.

The intuition behind the method

Imagine a table of counts showing how men and women prefer tea, coffee or juice. The classical chi-square test asks whether the counts are extreme enough to reject independence. The Bayesian version asks how many times more probable the observed counts are under a model with an association than under a model in which the variables are independent. A Bayes factor above 1 favours association and one below 1 favours independence. A non-significant p-value does not establish independence, but a Bayes factor below 1 is direct evidence in that direction.

History

Good (1967) developed a Bayesian significance test for multinomial distributions and compared it with several non-Bayesian criteria; his abstract notes that chi-squared also has a Bayesian justification for large samples. That work addresses multinomial significance testing rather than the independence test covered here. Gunel and Dickey (1974, Biometrika 61(3), 545-557) developed the default Bayes factors for contingency tables under several sampling models. Jamil et al. (2017) describe these default Bayes factors for R x C tables, illustrate them with simulations and practical examples, and provide code in the BayesFactor R package and JASP.

When to use it

Use this test when you have two or more categorical variables arranged in a contingency table and want to quantify evidence for association or for independence, rather than only rejecting or retaining a null. It is suited to situations where you need to distinguish 'no evidence of association' from 'evidence of no association', and where you can state a reasonable prior for the cell probabilities. Choose the sampling model to match the design under which the table was collected, since the design determines which model is appropriate. Do not use it when the data are not counts (for example continuous outcomes), when many cells have very low expected counts, since the Bayes factor will be unstable and sensitive to the prior, or when you cannot justify a prior at all. The test addresses independence in R x C tables; it is not a goodness-of-fit test of a specified set of cell probabilities.

Limitations and considerations

  • The Bayes factor depends on the prior placed on the cell probabilities; with small counts, changing the concentration parameter can change the verdict, so the prior is part of the result.
  • The default Bayes factors are tied to specific sampling models, and a table collected under a different design may require a different model.
  • The output is a comparison of two models rather than a parameter estimate; it does not directly give interval estimates for cell probabilities, which need a separate analysis under a chosen model.
  • Reading the scale correctly takes practice: BF10 below 1 favours independence, but a value near 1 means the data are uninformative, not that the null is true.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Because BF10 is a ratio of marginal likelihoods, it can fall below 1 and favour independence, so a result can be positive evidence for the null rather than only a failure to reject it.
  • It reports graded evidence, so BF10 values that differ only slightly are not pushed into different categories by a fixed alpha threshold.
  • Default sampling-model Bayes factors for contingency tables have been published and implemented in JASP and the BayesFactor R package, so the analysis can be reproduced in standard tools.
  • The same likelihood-ratio structure applies to R x C tables of any size, so the test is not restricted to 2 x 2 tables.

Applications

  • Testing independence in an R x C survey cross-tabulation where a researcher needs evidence for, and not only the absence of, an association.
  • Reporting a Bayes factor alongside the classical Pearson chi-square statistic for the same table, so readers can compare the two.
  • Analysing 2 x 2 tables of categorical outcomes, as a special case of R x C tables, under a sampling model matched to the data collection design.
  • Recomputing BF10 as counts accumulate in batches, while stating the prior used at each stage.

How it works

How it works

1

Two competing models are defined. H0 asserts that the row and column variables are independent, so cell probabilities equal products of the row and column marginal probabilities. H1 asserts that they are associated, with cell probabilities free to vary. The goal is to weigh the evidence for one model over the other. Several sampling models exist for contingency tables (for example multinomial, product-multinomial and hypergeometric), and the choice of sampling model affects the Bayes factor.

Formula
H_1: \text{association}\quad H_0: \text{independence};\quad BF_{10} = P(\text{data}|H_1)/P(\text{data}|H_0)
2

The model requires a prior distribution over the cell probabilities, and this prior must be stated. The default prior depends on the sampling model and on the software used, so it should be read from the documentation of the BayesFactor R package or JASP and reported with the result. Because the Bayes factor depends on the prior, check the conclusion by varying the prior when its choice is uncertain.

3

BF10 is the ratio of two marginal likelihoods: the probability of the observed counts under H1 and under H0, each averaged over the parameter values according to its prior. Under H0 the cell probabilities are constrained to products of the marginals; under H1 they are free. Jamil et al. describe default Bayes factors for several sampling models for contingency tables, and these forms are implemented in the BayesFactor R package and in JASP.

Formula
BF_{10} = \frac{\int P(\mathbf{x}|\boldsymbol{\theta}, H_1)\,p(\boldsymbol{\theta}|H_1)\,d\boldsymbol{\theta}}{\int P(\mathbf{x}|\boldsymbol{\theta}, H_0)\,p(\boldsymbol{\theta}|H_0)\,d\boldsymbol{\theta}}
4

BF10 is read on a continuous scale rather than against a fixed cut-off. Verbal labels are sometimes used as rough guides: values well above 1 are described as evidence for association, values well below 1 as evidence for independence, and values near 1 as uninformative. These labels are conventions, not formal decision rules, and any value should be read together with the prior used. Unlike a p-value, the Bayes factor can be recalculated as more counts are collected, although the prior enters each calculation.

5

The Bayes factor is the primary inferential output. Complementary descriptives include the observed and expected cell frequencies, row and column percentages, and Cramer's V as a standardised measure of association strength, all reported alongside the Bayes factor.

Common pitfalls

  • Reading a BF10 near 1 as evidence for H0; a value near 1 means the data do not discriminate between the hypotheses.
  • Reporting BF10 without the prior and without a sensitivity check, which hides the fact that the conclusion may depend on the prior, especially in small samples.
  • Confusing directions: BF10 and BF01 are reciprocals, so state which direction is reported and check it before interpreting the value.
  • Applying a sampling model that does not match how the table was collected, since the design determines which model is appropriate.
  • Using sparse tables with very few counts per cell, where both the classical and the Bayesian results can be unstable and the Bayes factor is also sensitive to the prior; check the expected cell counts before analysis.

Frequently asked questions

How is this different from the classical chi-square test?

The classical chi-square test produces a p-value, the probability of data this extreme or more extreme under the null of independence. The Bayesian version produces a Bayes factor, which directly compares how probable the observed counts are under the association model and the independence model. Unlike a p-value, the Bayes factor can favour the independence model. Good (1967) also noted that chi-squared has a Bayesian justification for large samples.

What prior should I choose?

The default prior depends on the sampling model and on the software, so there is no single default that applies to every table. Check the documentation of the software you run (the BayesFactor R package or JASP) and report the prior used. If you have substantive prior knowledge about the cell probabilities, an informative prior can be specified, but the conclusions should then be checked across a range of plausible prior settings.

What does a Bayes factor of 6 mean?

BF10 = 6 means the observed counts are six times more probable under the association hypothesis than under the independence hypothesis. Whether this counts as moderate or strong evidence is a matter of convention rather than a formal cut-off, so judge it together with the prior and the sample size.

Can I use this with a 2x2 table?

Yes. A 2 x 2 table is a special case of an R x C table, and the default Bayes factors described by Jamil et al. cover contingency tables in general. The sampling model you choose should match how the data were collected. The Bayesian Fisher exact test is a related option for 2 x 2 tables.

What software supports this test?

Jamil et al. describe implementations in JASP and in the BayesFactor R package. Both can be used to compute BF10 for contingency tables, and the output should state the prior and the direction of the Bayes factor.

Related methods

Sources

  1. Good, I. J. (1967). A Bayesian significance test for multinomial distributions. Journal of the Royal Statistical Society: Series B (Methodological), 29(3), 399–418.

    Open DOI reference
  2. Jamil, T., Ly, A., Morey, R. D., Love, J., Marsman, M., & Wagenmakers, E.-J. (2017). Default 'Gunel and Dickey' Bayes factors for contingency tables. Behavior Research Methods, 49(2), 638–652.

    Open DOI reference