Chi-Square Goodness of Fit

Tests counts against expected counts with the Pearson chi-square statistic.

Key facts

What it does
Tests counts against expected counts with the Pearson chi-square statistic.
Formula
χ² = Σ(O−E)²/E; df = categories − 1.
You enter
Observed counts · Expected counts
Worked example
χ² = 3.3333 with df = 2.

A clearer path to an answer

From your question to a useful result

This page keeps the calculation transparent: define the goal, enter the matching values, inspect the method, and decide what the result means in your situation.

01

Goal

Tests counts against expected counts with the Pearson chi-square statistic.

02

Inputs

Observed counts · Expected counts

03

Method

χ² = Σ(O−E)²/E; df = categories − 1.

04

Next step

Calculate, review the assumptions below, then compare a related tool when the decision needs more context.

Chi-Square Goodness of Fit

Tests counts against expected counts with the Pearson chi-square statistic.

Comma-separated, same count as expected.

Comma-separated, every value positive.

Result

Enter your values above and choose Calculate to see the result here.

Calculation map

Follow the path from input to answer

Ready to calculate
01

Inputs (2)

  • Observed counts Ready
  • Expected counts Ready
02

Formula

χ² = Σ(O−E)²/E; df = categories − 1.

Bounded, transparent calculation

03

Result

  • Calculate to preview the result.
This diagram mirrors the calculator contract. It summarizes the declared inputs, formula, and returned outputs; it does not add a forecast or professional advice.

Recent runs

Your recent runs stay in this browser session only.

Formula, assumptions, and example

Formula: χ² = Σ(O−E)²/E; df = categories − 1.

Sums squared standardized residuals across categories. Larger values signal worse fit at df = categories − 1.

  • Independent counts with matching observed/expected categories.
  • Every expected count positive (5+ preferred); at least 2 categories.

Worked example: χ² = 3.3333 with df = 2.

Displayed input contract

  • Observed counts
  • Expected counts

The displayed limits are checked before the handler runs. Model-specific domain checks may also reject impossible or non-finite inputs.

Methodology: This calculator follows the WorldCalculate input, formula, precision, and boundary policy. Read the official methodology.

Calculator usage statistics

Usage of this calculator and related tools

This section counts anonymous successful Calculate submissions, not unique visitors. Counts and top tools appear only when trusted aggregate data is available; country analysis is shown only under the same condition and reporting threshold.

Waiting for trusted aggregate usage data.

Answer-first guide

How to use the Chi-Square Goodness of Fit for a real question

Tests counts against expected counts with the Pearson chi-square statistic. Start with one clearly defined goal, enter values in the units shown, and keep the result attached to the assumptions below.

What this answers

This tool is useful when your question includes chi-square, goodness of fit, observed expected. It returns the outputs declared in the calculator contract rather than a live quote, approval, diagnosis, or professional sign-off.

What you enter

Observed counts · Expected counts. Keep the same time period, unit system, and currency wherever the form requires comparable values.

How to check it

Run the worked example first, compare its output with the page's example, then change one input at a time. This makes an unexpected result easier to trace to a unit, boundary, or assumption.

Three checks before you rely on the answer

  1. Match the question. Confirm that the result means the quantity you need, not a similar-sounding percentage, balance, rate, or estimate.
  2. Match the inputs. Use the requested units and period, and read each hint before replacing the example values with your own.
  3. Read the boundary. Review the assumptions and limits. Independent counts with matching observed/expected categories.

Need a wider view? Browse Statistics Calculators or compare the related tools below. The WorldCalculate methodology explains how formulas, examples, limits, and revisions are reviewed.

How to use the Chi-Square Goodness of Fit

  1. Enter Observed counts — Comma-separated, same count as expected.
  2. Enter Expected counts — Comma-separated, every value positive.
  3. Choose Calculate and read the result panel.
  4. Use Download PDF or Download Word to save a result sheet.

Formula

χ² = Σ(O−E)²/E; df = categories − 1.

Sums squared standardized residuals across categories. Larger values signal worse fit at df = categories − 1.

Worked example

χ² = 3.3333 with df = 2.

Assumptions and limits

  • Independent counts with matching observed/expected categories.
  • Every expected count positive (5+ preferred); at least 2 categories.

Context and background

How statistical calculations should be interpreted

Statistics tools describe data or evaluate a stated probability model. They do not turn an observed summary into causation, certainty, or a forecast without additional evidence.

