📚 15A Chi-squared Tests | 卡方检验
Chi-squared tests are fundamental non-parametric statistical tools used to analyse categorical data. They allow us to determine whether observed frequencies differ significantly from expected frequencies, either for a single categorical variable (goodness‑of‑fit) or to explore the association between two categorical variables (test for independence). In IB Mathematics, particularly in the Applications and Interpretation HL course, chi‑squared tests appear as a core method for drawing conclusions from frequency data, without making assumptions about the underlying population distribution. Mastering these tests involves understanding hypotheses, calculating the test statistic by hand and with technology, interpreting degrees of freedom, and linking p‑values or critical values to a significance level.
卡方检验是分析分类数据的基础非参数统计工具。它们帮助我们判断观测频数与期望频数是否存在显著差异,可用于检验单一分类变量的分布(拟合优度)或检验两个分类变量之间的关联(独立性检验)。在IB数学课程,尤其是应用与解释高水平课程中,卡方检验是处理频数数据、推断结论的核心方法,它无需对总体分布做任何假设。掌握这些检验需要理解假设的设定、手工与借助技术计算检验统计量、解释自由度,并将p值或临界值与显著性水平联系起来。
1. What is a Chi-squared Test? | 什么是卡方检验?
A chi‑squared (χ²) test compares observed counts with expected counts under a specific hypothesis. Because the test statistic follows a chi‑squared distribution when the null hypothesis is true, we can use it to make inferential decisions. The shape of the χ² distribution depends on the degrees of freedom (df), and it is always positive and skewed to the right, especially for small df.
卡方检验(χ²检验)将实际观测计数与特定假设下的期望计数进行比较。由于在原假设成立时检验统计量服从卡方分布,我们可以利用它进行推断。χ²分布的形状取决于自由度(df),该分布恒取正值,且在小自由度时呈现右偏态。
- The test is suitable for categorical data, organised into frequency tables.
- 检验适用于被整理为频数表的分类数据。
- There are two main variants: goodness‑of‑fit test (one variable) and test for independence (two variables).
- 主要有两种形式:拟合优度检验(一个变量)和独立性检验(两个变量)。
- It does not require the data to be normally distributed.
- 该检验不要求数据服从正态分布。
2. Types of Chi-squared Tests | 卡方检验的类型
In the IB syllabus, you will meet the goodness‑of‑fit test (χ² GOF) and the χ² test for independence. The GOF test checks whether a single categorical variable follows a claimed distribution. The test for independence examines whether two categorical variables are associated, using a contingency table. A third related test, the test for homogeneity, is structurally identical to the independence test but differs in sampling design; it is sometimes mentioned but not formally required in Standard Level or basic HL.
在IB课程大纲中,你会遇到拟合优度检验(χ² GOF)和独立性χ²检验。拟合优度检验检查单一分类变量是否服从某一声称的分布。独立性检验使用列联表考察两个分类变量之间是否存在关联。第三种相关检验——同质性检验,在结构上与独立性检验相同,但抽样设计不同;偶尔会提到,但在标准水平或普通高水平中不做正式要求。
- Goodness‑of‑fit: e.g., testing if a die is fair.
- 拟合优度:比如检验一个骰子是否均匀。
- Independence: e.g., testing if gender and voting preference are related.
- 独立性:比如检验性别与投票偏好是否有关联。
3. Null and Alternative Hypotheses | 原假设与备择假设
For a goodness‑of‑fit test, the null hypothesis H₀ states that the observed frequencies follow the specified distribution. The alternative H₁ claims that they do not. For example, when testing a die: H₀: the die is fair (each face has probability 1/6); H₁: the die is not fair. For a test for independence, H₀ asserts that the two variables are independent, while H₁ states they are dependent. These are always written in words, not symbols, when defining the test.
对于拟合优度检验,原假设H₀陈述观测频数服从某一指定分布,备择假设H₁则称其不服从该分布。例如,检验一个骰子:H₀:该骰子是均匀的(每个面概率为1/6);H₁:该骰子不均匀。对于独立性检验,H₀断言两个变量相互独立,H₁则表示它们相关。在定义检验时,这些假设总用文字而非符号表述。
| Test type | H₀ | H₁ |
|---|---|---|
| Goodness‑of‑fit | The data follow the specified distribution. | The data do not follow the specified distribution. |
| Independence | The two variables are independent. | The two variables are dependent (associated). |
4. The Test Statistic Formula | 检验统计量公式
The chi‑squared statistic is calculated by summing the squared differences between observed (O) and expected (E) frequencies, divided by the expected frequency for each cell:
卡方统计量的计算方式为:对各单元格求观测频数(O)与期望频数(E)之差的平方除以期望频数,再对所有单元格求和:
χ² = ∑ (O − E)² / E
Here, the sum runs over all categories or cells in the table. A large χ² value indicates a big discrepancy between what we observe and what we would expect if H₀ were true. For both types of test, the formula remains the same. In the goodness‑of‑fit test, expected values come from the claimed distribution; in the independence test, they are calculated from row and column totals assuming independence.
式中,求和遍及所有类别或表格单元格。若χ²值较大,说明实际观测与H₀成立时的期望值之间存在较大偏差。两种检验的公式保持不变。在拟合优度检验中,期望值来自声称的分布;在独立性检验中,期望值基于行合计与列合计、在独立性假设下计算得出。
5. Degrees of Freedom | 自由度
Degrees of freedom (df) determine the shape of the χ² distribution used to find the p‑value or critical value. For a goodness‑of‑ 1). Getting the df correct is essential; a mistake here will make the whole test invalid.
自由度(df)决定了用于查找p值或临界值的χ²分布的形状。对于拟合优度检验,df = 类别数 − 1 − 被估计参数的个数。如果没有从数据中估计参数,则df = k − 1,其中k为类别数。对于r × c列联表的独立性检验,df = (r − 1)(c − 1)。正确确定自由度至关重要;一旦出错,整个检验将失效。
- Example GOF: a fair 6‑sided die, k = 6, df = 6 − 1 = 5.
- 拟合优度示例:一枚均匀六面骰子,k = 6,df = 6 − 1 = 5。
- Example independence: a 2×3 table, df = (2−1)(3−1) = 1 × 2 = 2.
- 独立性示例:2×3表格,df = (2−1)(3−1) = 1 × 2 = 2。
6. Goodness‑of‑Fit Test: Step-by-Step | 拟合优度检验:逐步讲解
A goodness‑of‑fit test is conducted when you have one categorical variable and you want to test whether the observed distribution matches a theoretical distribution. Follow these steps:
当你拥有一个分类变量,并希望检验其观测分布是否与某一理论分布一致时,可进行拟合优度检验。遵循以下步骤:
- State H₀ and H₁ in words.
- 用文字陈述H₀与H₁。
- Calculate expected frequencies: multiply the total sample size by the claimed proportions.
- 计算期望频数:将样本总数乘以声称的比例。
- Compute χ² using the formula ∑ (O − E)² / E.
- 使用公式∑ (O − E)² / E 计算χ²值。
- Determine degrees of freedom: df = k − 1 (or adjust if parameters were estimated).
- 确定自由度:df = k − 1(如果估计了参数则调整)。
- Find the p‑value (using GDC or χ² table) for the given significance level α, or compare χ² with the critical value.
- 在给定显著性水平α下,求得p值(借助GDC或χ²表),或将χ²与临界值进行比较。
- Make a conclusion: if p ≤ α, reject H₀; otherwise, do not reject H₀.
- 得出结论:若p ≤ α,拒绝H₀;否则不拒绝H₀。
7. Example: Goodness‑of‑Fit | 示例:拟合优度检验
A bag of sweets is claimed to contain 40% red, 30% green, 20% blue and 10% yellow. A random sample of 100 sweets gives: 45 red, 20 green, 25 blue, 10 yellow. Test at the 5% significance level whether the sample fits the claimed distribution.
某包糖果声称含有40%红色、30%绿色、20%蓝色和10%黄色。随机抽取100颗糖果得到:红色45颗、绿色20颗、蓝色25颗、黄色10颗。在5%显著性水平下检验该样本是否符合声称的分布。
Expected: red 40, green 30, blue 20, yellow 10.
期望频数:红色40、绿色30、蓝色20、黄色10。
−20)²/20 + (10−10)²/10 = 25/40 + 100/30 + 25/20 + 0 = 0.625 + 3.333 + 1.25 = 5.208 (3 dp).
df = 4 − 1 = 3. Using GDC, p‑ idence to conclude that the distribution of colours differs from the claimed distribution.
df = 4 − 1 = 3。使用GDC得p值约0.157。由于0.157 > 0.05,我们不拒绝H₀。没有足够证据表明糖果颜色分布与声称的分布不一致。
8. Test for Independence: Contingency Tables | 独立性检验:列联表
nce): E = (row total × column total) / grand total, for each cell. This test is always one‑tailed to the right, but we talk about “association” rather than direction.
独立性χ²检验考察两个分类变量是否存在关联。数据汇总于r × c列联表中。在H₀(独立)成立的假设下,各单元格的期望频数计算公式为:E = (行合计 × 列合计)/ 总计。该检验总是右尾检验,但我们谈论的是“关联”而非方向。
The steps mirror the goodness‑of‑ expected counts computed from the table. Remember to check that no expected frequency falls below 5; if some do, you may need to combine categories or use a different test (IB usually expects you to recognise this assumption).
步骤与拟合优度检验相似,但df = (r−1)(c−1),且期望计数由表格计算得出。务必确认没有任何期望频数低于5;若个别单元格如此,可能需要合并类别或改用其他检验(IB通常要求你认识到这一假设)。
9. Example: Test for Independence | 示例:独立性检验
Researchers survey 200 students to see if gender is independent of favourite sport (football, basketball, volleyball). The observed table is:
研究人员调查了200名学生,想了解性别是否与最喜爱的运动(足球、篮球、排球)独立。观测频数表如下:
| Football | Basketball | Volleyball | Total | |
|---|---|---|---|---|
| Male | 60 | 25 | 15 | 100 |
| Female | 30 | 35 | 35 | 100 |
| Total | 90 | 60 | 50 | 200 |
Expected for Male/Football: (100×90)/200 = 45. Complete expected table:
男性-足球的期望值:(100×90)/200 = 45。完整的期望表如下:
| Male | Female | |
| Football | 45 | 45 |
| Basketball | 30 | 30 |
| Volleyball | 25 | 25 |
+ (35−30)²/30 + (15−25)²/25 + (35−25)²/25 = 5 + 5 + 0.833 + 0.833 + 4 + 4 = 19.666 (3 dp).
df = (2−1)(3−1) = 1×2 = 2. Using GDC, p‑ Since p < 0.05, we reject H₀ and conclude that gender and favourite sport are associated.
df = (2−1)(3−1) = 2。使用GDC得p值约0.0000536。由于p < 0.05,拒绝H₀,认为性别与最喜爱的运动之间存在关联。
10. p‑value and Critical Value Approach | p值与临界值法
You can decide the outcome of a χ² test by either comparing the p‑value to the significance level α, or by comparing the calculated χ² statistic to the critical value from the χ² distribution table. The p‑value method is generally preferred when using a calculator, while the critical value method appears more often in exams when tables are provided. Both lead to the same conclusion.
你既可以将p值与显著性水平α进行比较,也可以将计算出的χ²统计量与χ²分布表中的临界值进行比较,从而决定检验结果。使用计算器时通常更倾向于p值法,而在提供表格的考试中临界值法更常见。两者得出相同的结论。
- If p‑value ≤ α, reject H₀.
- 若p值 ≤ α,拒绝H₀。
- If χ² ≥ critical value (at α and df), reject H₀.
- 若χ² ≥ 临界值(在α与df下),拒绝H₀。
- The critical region lies in the right tail; χ² tests are always one‑tailed.
- 拒绝域位于右尾;χ²检验始终为单尾检验。
11. Conditions and Assumptions | 条件与假设
. For 2×2 tables, some IB textbooks mention a lower limit of 5 for expected frequencies; if violated, consider combining rows or columns, or applying Yates' correction.
为使χ²检验有效,必须满足若干条件。数据应通过随机抽样收集。每个观测值必须恰好归于一个类别。类别之间应互斥。最重要的是,每个单元格的期望频数应至少为5。对于2×2表格,部分IB教材要求期望频数下限为5;若该条件不满足,可考虑合并行或列,或应用Yates修正。
- Random sample.
- 随机样本。
- Expected frequencies ≥ 5.
- 期望频数 ≥ 5。
- Independent observations.
- 观察值相互独立。
12. Yates' Continuity Correction | Yates连续性修正
Yates' encies are borderline. It reduces the χ² value slightly by adjusting the formula: χ² = ∑ (|O − E| de it by default. Check your syllabus specification; some courses mention it but do not test it extensively.
Yates修正仅应用于2×2列联表,且当样本总量较小或期望频数处于边界值时使用。它将公式调整为χ² = ∑ (|O − E| − 0.5)² / E,由此略微减小χ²值。这使得检验更加保守(更不倾向于拒绝H₀)。在IB中,通常会告知何时使用该修正;现代GDC默认可能不包含此修正。请核对你的课程大纲;有些课程会提及但不会深入考查。
13. Using Technology (GDC) | 使用技术(图形计算器)
IB exams expect you to perform χ² tests efficiently using a graphical display calculator. You can enter observed data into a matrix or list, and the GDC will compute the test statistic, degrees of freedom and p‑value. For goodness‑of‑fit, some calculators require entering observed and expected lists. For independence, you typically use the χ²‑Test function after entering the observed contingency matrix. Always round the p‑value to three significant figures in your final report, and make sure to write a conclusion in context.
IB考试希望你能熟练运用图形计算器执行χ²检验。你可以将观测数据输入矩阵或列表,GDC会算出检验统计量、自由度以及p值。对于拟合优度检验,某些计算器需输入观测值列表和期望值列表。对于独立性检验,通常在输入观测列联矩阵后使用χ²‑Test功能。最终呈现时,务必将p值四舍五入到三位有效数字,并务必结合语境写出结论。
Published by TutorHao | IB Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图