Contact

Gnumeric · Statistical analysis · Intermediate

Test a Contingency Table for Independence in Gnumeric

Run Gnumeric's chi-squared independence analysis with numeric counts, correct labels, expected-count checks and an independently checked example.

Gnumeric 1.12.62 released source reviewed; independent arithmetic and headless formula checks; graphical analysis-tool execution pending · Editorial standards

Gnumeric’s Test of Independence analyzes a rectangular table of counts for two categorical variables. It calculates expected counts from the table’s margins and reports a Pearson chi-squared statistic, degrees of freedom, p-value and critical value.

The most important setup detail is Labels: in this tool it removes both the first row and the first column of the selected range. Select only the numeric counts and leave Labels off, or include a complete row-and-column label border and turn it on. Do not include totals in either selection.

Version and verification: This guide follows Gnumeric 1.12.62’s English GTK interface and released calculation source. The worked formulas were independently checked and recalculated with headless ssconvert 1.12.62 on Debian 13 x86-64. The graphical dialog and tool-generated report were not executed. Other versions, platforms and translated labels are not verified. The official manual’s contingency section contains headings without procedural instructions; the steps below are qualified to the released source, not a completed manual walkthrough.

Start with counts, not percentages

For an ordinary independence test, each independently sampled observation contributes to exactly one cell: one category of the row variable and one category of the column variable. Use nonnegative whole-number observed counts, not percentages, category codes, averages or repeated measurements of the same person. Sampling design matters; a spreadsheet cannot establish that observations are independent.

Use at least two numeric rows and two numeric columns, with positive row totals, column totals and grand total. The chi-squared reference distribution is an approximation that needs sufficiently large expected counts. This guide uses every expected count at least 5, matching Gnumeric’s own report-title check. This is a conservative working condition, not a claim that 5 is a universal statistical boundary. NIST’s independence-test reference explains the expected-count calculation and approximation cautions.

Keep blanks, text, Boolean values and formula errors out of the numeric rectangle. A true observed zero is a count, not a missing value, but still check its expected count. Sparse tables, empty categories, structural zeros, weighted surveys and dependent observations need a statistical method appropriate to their design, not an assumption that the dialog fixes them.

Enter a small example

Suppose a fictitious random sample of 60 distinct commuters records residential area and main travel mode. Enter this original example in A1:D3:

Sheet row A: Area B: Bike C: Bus D: Walk
1 Area Bike Bus Walk
2 North 18 9 3
3 South 6 12 12

The observed count rectangle is B2:D3, containing six counts. It represents 60 people, not six observations. The question is whether the two classifications are associated in the sampled population; the null hypothesis is independence.

You can add totals for checking, outside the analysis range:

Cell or range Entry Result
E1 Row total Heading
E2 =SUM(B2:D2) 30
E3 =SUM(B3:D3) 30
A4 Total Label
B4 =SUM(B2:B3); copy right through D4 24, 21, 15
E4 =SUM(E2:E3) 60

Including row 4 or column E in the analysis would treat margins as extra categories. They are checks, not additional observations.

Run the independence tool

  1. Choose Statistics → Multiple Sample Tests → Contingency Table → Test of Independence…. This is a Statistics-menu command, not an Excel-style Analysis ToolPak path. The released menu hierarchy and action labels establish the path.
  2. On Input, set Contingency Table to B2:D3 and leave Labels unchecked. This numeric-only selection is the simplest starting point.
  3. Alternatively, select A1:D3 and check Labels. That removes row 1 and column A, leaving exactly the same six numeric cells. Labels is not a choice to remove only column headings. Do not use B1:D3 with Labels on.
  4. On Options, keep Test of Independence selected and set Alpha to 0.05. Choose the significance level before interpreting the result. The released dialog requires a value strictly between 0 and 1.
  5. On Output, choose New sheet to avoid overwriting the observed table. Select Formulæ if you want the results to recalculate when counts in the existing range change. Values produces a snapshot. The tool enables formula output by default in this release.
  6. Select OK, then compare the result with the independently calculated values below. A fixed input range does not automatically include new category rows or columns; rerun with the revised range when its shape changes.

These controls come from the released contingency dialog, dialog validation and shared output controls.

Check expected counts yourself

For each cell, the independence model gives:

Expected count = row total × column total / grand total.

For North–Bike, that is 30 × 24 / 60 = 12. For North–Bus, it is 30 × 21 / 60 = 10.5. Expected counts may be fractional even though observed counts are whole numbers. Do not round them before calculating the statistic.