Data analysis developed from summaries of observations into probability, estimation, and decision measures. The essential habit remains the same: define the population, sample, variable, and convention before calculating.

Research and review

How this guide was researched

Researched by , Founder and editorial researcher at WorldCalculate.

This guide follows the live calculator's declared inputs, formula, worked example, assumptions, validation boundaries, and source-backed methodology. The review date describes editorial review of the calculator explanation; it is not a promise that external facts or rates remain current.

Read the WorldCalculate research and methodology policy

WorldCalculate visual connecting observations, weights, average, spread, confidence interval, evidence, and interpretation for Chi-Square Goodness of Fit
A statistic is easier to interpret when the observations, weights, spread, uncertainty, and question stay connected. An original statistics visual showing how observations become summaries, uncertainty ranges, evidence comparisons, and cautious interpretation. WorldCalculate original artwork; watermark included.

A chi-square goodness-of-fit calculation asks whether observed counts in one categorical variable are reasonably consistent with a specified set of expected counts. The categories might be outcomes of a die, response choices on a survey, defect types in a production sample, or any other mutually exclusive labels. The observed list records what happened. The expected list records what a proposed distribution predicts for the same categories and usually the same total number of observations. The calculation uses chi-square = sum((O-E)^2/E), where O is observed and E is expected for one category, and it reports degrees of freedom as categories - 1. This calculator is deliberately small and transparent: it parses two comma-separated count lists, checks their basic numeric contract, calculates one contribution per category, sums them, and returns the fixed degrees-of-freedom rule. It does not choose the expected model, calculate a p-value, or decide whether a scientific or practical claim is justified. The guide below explains how to frame the test, prepare the lists, derive the statistic, inspect contributions, handle assumptions and precision, and decide what additional analysis is needed.

Small WorldCalculate visual showing data moving through average, spread, interval, evidence, and interpretation for Chi-Square Goodness of Fit
The result describes the entered data and model; interpretation still depends on the study question. Compact statistics visual distinguishing calculation from the conclusion drawn from evidence. WorldCalculate original artwork; watermark included.

Start with the goodness-of-fit question

A goodness-of-fit question compares one observed categorical distribution with one distribution stated in advance. Let the null hypothesis say that the category probabilities follow the proposed pattern. The expected counts are the counts that pattern would produce for the sample size at hand. The alternative hypothesis says that at least one category probability differs from the proposal. The test is about the whole distribution, not just whether one selected category is high or low.

The expected pattern can come from a physical law, a design specification, a claimed ratio, a historical baseline, a policy allocation, or a simple benchmark such as equal probabilities. The origin matters because it supplies the meaning of a disagreement. A statistic can be large because the model is wrong, because the sample is unusual, because the categories were defined poorly, or because the observations are dependent. The arithmetic cannot identify which explanation is responsible.

This procedure is for a single categorical variable. A flat observed list such as one count for each color does not contain the row and column structure needed to ask whether two categorical variables are associated. A contingency-table independence or homogeneity analysis is a different question with a different expected-count calculation and usually different degrees of freedom. Treating every chi-square expression as a goodness-of-fit test can produce a numerically neat but conceptually wrong result.

Before entering numbers, write the question in one sentence. State the variable, the categories, the proposed probabilities or counts, the sample size, and what would count as evidence against the proposal. If that sentence is unclear, the lists are not ready. A clear question also prevents changing the expected distribution after seeing the observed results merely to make the fit look better.

  • Null hypothesis: the observed category probabilities follow the specified expected distribution.
  • Alternative hypothesis: at least one category probability differs from that distribution.
  • The test concerns one categorical variable and all of its listed categories together.
  • A large statistic is evidence of discrepancy, not an explanation for the discrepancy.

Observed and expected categories must match

An observed count O_i is the number of sampled outcomes assigned to category i. An expected count E_i is the count predicted for that same category under the null model. The subscript is important: category 1 in the observed list must correspond to category 1 in the expected list, category 2 to category 2, and so on. The calculator has no category-label field, so list position is the only identity it can use.

Suppose the categories are red, blue, and green. The input observed = 12, 18, 10 and expected = 13, 15, 12 is meaningful only if both lists use exactly that order. Reordering one list changes every comparison while leaving the numbers themselves unchanged. A safe preparation habit is to make a small labeled table outside the calculator, sort neither list independently, and copy the rows from top to bottom into both fields.

