Goodness-of-fit test

Chi-square goodness-of-fit from counts or a column

A goodness-of-fit test asks a simple question: do the counts I observed match the counts I expected? Magic Stat computes both the Pearson chi-square and the likelihood-ratio G, with the per-category residuals, and lets you supply the expectation in three different ways.

The honest part

One variable, one set of expected counts

The test compares a single categorical variable's observed counts with expected counts under a hypothesis. Pearson's statistic is χ² = Σ (o−e)²/e; the likelihood-ratio G is G = 2·Σ o·ln(o/e), with 0·ln 0 taken as 0. Both have k−1 degrees of freedom. They usually agree; when they diverge, the divergence itself is informative, so Magic Stat reports both rather than choosing for you.

The expectation can be uniform (every category equally likely), a set of custom proportions, a set of expected counts, or — the case that saves the most time — an already-computed expected column in your spreadsheet, one row per cell, so you compare observed against a column you did not have to type in.

This is a one-variable test. If your question is whether two categorical variables are associated, that is a contingency table, and it lives elsewhere in the app. Using a goodness-of-fit test for that question would be a category error.

What it does

What Magic Stat gives you for goodness-of-fit

How it works

From counts to observed versus expected

  1. Choose the input tab. a categorical column, manual counts, or two numeric columns (observed and expected).
  2. Set the expectation. equal, custom proportions, custom counts, or an expected column.
  3. Run the active tab. both the Pearson χ² and the G statistic are computed.
  4. Read the diagnostics. check the minimum expected count and the cells-below-5 note before trusting the p.
  5. Inspect the categories. the contributions and standardized residuals show which categories depart from the expectation; export the table and the report.
Options

The settings, out in the open

Input modes: From column · Manual entry (optional category labels) · Two columns (observed × expected).

Expected under H0: equal proportions · custom proportions · custom expected counts.

Statistics: Pearson χ² and likelihood-ratio G, both with df = k−1.

Parity note: the χ² follows R's chisq.test without a continuity correction (which does not apply to the one-variable test), and the G follows the uncorrected G = 2·Σ o·ln(o/e).

Frequently asked

Goodness-of-fit questions, answered honestly

When do I need the G-test as well?

You do not always. It answers the same question with a different statistic, and with healthy counts the two agree closely. It is worth reporting when the counts are small or when a reviewer expects the likelihood-ratio version; having both is cheap.

Can the expected counts come from another column?

Yes — that is the third input mode. Give an observed column and an expected column, one row per cell; if the expected counts do not sum to the observed total they are rescaled to it (as R's chisq.test does with p = e/Σe) and a note appears.

What if a category has zero expected count?

Then G is infinite for that category (you cannot compute o·ln(o/0)) and the standardized residual is undefined. The app reports that honestly instead of substituting a number.

Goodness-of-fit or a contingency table?

Goodness-of-fit is for one categorical variable against an expectation. To test whether two categorical variables are associated, use the contingency table analysis — those are different questions and different tests.

Does it store my counts anywhere?

No. The calculation runs locally; the only signal sent is an anonymous installation counter.

Contingency tables → Log-linear models → Multinomial logistic regression →