SPSS command: SPSS BAYES LOGLINEAR
Bayesian test of independence for contingency tables
The Bayesian test of independence asks whether two categorical variables are associated by comparing an independence model with a model that lets every cell vary.
Free · No account · Files stay on your device · Updated 18 October 2026
What it tells you
Crosstabs runs the SPSS BAYES LOGLINEAR procedure on your device with Gunel–Dickey, Good and Quintana Bayes factors under the sampling model that matches your design, and locates the association with posterior log odds ratios.
- How strongly the table supports an association (BF10) or independence (BF01) between the row and column variables.
- Which cells drive the association: each interaction term is a log odds ratio against the last row and last column.
- Simultaneous credible intervals for those log odds ratios, which hold jointly across all cells.
- Pearson's chi-square and its asymptotic significance for comparison.
When to use it
Use it when
- Two categorical variables, such as plan type by acquisition channel or treatment by outcome category.
- You want evidence for independence, for example that a randomization produced balanced groups.
- Aggregated tables, entered as one row per cell with a count used as a frequency weight.
Use something else when
- More than two classification variables, or loglinear models with selected terms: use hierarchical or general loglinear analysis.
- You need Fisher's exact test, odds ratios with confidence intervals or Cramér's V: use the Crosstabs statistics in Analyze mode.
- Tables larger than 400 cells, which the panel refuses.
How to run it in Crosstabs
- 01
Open your data
Open case-level data, or one row per cell with a count column set as the workspace weight, and switch to Statistics mode.
- 02
Choose the two variables
In the Bayesian statistics group choose Bayesian test of independence, then pick a Row variable and a Column variable (each with at most 20 categories).
- 03
Match the sampling model
Set Sampling model to Multinomial, total fixed; Independent multinomial, row totals fixed; Independent multinomial, column totals fixed; or Poisson (nothing fixed), according to what your design held constant.
- 04
Pick the Bayes factor
Choose Conjugate prior (Gunel & Dickey) with Prior shape a, Mixture of Dirichlet priors (Good), or Nonparametric (Quintana) with λ. Good's mixture is not available for Poisson sampling, and Quintana's factor needs fixed row or column totals with two rows or two columns.
- 05
Run
Set Posterior draws (default 10 000), Seed and Credible interval (%), declare the weight as a frequency weight if it holds cell counts, and press Run Bayesian test of independence.
Worked example
Computed by the Crosstabs engine from the synthetic data below when this page was built — not typed in.
Data
A synthetic survey of 206 customers cross-classified by billing plan (1 = monthly, 2 = annual) and acquisition channel (1 = search, 2 = referral, 3 = social). The six cell counts are the input, entered as a frequency weight n.
Input preview
| plan | Search | Referral | Social | Total |
|---|---|---|---|---|
| Monthly | 34 | 41 | 25 | 100 |
| Annual | 22 | 38 | 46 | 106 |
| Total | 56 | 79 | 71 | 206 |
| Sampling model | BF01 | BF10 | Pearson chi-square | df | Asymp. Sig. |
|---|---|---|---|---|---|
| Multinomial, total fixed | 0.155 | 6.431 | 8.729 | 2 | .013 |
Gunel & Dickey (1974) natural-conjugate Bayes factor, prior shape a = 1 for every cell.
| plan | channel | Posterior mean | Posterior SD | 95% simultaneous lower | 95% simultaneous upper |
|---|---|---|---|---|---|
| Monthly | Search | 1.028 | 0.366 | 0.237 | 1.830 |
| Monthly | Referral | 0.676 | 0.333 | −0.051 | 1.436 |
Log odds ratio of each cell against the last row (annual) and last column (social); Dirichlet(1) prior; intervals from 10,000 draws, seed 2000000.
How to read it
Pearson's χ²(2) = 8.73, p = .013. The Gunel–Dickey Bayes factor under joint multinomial sampling gives moderate evidence for the alternative (BF10 = 6.431) for an association between plan and channel. The interaction table locates it: for Monthly × Search the posterior log odds ratio is 1.028, and its simultaneous interval (0.237 to 1.830) excludes 0.
Output tables explained
- Row × Column Crosstabulation
- Titled with the two variable names: the observed (weighted) counts of every cell with row and column totals.
- Bayes Factor Test of Independence
- The sampling model, BF01 and BF10, Pearson chi-square, df and asymptotic significance; footnotes name the Bayes factor and explain when it cannot be estimated.
- Posterior Distribution of Interaction Terms (log odds ratios)
- For every cell except the last row and column: exact posterior mean and SD of the log odds ratio under a Dirichlet(1) prior, and simultaneous credible bounds from seeded posterior draws. An interval that excludes 0 marks association in that cell.
Assumptions and notes
- Each case falls in exactly one cell, and cases are independent.
- The sampling model reflects the design: fixed row totals for stratified samples, a fixed grand total for a single random sample, nothing fixed for counts collected over a period.
- A weight used for cell counts must hold whole numbers; sampling weights are refused.
How the results are validated
On 2 × 2, 2 × 3 and 3 × 3 reference tables, the Gunel–Dickey factor matches R BayesFactor 0.9.12.4.8 contingencyTableBF(priorConcentration = 1) to a relative 1e-9 and the Python reference to 1e-10 under all four sampling models; Good's mixture matches to 1e-8 and Quintana's factor to 1e-12. Interaction posterior means match to 1e-12 and SDs to 1e-10, cross-checked against 200 000 NumPy Monte Carlo draws within 0.01. Validation evidence
Questions
Which sampling model should I choose?
Use the one that matches how the data were collected: a fixed total sample size for most surveys, fixed row totals when you sampled a set number per row group, Poisson when nothing was fixed in advance. The Bayes factor changes with the model.
Why is the interaction table random?
The posterior means and SDs are exact. Only the simultaneous interval bounds come from posterior draws; they are reproducible because the Seed is fixed, and more draws make them more stable.
Can I enter a summary table instead of raw data?
Yes. Put one row per cell with the row code, column code and count, set the count as the workspace weight, and declare it as a frequency weight in the panel.
Why does it say the Bayes factor cannot be estimated?
Either a prior component is too small for the conjugate factor, or Quintana's factor was requested for a table that does not have two rows with fixed row totals (or two columns with fixed column totals).
Related procedures
- Crosstabs StatisticsCROSSTABS /STATISTICS
- Hierarchical Loglinear AnalysisHILOGLINEAR
- General Loglinear AnalysisGENLOG
- ProportionsPROPORTIONS
- Bayesian Independent SamplesBAYES INDEPENDENT
- Free SPSS alternative: full coverage list
Run Bayesian Test of Independence on your own data
Open a .sav, CSV or Excel file. Everything runs in your browser; the file never leaves your device.
SPSS is a trademark of IBM Corp. Crosstabs is not affiliated with or endorsed by IBM.