Categories should normally be mutually exclusive and collectively exhaustive for the observations being analyzed. Each observation should contribute to one and only one listed category. If an outcome can belong to several categories, if some outcomes were discarded, or if an unclassified group was omitted, the observed total no longer represents the population described by the expected model. Add a defensible residual category or redesign the analysis rather than hiding the missing outcomes.

Expected counts are often built from expected probabilities. If the total observed sample size is N and the null probabilities are p_1 through p_k, then E_i = N times p_i. The expected probabilities should add to one, apart from harmless numerical rounding, so the expected counts add to N. An observed zero is allowed by this handler and can be meaningful. An expected zero is not allowed because the formula would divide by zero and because a structural-zero model needs separate reasoning.

  • Keep the same category order in both fields; the calculator cannot see category names.
  • Use mutually exclusive and exhaustive categories for the population being described.
  • For probabilities p_i and total N, construct each expected count as N times p_i.
  • Observed zero can be valid; an expected zero violates this calculator's contract.

Parsing and validation contract

Both fields are text fields intended for comma-separated numbers. The parser trims the overall input and splits on one or more commas or whitespace characters, so a value such as 10, 20, 30 and a value separated by spaces are read as the same three numeric tokens. Commas make the category boundaries easiest for a human to inspect. A blank field, an empty field, or a field containing no number is rejected before any statistic is computed.

Each token must be a complete decimal-style number. Signed values, decimal points, and scientific notation are accepted when they form a complete token, but arithmetic expressions, labels, currency marks, percent signs, and words are not expressions the parser evaluates. Values must be finite and within -1e12 through 1e12 before the category-specific checks are applied. The parser also limits each text field to 32,000 characters and each list to 1,000 numbers so accidental pastes cannot create an unbounded calculation.

The two parsed lists must have the same length, and that length must be at least two. Expected values must be strictly positive. Observed values must be zero or greater. The field accepts numeric decimals even though ordinary counts are integers; this is a property of the generic numeric parser, not a claim that fractional people or fractional physical events form a standard multinomial sample. A fractional entry can be appropriate for a weighted or normalized analysis only when the method behind that analysis supports it and the interpretation is documented.

The validator checks syntax, finite numeric range, list length, signs, and positivity. It does not verify category labels, total equality, probability normalization, integer status, random sampling, independence, or whether the expected values were chosen before the data. It also does not enforce the preferred 5+ expected-count guideline. Very small positive expected values can pass the positivity check but make the quotient numerically unstable or too large; the result guard rejects a nonfinite final statistic rather than silently replacing the input.

A validation error is useful information about the input contract, not evidence against the goodness-of-fit hypothesis. Fix the data preparation and rerun the calculation. Do not repair a missing token by inserting zero, do not move a value to a different position to satisfy the length check, and do not replace an invalid expected zero with a tiny arbitrary number merely to obtain an output. Those changes alter the analysis.

  • Use comma-separated lists with matching positions; commas or whitespace separate tokens.
  • Tokens must be complete finite numbers, not formulas or text with units attached.
  • Each list is bounded at 32,000 characters and 1,000 numbers.
  • Observed values are nonnegative; expected values are strictly positive.
  • The handler does not check that totals, probabilities, labels, or sampling design are appropriate.

Choose and check the expected counts

The expected list is a model, not a second measurement of the same event. It should be derived from the claim being examined. For a fair six-outcome device, equal expected probabilities produce six equal expected counts. For a known allocation ratio, multiply the total sample size by each ratio after normalizing the ratios to probabilities. For a historical reference, define which population and time period make the reference relevant before converting it to counts.

Check the expected total before entry. In the usual fixed-total goodness-of-fit setting, the expected counts should sum to the observed total N. If the proposed probabilities are p_i, the construction E_i = N times p_i guarantees this when the probabilities sum to one. If the expected values sum to a different total because they came from a forecast, exposure adjustment, or a separate data source, the formula can still produce a descriptive discrepancy, but the standard p-value interpretation and the df rule may no longer apply without a model that explains the different total.

Round expected counts only after they have been derived, and inspect the effect of that rounding. Small changes can matter when one expected value is small or when several categories are near their observed values. If rounded expected counts no longer have the intended total, decide whether the analysis should use unrounded values, a controlled rescaling, or a different method. Do not make a quiet correction after looking at the statistic.