On the original input sheet, put =$E2*B$4/$E$4 in B7, then copy across and down to fill B7:D8. The mixed references preserve the appropriate row total, column total and grand total.

Expected counts Bike Bus Walk
North 12 10.5 7.5
South 12 10.5 7.5

The minimum expected count is 7.5. Although one observed count is only 3, it is the expected counts that drive the tool’s warning.

The released report occupies two columns and five rows, including its title. It does not print a separate expected-count table. Its title cell stores the minimum expected count and formats it as Test of Independence when the minimum is at least 5, or Invalid Test of Independence in red when it is below 5. The calculation source still constructs the statistic and tail formulas; the warning is not an exact-test fallback or proof that every assumption was checked. Released report writer.

Verify the statistic and upper tail

Each cell contributes (observed − expected)² / expected. Enter =(B2-B7)^2/B7 in B11, then copy across and down through B11:D12.

Contribution Bike Bus Walk
North 3 3/14 ≈ 0.214285714 2.7
South 3 3/14 ≈ 0.214285714 2.7

Their sum is 414/35 ≈ 11.828571429. With two numeric rows and three numeric columns, degrees of freedom are (2 − 1) × (3 − 1) = 2.

Use these ordinary formulas on the original sheet, separate from the tool output:

Cell Formula Expected result
H2 =SUM(B11:D12) 11.828571429
H3 =(ROWS(B2:D3)-1)*(COLUMNS(B2:D3)-1) 2
H4 =CHIDIST(H2,H3) 0.002700588102
H5 =CHIINV(0.05,H3) 5.991464547108
H6 =MIN(B7:D8) 7.5

The tool’s output labels are Test Statistic, Degrees of Freedom, p-Value and Critical Value, in that order. The table above is a calculation guide, not a captured tool report.

CHIDIST supplies the right-tail probability; CHIINV takes the right-tail probability alpha, not 1-alpha. The released engine calls those functions directly. At exactly two degrees of freedom, a separate mathematical check is p = exp(−statistic/2) and critical value = −2 × ln(0.05). These give the same results without calling either chi-squared function. See the released tail-function definitions.

Here p < 0.05, and equivalently 11.828571429 > 5.991464547108. Reject independence at the chosen 5% significance level under the stated assumptions. This is evidence of association, not proof that residential area causes a particular travel choice. A p-value is a tail probability under the null model, not the probability that independence is true or that this decision is a Type I error. Failing to reject in another example would not prove independence.

Correction and homogeneity boundaries

The 1.12.62 implementation uses the uncorrected Pearson statistic. The complete calculation routine squares observed-minus-expected differences directly. It contains no 2-by-2 branch applying Yates’ continuity correction, and the dialog offers no correction selector. It also does not switch to Fisher’s exact test when expected counts are small. Do not assume another application’s chi-squared defaults will match.

Test of Homogeneity appears beside Independence in the same dialog. In this released engine, changing that choice changes the report labeling, not the expected-count, statistic, degrees-of-freedom or tail formulas. The statistical question and sampling design still differ: comparing categorical distributions across separately sampled populations is not the same design as cross-classifying one sample by two variables. This example covers the latter only; it is not a separate validated homogeneity walkthrough.

Troubleshooting

Symptom Check before interpreting a result
Input range is too small Keep at least a 2-by-2 numeric table after labels are removed. A label-inclusive selection therefore needs at least three rows and three columns. A one-dimensional goodness-of-fit example is not this tool’s input.
Labels changes the result unexpectedly Check that both the first row and first column are labels. Numeric-only B2:D3 needs Labels off; A1:D3 needs it on.
Wrong degrees of freedom Exclude totals, extra numeric columns and headings. Count only the remaining numeric categories.
Red Invalid Test of Independence title Inspect all expected counts, not only the observed counts. Do not treat a displayed p-value as permission to ignore sparse-data concerns or merge categories merely to obtain significance.
Numbers differ from another program Check the same counts, margins, degrees of freedom, upper-tail convention and continuity-correction setting. Compare unrounded values.
Counts changed but output did not Check whether Values was selected instead of Formulæ, and whether the changed cells fall within the original input range.
Zero total, blank, text or an error in the input Stop and resolve the data/model issue. Zero margins give zero expected cells, and a zero grand total makes the expectation formula undefined. The dialog checks range shape, alpha and output readiness, not all statistical validity. Exact GUI error propagation for these cases is not verified here.