Statistics & probability · AI SL & HL
Chi-square goodness of fit
Test whether category counts fit a specified distribution, account for estimated parameters and interpret departures without overclaiming.
Course focus: AI SL & HL: fixed-probability goodness-of-fit setup and technology are shared. Adjusting degrees of freedom for fitted model parameters is marked HL.
Before you start: Probability distributions, frequencies and hypothesis-test decisions.
Build it from the beginning
A goodness-of-fit test compares observed category counts with those predicted by one specified model. Expected counts equal sample size times model probability. A small p-value suggests the pattern is hard to explain under that model, not that the data are impossible.
A first walkthrough
A fair die is rolled 60 times. Find the expected count for each face.
- The null model assigns probability 1/6 to each face.
- Multiply the probability by the total of 60.
- Each expected count is 10; all six expected counts add back to 60.
The foundations behind the method
Understand what the symbols mean
Goodness of fit asks whether a specified probability model produces a plausible pattern of counts. It is about one classified variable, unlike a test of independence between two variables. The model must define all category probabilities, including omitted-looking tails, before the observed-versus-expected comparison is meaningful.
How the ideas connect
Categorization turns a distribution into a finite list of probabilities, and multiplication by the total turns those probabilities into expected counts. Pooling changes that list. Estimating model parameters also changes how much independent information remains in the discrepancy, explaining why degrees of freedom must follow the complete setup rather than a memorized category count.
Start with the idea
Build your understanding
Specified distribution
The null says how category probabilities are generated. Equal probabilities are only one possible model.
Remaining information
Pooling and fitting affect the independent deviations available to assess fit; they must be reflected in the test setup.
Compare the approaches
Choose by the information in the question, rather than the formula you recognise first.
Fixed-probability test
When it helpsUse when category probabilities are supplied independently of the sample.
Check before using itExpected frequencies must use the actual probability list, not equal shares unless the model says so.
Fitted-model test
When it helpsUse when specified parameters are estimated from these observations.
Check before using itAccount for parameter estimation and final pooled categories when choosing degrees of freedom.
Your method plan
- Write the null probabilities and compute all expected counts.
- Pool compatible small categories if required and determine final degrees of freedom.
- Calculate the right-tail evidence and state a qualified conclusion.
Learn the methods
Learn step by step
1. Specify one distribution before testing
A goodness-of-fit test compares one categorical or grouped variable with a model for its category probabilities. The null can specify equal proportions, known unequal proportions or a parametric distribution. State the categories and make them exhaustive without overlap. Counts should come from independent observations or a suitable count model. A hypothesis chosen after inspecting discrepancies needs care: choosing the model to fit the same data changes the interpretation of its subsequent test.
2. Expected counts come from the null probabilities
For total N and category probability p, use expected count Np. Probabilities must add to one; expected counts then sum to N. For grouped numerical observations, compute each category probability over its interval, including tail categories. Use the underlying count data, not rounded percentages. Expected values may be fractional and should not be rounded to integers before calculating the statistic.
Model expectation
Why this formula works
If each observation has model probability p of entering a category, summing its indicator across N observations gives expected count Np. This links the probability model to the count scale used in the test. Unequal probabilities therefore give unequal expected counts, even when the sample categories are drawn with equal widths.
\(E_i=Np_i\) \(\sum_i p_i=1\).
Quick example
With N=80 and category probabilities 0.2,0.3,0.5, the expected list is 16,24,40.
3. Pool categories responsibly
The chi-square reference approximation can be unreliable with small expected counts. Follow the expected-count conditions specified in the task or course guidance. Combine adjacent or contextually compatible categories when justified, and add both their observed and expected counts. Pooling reduces the number of categories and changes degrees of freedom. It is not legitimate to remove a poorly fitting category solely because it would prevent a desired conclusion.
Worked example: Pool a small tail
An expected list is 24,20,10,4,2 and the corresponding observed list is 22,19,12,5,2. Combine the last two compatible categories.
- The pooled observed count is 5+2=7 and its expected count is 4+2=6.
- The final observed list is 22,19,12,7; expected list is 24,20,10,6.
- Both lists total 60 and every expectation is at least 5.
- With completely fixed probabilities, use \(4-1=3\) degrees of freedom; if a parameter was estimated, account for that separately.
4. Calculate the discrepancy and p-value
Sum \((O-E)^2/E\) for every final category. A larger statistic indicates greater departure from the specified model. Use the right-tail chi-square p-value and the correct degrees of freedom. Record the expected-frequency list and any pooling so the numerical setup is reproducible. A calculator may require observed and expected lists, not the original raw observations. Check their ordering carefully.
Fit is a comparison of complete count lists
- Observed
- Expected under model
Worked example: Four equally likely outcomes
A model predicts four equally likely categories. Observed counts are 12,8,9,11 from 40 observations.
- Each expected count is 10. No pooling is needed under a minimum expected-count-5 rule.
- The statistic is \((4+4+1+1)/10=1\).
- There are 3 degrees of freedom; the right-tail p-value is about 0.801252.
- At 5%, do not reject. The sample provides insufficient evidence against equal category probabilities; it does not prove equality.
Worked example: An observed list that exactly matches its null expectation
A fixed model gives category probabilities 0.2,0.3,0.5. Observed counts are 20,30,50 from 100 observations.
- The expected list is 20,30,50.
- Every observed-minus-expected difference is zero, so the statistic is zero.
- There are 2 degrees of freedom and the right-tail p-value is 1.
- Do not reject this model, but do not call it proved correct. These category totals cannot test unrecorded structure within categories or sampling bias.
5. Distinguish fixed and fitted probabilities
HL extensionWhen k final categories have completely specified probabilities, degrees of freedom are k−1. Estimating m independent model parameters from the same observations typically reduces this to k−1−m under the appropriate regularity conditions. This parameter adjustment is an HL extension. For a fitted Poisson model, estimating its mean costs one degree of freedom. Fitting categories or constraints arbitrarily can require different reasoning; use the model and task specification.
Goodness-of-fit degrees of freedom
HL extensionWhy this formula works
The counts sum to a fixed total, so one category is determined by the others. Each independently fitted parameter uses further information from those same deviations, reducing the independent discrepancy available for testing. Apply this adjustment after pooling categories and under the supplied model conditions.
\(\nu=k-1\) for fixed probabilities; \(\nu=k-1-m\) when m parameters are appropriately estimated.
Quick example
Five final categories with a mean estimated for a Poisson model give \(5-1-1=3\) degrees of freedom.
6. Conclude about the model, not perfection
Rejecting the null gives evidence that the specified distribution does not adequately explain the categorized observations under the test assumptions. Not rejecting means insufficient evidence against it, not proof that the model is correct. Small samples may miss departures; very large ones may detect minor differences. The categories affect what features are visible. Discuss the largest contributions cautiously and avoid describing a p-value as the probability that the model is right.
Quick formula reference
For revision once you understand the methods above. Check the conditions before using a formula.
Goodness-of-fit degrees of freedom
HL extension\(\nu=k-1\) for fixed probabilities; \(\nu=k-1-m\) when m parameters are appropriately estimated.
Return to the explanation →Learn to diagnose an error
Spot the mistake
The statement below is incorrect. Identify the missing condition or reasoning before opening the explanation.
After combining two categories, keep the original degrees of freedom.
Explain and repair the mistake
Pooling reduces the number of final categories and therefore changes the degrees of freedom. Add both observed and expected counts, then calculate degrees of freedom from the pooled category count and any fitted parameters.
Connect and apply
Put the ideas together
A more demanding application of this guide’s methods. This is a learning stage; any additional HL content is labelled separately.
An omitted tail invalidates totals
A Poisson model is grouped into 0,1,2,3,4 arrivals, but arrivals above 4 are possible. What is missing?
- The listed category probabilities add to less than one.
- The expected counts therefore add to less than the sample total.
- Include a final category such as 5 or more, using a cumulative complement.
- Consider pooling that tail with adjacent categories if expected-count conditions require it.
Can above-4 observations simply be deleted?
Check your reasoning
No, unless the sampling design itself is explicitly truncated and the null probabilities are conditioned accordingly. Otherwise deletion changes the observed experiment and distorts the model comparison.
Common mistakes and how to avoid them
- Pooling reduces the number of final categories and therefore changes the degrees of freedom. Add both observed and expected counts, then calculate degrees of freedom from the pooled category count and any fitted parameters.
- Expected frequencies must use the actual probability list, not equal shares unless the model says so.
- Account for parameter estimation and final pooled categories when choosing degrees of freedom.
Practise independently
Build confidence, then apply it
Try each question before opening its hint or solution. If a method is new, return to the walkthrough, then try again. These learning stages describe the practice sequence; additional HL content is labelled separately.
- 1
Build confidence
A category has observed count 14 and expected count 10. Find its chi-square contribution.
Need a starting point?
Square the discrepancy, then divide by the expected count.
Show the worked solution
- The contribution is \((14-10)^2/10\).
- It equals 1.6, not the signed discrepancy 4.
- 2
Apply and explain
A test returns p=0.4 at the 5% level. Have you proved the model true?
Need a starting point?
Distinguish insufficient evidence from proof.
Show the worked solution
- Do not reject the null model because 0.4 exceeds 0.05.
- The data do not provide sufficient evidence against it; that does not prove it is the true distribution.
- 3
Check your understanding
For N=50 and a null category probability 0.2, what is its expected count?
Show the worked solution
It is 50×0.2=10. Keep the entire model’s probability list consistent and exhaustive so all expected counts add to the sample total.
- 4
Use the method
A fully specified model has six final categories. What degrees of freedom should be used?
Show the worked solution
Use 5, because the six counts have one fixed-total constraint and no model parameter has been estimated from them. If one relevant parameter were estimated, the usual adjusted value would be 4.
Finished? Use the linked question bank below to practise selecting the method without a guide telling you which rule to use.
Using these methods in exam questions
AI Paper 1
GDC requiredShort-response questions still need mathematical setup and interpretation. Choose the correct tool, enter the model or data carefully, and check units and rounding.
AI Paper 2
GDC requiredExtended-response questions connect several steps. Keep intermediate values at full precision and explain how each result answers the context.
For this topic: Define the variable or events, write the probability statement or hypotheses, then calculate. Name the distribution and its parameters; interpret the result using the original population or context.
Paper 3: build a connected argument
Both AA HL and AI HL Paper 3 contain two extended problem-solving questions. A question develops a theme, so keep useful earlier results, test small cases and explain any proposed general rule. A calculator pattern can suggest a result; your mathematical reasoning must support it.
- Identify what the first part establishes and record the conditions under which it holds.
- When a later part introduces a new definition or model, connect it to methods you already know rather than assuming a new formula must have been memorised.
- Check the conclusion against an earlier numerical case and explain its meaning or limitation.
For the first-assessment-2021 courses. IB assessment reference ↗
Find a specific method or formula
Now practise the method
If you opened this guide from a question, return to that tab and try the method without looking at the example. Your answer stays in the question tab.
Practise this subtopic →Want a broader practice session? Explore IB Maths AI SL practice questions →Explore IB Maths AI HL practice questions →Try free IB Maths exam-style questions and worked solutions →
Original Arc Practice teaching notes for Maths AI. Core and HL sections are distinguished above. These notes follow the first-assessment-2021 course and are not an official IB publication or a complete syllabus checklist. IB course reference. Report a correction.