If expected counts depend on parameters estimated from the observed sample, record that fact. Fitting a mean, a probability, or another parameter uses information from the data and consumes degrees of freedom in the corresponding inferential test. This calculator deliberately applies categories - 1, so its output should not be presented as a fully adjusted test when fitted parameters require a correction.

  • Derive expected values from a declared null model or reference rule.
  • In the ordinary fixed-total setting, make expected and observed totals agree at N.
  • Prefer unrounded expected counts for the calculation and document any rounding.
  • Mark clearly whether any expected parameters were estimated from the same observations.

Deriving the chi-square statistic

For one category, the raw discrepancy is O_i - E_i. A discrepancy of -5 and a discrepancy of +5 are equally far from expectation, so the method squares the difference. The squared discrepancy is then divided by E_i, giving the category contribution (O_i - E_i)^2 / E_i. The denominator puts differences on a scale related to the amount of variation expected in a count of that size; it also means that the same raw difference can matter more when the expected count is smaller.

The expression can be understood through a standardized residual. Define r_i = (O_i - E_i) divided by the square root of E_i. Squaring that residual gives r_i^2 = (O_i - E_i)^2 / E_i. Adding all category contributions produces chi-square = sum((O-E)^2/E). Every contribution is nonnegative, so the statistic is nonnegative. It is zero only when every observed count equals its expected count exactly.

The formula does not add raw differences because positive and negative deviations would cancel. It also does not divide by the observed count, because the null model supplies the reference scale. Using O in the denominator answers a different question and can behave badly for an observed zero. The order of the subtraction does not affect the total after squaring, but retaining the signed residual is useful when diagnosing which categories are overrepresented or underrepresented.

The calculator computes every contribution from the entered pair, sums the contributions, and reports the resulting statistic. It also exposes a breakdown so the total can be checked. That breakdown is arithmetic evidence: it shows which categories contribute most to the discrepancy. It is not, by itself, a collection of separate hypothesis tests for the individual categories.

  • Category discrepancy: O_i - E_i.
  • Category contribution: (O_i - E_i)^2 / E_i.
  • Total statistic: sum of all category contributions.
  • A signed residual identifies direction; its square determines the contribution.

Why the degrees of freedom are categories minus one

If there are k categories and the sample total is fixed at N, the counts cannot vary independently in all k directions. Once k - 1 counts are known, the final count is determined by the total. This single sum constraint removes one free dimension, leaving k - 1 degrees of freedom. The same constraint is why observed cell counts in a multinomial sample are not literally independent of one another even though the observations that generated them can be independent.

For three categories, the output is df = 2. If the first two category counts change while the total stays fixed, the third must compensate. For six categories, the output is df = 5. Combining two categories reduces k and therefore changes the degrees of freedom; splitting one category increases k only if the split is scientifically defined before interpreting the result.

The handler always reports categories - 1. That is the stated contract for fixed expected counts. In a more general goodness-of-fit test, parameters estimated from the observations reduce the usable degrees of freedom further. If q independent parameters were fitted under the null model, a common adjusted expression is k - 1 - q, provided the assumptions and estimation procedure support that expression. The calculator does not know q and cannot make that adjustment.

Degrees of freedom are not a measure of sample quality and are not the number of categories that differ. They identify the reference chi-square distribution used when a p-value is computed under the stated model. A correct df value cannot rescue mismatched categories, sparse expected counts, dependent observations, or a model selected after inspecting the data.

  • With k categories and one fixed-total constraint, df = k - 1.
  • The calculator uses df = categories - 1 for every accepted input.
  • Estimated null parameters can require additional df adjustments outside this page.
  • Changing category definitions changes both the statistic and the degrees of freedom.

Default worked example

The default lists are observed = 10, 20, 30 and expected = 15, 15, 30. There are three categories, and both totals are 60, so the fixed-total setup is internally consistent. Category 1 is five below expectation, category 2 is five above expectation, and category 3 matches expectation exactly. The signs differ, but the two five-count deviations should both contribute evidence of discrepancy rather than cancel.

For category 1, the contribution is (10 - 15)^2 / 15 = 25 / 15 = 1.6667 when displayed to four decimal places. For category 2, the contribution is (20 - 15)^2 / 15 = 25 / 15 = 1.6667. For category 3, the contribution is (30 - 30)^2 / 30 = 0. Adding them gives chi-square = 1.6667 + 1.6667 + 0 = 3.3333, subject to display rounding.

The degrees of freedom are 3 - 1 = 2. The output therefore reads chi-square = 3.3333 with df = 2. The statistic says that the observed list has a measurable discrepancy from the expected list, with the first two categories supplying all of the displayed contribution. It does not yet say whether that discrepancy is unusual enough to reject the proposed distribution.

For orientation only, if the fixed expected model and the sampling assumptions are appropriate, the upper-tail probability for a chi-square value of 3.3333 with 2 degrees of freedom is about 0.189. That probability is not calculated by this handler; it is an additional inferential step. The example illustrates why a statistic and a decision should be reported separately.

  • Observed total = expected total = 60.
  • Contributions = 1.6667, 1.6667, and 0.0000.
  • Total chi-square = 3.3333 before or after ordinary display rounding.
  • Degrees of freedom = 2; any p-value requires a separate upper-tail calculation.

Additional worked examples

Consider four categories with observed counts 18, 12, 20, 10 and equal expected counts 15, 15, 15, 15. Both totals are 60. The contributions are 9/15 = 0.6000, 9/15 = 0.6000, 25/15 = 1.6667, and 25/15 = 1.6667. The total is 4.5333 with df = 4 - 1 = 3. The last two categories account for most of the discrepancy because their deviations are five rather than three counts in magnitude.

Now use a three-category model with observed counts 50, 30, 20 and expected counts 45, 35, 20. The contributions are 25/45 = 0.5556, 25/35 = 0.7143, and 0. The total is about 1.2698 with df = 2. This is a useful reminder that two nonzero deviations can be modest even when the raw counts look different. The denominator and the total sample size determine the scale of the comparison.

An observed zero is valid when the expected count is positive. For observed 0, 12, 18 and expected 5, 10, 15, the contributions are 25/5 = 5, 4/10 = 0.4, and 9/15 = 0.6. The statistic is 6 with df = 2. The zero contributes strongly because an outcome predicted to occur five times did not occur. Whether that is surprising enough for a decision still depends on the reference distribution and the planned threshold.

For a fair six-outcome experiment with 60 trials, the expected list is six values of 10. If the observed list is 18, 14, 9, 11, 8, 10, the contributions are 6.4, 1.6, 0.1, 0.1, 0.4, and 0, giving a total of 8.6 and df = 5. The first category dominates. That pattern may prompt a check of the equipment, recording, or category definition, but a contribution ranking alone does not establish a cause.

  • Equal expected counts make uniform-distribution examples easy to audit.
  • A zero observed count can be valid when its expected count is positive.
  • Large raw differences do not have a fixed meaning without their expected scale.
  • A dominant contribution is a diagnostic lead, not an automatic category-level verdict.

Expected-count conditions and sparse categories

The formula requires every E_i to be positive, which is why the handler rejects an expected zero. For an inferential chi-square approximation, expected counts should also be large enough that the reference distribution is a reasonable approximation to the true sampling distribution. A common planning preference is at least 5 in every category. The 5+ guideline is not a magical boundary, but it is a useful warning signal that the ordinary approximation may be unreliable when it is violated.

Sparse expected counts cause two related problems. First, the denominator makes a small absolute discrepancy produce a large contribution. Second, the continuous chi-square reference distribution may not describe the discrete count outcomes well. A category with an expected count of 0.2 is not made safe by entering 0.2 instead of zero. It remains a sparse category with a fragile contribution and a model that needs review.

If categories are substantively similar, combining them before the analysis can increase expected counts, but the grouping rule should come from the subject matter rather than from the observed result. Combining only the categories that look inconvenient changes the question and can hide the very departure being studied. If rare categories are scientifically essential, retain them and use a method designed for sparse data instead of forcing the preferred approximation.

Exact multinomial calculations, conditional methods, or simulation-based reference distributions can be better choices for small samples. These alternatives still require a defensible null model and category mapping. A different method is not a license to ignore structural zeros, missing outcomes, or dependent observations; it only changes how sampling variability is represented.

  • Every expected count must be greater than zero for this calculator.
  • Expected counts of 5 or more are preferred as a practical approximation check.
  • Do not insert an arbitrary tiny expected value to bypass a structural zero.
  • Merge sparse categories only when the grouping is substantively justified.

Independence and sampling assumptions

The usual independence assumption concerns the observations that produced the counts. Each trial, person, item, or event should contribute an outcome without its category being determined by another observation in the sample. The category totals themselves must add to a fixed N and therefore are mathematically linked; calling the observations independent does not mean the final cell counts are free to vary independently.

A random or otherwise defensible sampling process is also important. If the sample is a convenience group, a single time window, a biased collection source, or a deliberately selected set of cases, a small p-value may describe that selection process rather than a general population. A representative sample is not guaranteed by a large sample size. Document who or what could enter the sample and how each outcome was assigned.

Repeated measurements from the same person, multiple items from one batch, households sampled together, sites sharing a common environment, time-series observations, and clustered survey designs can create dependence. In those settings, a flat count comparison can understate or misrepresent uncertainty. A cluster-aware, repeated-measures, hierarchical, or resampling approach may be needed, depending on the design.

Weights and adjustments require special care. A weighted total can be useful for estimation, but fractional weighted counts do not automatically have the same sampling distribution as raw multinomial counts. If exposure differs across categories, the expected model may need offsets or rate comparisons rather than simple counts. The calculator can evaluate the entered arithmetic, but it cannot recognize whether the data-generating design supports the chi-square reference distribution.

  • Independence refers primarily to the observations or trials that generated the counts.
  • Use a random or well-justified sampling process for population-level claims.
  • Clustered, repeated, time-dependent, or batch-dependent observations need design-aware methods.
  • Weighted or fractional counts require a sampling model that justifies their use.

Statistic, p-value, and decision are different

The chi-square statistic is a distance-like summary of the observed counts from the expected counts. A p-value is a tail probability calculated under the null model and a specified degrees-of-freedom reference distribution. For a goodness-of-fit statistic, the relevant tail is normally the upper tail: values at least as large as the one observed. The p-value therefore requires more than the two lists. It requires a valid null model, an appropriate df, and a method for evaluating the reference distribution.

A decision rule should be chosen before interpreting the result. With a stated significance level alpha, one common rule rejects the null when the p-value is at most alpha and otherwise reports failure to reject. Failure to reject does not prove the expected distribution is true. It means the sample did not provide enough evidence against it under the chosen model, design, and threshold. A small p-value also does not prove that the model is the only possible explanation for the data.

Statistical significance and practical importance can diverge. With a very large sample, a tiny departure from an expected ratio can generate a large statistic and a small p-value. With a small sample, a meaningful departure can remain uncertain. Report the counts, expected model, statistic, df, p-value if separately computed, decision rule, and an effect description rather than reducing the analysis to a binary label.

The chi-square distribution has no negative tail for this statistic. A category being below expectation does not create a lower-tail goodness-of-fit test; its squared contribution is already part of the two-sided discrepancy measure. If the substantive question is specifically whether one category is lower or higher, a planned directional analysis may be more suitable than changing the interpretation of the omnibus statistic.

Do not interpret a p-value as the probability that the null hypothesis is true, the probability that the observed data were caused by chance, or the size of the discrepancy. It is conditional on the null model and sampling procedure. If categories, the expected rule, or the stopping point were chosen after inspecting the data, the nominal p-value can be optimistic and should not be reported without that selection context.

  • Statistic: the calculated discrepancy between observed and expected counts.
  • P-value: an upper-tail probability under an appropriate null reference distribution.
  • Decision: a rule comparing the p-value with a preselected alpha, when a test is justified.
  • Neither a small p-value nor a large one replaces effect, design, or practical interpretation.

Read the residual contributions

The breakdown is one of the most useful outputs because it shows how the total was assembled. A contribution near zero means that the category is close to its expected count relative to its expected scale. A large contribution means that the category is influential in the omnibus discrepancy. To recover direction, inspect the signed difference O_i - E_i or the signed standardized residual (O_i - E_i) divided by the square root of E_i.

A positive residual means overrepresentation: more observations occurred than the model predicted. A negative residual means underrepresentation. In the default example, category 1 is under by five and category 2 is over by five, and both contributions are 1.6667 because their expected counts are equal. If the expected counts differed, equal raw deviations would not necessarily produce equal contributions.

You can compute each contribution's share of the total as its contribution divided by chi-square when the total is positive. That is a descriptive way to prioritize review. It is not a probability that the category is responsible for the model failure, and it is not a category-level p-value. Looking at many residuals and selecting the most extreme one creates a multiple-comparison issue that needs a planned adjustment or a separate exploratory label.

Residual review should include the raw records or a labeled summary. A high contribution may reveal a recording error, a category with unclear rules, an omitted exposure difference, or a real departure. The calculator reports numbers without labels, so attach category names and data-quality notes outside the input fields before drawing a substantive conclusion.

  • Contribution magnitude shows which category affects the total most.
  • Signed residual direction distinguishes overrepresentation from underrepresentation.
  • Contribution shares are descriptive and are not individual category p-values.
  • Review the underlying records before explaining a large residual.

Rounding, precision, and numerical scale

Use the most precise defensible values when constructing expected counts and retain unrounded values through the calculation. Rounding each expected count separately can change the total, and rounding both observed and expected values can change small differences disproportionately. The effect is especially visible when O_i and E_i are close, because the test depends on their subtraction, or when E_i is small, because the denominator magnifies the result.

The handler calculates with the entered JavaScript numeric values and displays the chi-square result to four decimal places. Contributions in the breakdown are also formatted to four decimal places, while degrees of freedom is displayed as an integer. The displayed contributions may not add exactly to the displayed total because each component was rounded for presentation after the total was calculated. Use the underlying inputs and unrounded arithmetic when a reconciliation needs more precision.

If the source data are only known to whole counts, do not report a long decimal as if it were highly accurate. If expected values are fractional because they come from probabilities, that is normal, but the probability model and total should be retained. If observed values are fractional weights, state that they are weighted values and confirm that the chosen inferential method supports them rather than assuming that parser acceptance proves validity.

The numeric bounds are broad, but broad bounds are not a recommendation. A very large observed value paired with a nearly equal expected value can lose meaningful digits in subtraction. An extremely small positive expected value can make a contribution overflow even though it passes the positivity test. If the result is too large to calculate, revisit units, scaling, category construction, and the expected model; do not replace a value silently.

  • Calculate from unrounded defensible values whenever possible.
  • Four displayed decimal places are formatting, not an uncertainty estimate.
  • Keep expected and observed totals aligned after any deliberate rounding or scaling.
  • Do not infer data quality from the number of digits shown in the result.

Common mistakes to avoid

The most damaging mistake is comparing the wrong pairs. If the expected order does not match the observed order, every contribution is attached to the wrong category. The next common error is using the wrong denominator or forgetting to square the difference. Write one row as (O_i - E_i)^2 divided by E_i before summing, and check that an exact match contributes zero.

Another error is treating the expected list as optional decoration. Expected counts encode the null hypothesis. Entering observed counts in both fields tests exact self-agreement and always returns zero, but it does not test a meaningful external claim. Similarly, entering percentages without converting them to expected counts can create a mismatch between a probability scale and a count scale.

Users also often use the wrong degrees of freedom, especially when they count categories rather than subtract one. Or they apply this one-variable calculation to a two-way table by flattening the table, which discards the row and column structure. A correct formula applied to the wrong design is still the wrong analysis.

Finally, avoid turning an exploratory result into a causal or operational decision. A large statistic can be caused by dependence, biased sampling, category changes, recording errors, or a reasonable but imprecise model. A small statistic can coexist with a practically important difference when the sample is small. Keep the inferential language proportional to what the data and design establish.

  • Do not reorder one list independently of the other.
  • Do not use O as the denominator, omit the square, or add raw signed differences.
  • Do not enter percentages or probabilities where expected counts are required without scaling them.
  • Do not use df = categories, or flatten a contingency table into one list.
  • Do not treat fail to reject as proof, or a large statistic as a cause.

Alternatives and limitations

The ordinary chi-square approximation is attractive because it is simple, fast, and easy to audit, but it is not universal. For very small samples or sparse expected counts, an exact multinomial calculation can represent the discrete sampling space more directly. A conditional or permutation-style procedure may be useful when the design provides a natural way to generate samples under the null. A simulation-based reference distribution can also help when an exact calculation is difficult, provided the simulation preserves the relevant design.

A likelihood-ratio goodness-of-fit statistic is another large-sample alternative. It compares observed counts with expected counts using logarithmic terms rather than squared differences. It may behave differently in finite samples, especially with sparse cells, and it should not be substituted casually while retaining the same interpretation and cutoffs. For two categories, a binomial test may be more direct. For several categories with estimated parameters, a fitted multinomial or other model can make the parameter and df accounting explicit.

The calculator is limited to a single pair of flat lists. It has no category labels, no data table, no missing-value handling beyond token validation, no exposure field, no sampling weights, no parameter-fitting step, no exact reference distribution, and no p-value field. It cannot compare repeated samples, model trend across ordered categories, test association between variables, or diagnose which record caused a residual.

A method choice should follow the data-generating process. Ordered categories may call for a trend analysis. Dependent observations may call for a clustered model. Rates with unequal exposure may require a different denominator. A table with two categorical dimensions needs an independence or homogeneity framework. An exact or simulated method may be preferable when expected counts are small. The output of this calculator is still useful as a transparent descriptive statistic, but its inferential role depends on those choices.

  • Exact or conditional methods can be preferable for small or sparse samples.
  • Simulation can approximate a null reference when the design is simulated honestly.
  • Likelihood-ratio and binomial procedures answer related but not identical questions.
  • Use a design-aware model for order, exposure, clustering, repeated measures, or two-variable tables.

What the calculator does not decide

The calculator does not decide what the categories mean or whether the categories are mutually exclusive. It does not know whether category 1 is a color, a treatment response, a defect code, or an administrative label. It cannot tell whether an observation was classified consistently, whether an unclassified outcome was omitted, or whether a category boundary changed during collection.

It does not decide whether the expected distribution is reasonable, whether its probabilities were specified before seeing the sample, or whether the expected counts should sum to the observed total. It does not determine whether parameters were estimated from the same data or reduce the degrees of freedom for that estimation. The returned df is the fixed categories - 1 rule encoded by the record.

It does not decide whether sampling was random, representative, independent, or free from clustering and repeated-measure dependence. It does not assess missingness, measurement error, selection bias, exposure differences, stopping rules, or data fabrication. These are design and data-quality questions that no two-list arithmetic can answer.

It does not calculate a p-value, choose alpha, make a reject or fail-to-reject decision, measure practical importance, establish causation, identify a responsible category, or recommend an operational response. It returns a statistic, degrees of freedom, and contribution breakdown. Those outputs become an inference only when joined to a justified model, a valid sampling design, an appropriate reference distribution, and a clearly stated decision context.

  • Not decided: category labels, order, inclusion rules, or data classification quality.
  • Not decided: expected-model validity, total consistency, parameter estimation, or df adjustment.
  • Not decided: random sampling, independence, representativeness, missingness, or bias.
  • Not decided: p-value, alpha, decision, effect importance, causation, or remedy.

A reproducible reporting workflow

Begin with a labeled table containing the category names, observed counts, expected probabilities or counts, and the source of the expected model. Check that every observation belongs to one category, that the categories are in the same order, and that the ordinary fixed-total construction gives matching totals. Record whether any values were rounded, weighted, or estimated from the sample.

Enter the two lists without labels or expressions and read the validation result. Confirm that the list lengths match, there are at least two categories, observed values are nonnegative, and expected values are positive. Inspect the expected-count guideline before relying on an inferential approximation. If a value is rejected, correct the data preparation rather than altering the meaning of the category.

After the result appears, verify one or two contributions by hand. Sum the unrounded contributions, compare that sum with the displayed statistic, and check df = categories - 1. Then inspect signed differences and the labeled source table to see which categories are over or under expectation. If a p-value is needed, calculate it separately with the correct upper-tail reference distribution and document why that reference is justified.

A concise report can state the question, category order, observed list, expected list, total, chi-square statistic, df, p-value if computed, alpha if a decision was planned, the largest residual contributions, and the relevant assumptions. Add a plain-language conclusion that distinguishes evidence of discrepancy from evidence about cause or practical importance. Preserve the original lists so another analyst can reproduce the same arithmetic and challenge the modeling choices.

  • Define and label the categories before copying values into the fields.
  • Check totals, expected-count size, sampling design, and any rounding or weighting.
  • Recalculate representative contributions and verify df independently.
  • Report the statistic separately from any p-value, decision, or practical conclusion.
  • Keep the raw and expected inputs with the analysis record.

Frequently asked questions

What is the Chi-Square Goodness of Fit?

Tests counts against expected counts with the Pearson chi-square statistic.

What is the formula for the Chi-Square Goodness of Fit?

χ² = Σ(O−E)²/E; df = categories − 1. Sums squared standardized residuals across categories. Larger values signal worse fit at df = categories − 1.

What do I need to use this calculator?

Enter Observed counts, Expected counts, then choose Calculate.

What are the limits of this calculator?

Independent counts with matching observed/expected categories. Every expected count positive (5+ preferred); at least 2 categories.

Methodology

This calculator is part of the WorldCalculate library. Its formula, example, assumptions, input bounds, and output formatting follow the official methodology.

Read the WorldCalculate methodology

Use this calculator as part of a bigger plan

These WorldCalculate collections connect this tool with related questions while keeping each calculation separate and transparent.

Keep this guide handy

Share this guide

Send the canonical WorldCalculate page to a classmate, client, teammate, or friend with the destination you already use.