跳到主要内容

分类数据的推断:卡方

AP 统计学 · 知识点 8

本主题的视频课程 打开视频页面
7:49

分类数据的推断:卡方

掷一枚公平骰子六十次。每个面应出现十次。但从未如此——这里八次,那里十三次。差距始终存在。因此再掷一次…

英语旁白 · 英中内嵌字幕

8.1

统计学导论:我的结果出乎意料吗?

教学大纲

持久理解 (VAR-1): 鉴于变异可能是随机的,也可能不是随机的,因此结论具有不确定性。

学习目标 VAR-1.J: 识别由分类数据中观察值与期望值之间的计数差异所提出的问题。[技能 1.A]

  • VAR-1.J.1 我们实际发现的结果与我们预期发现的结果之间的变异,可能是随机的,也可能不是随机的。

来源:College Board AP 课程与考试说明

English

Do Grade 10 and Grade 11 students study in different places? Ask 200 of them and the counts will never split perfectly evenly, even if grade makes no difference at all. The question this unit answers is how uneven the counts must be before chance stops being a good explanation.

When data are counts 频数 spread across several categories 类别, we test whether the observed counts 观测频数 differ from what a claim predicts. The tool is the chi-square 卡方 ($\chi^2$) statistic, which adds up the standardized gaps between observed and expected counts:

$$\chi^2=\sum \frac{(\text{observed}-\text{expected})^2}{\text{expected}}.$$
A large $\chi^2$ means the observed counts are far from expected – evidence against the claim. The chi-square distribution 卡方分布 is right-skewed 右偏的 and depends on its degrees of freedom 自由度.

词汇 训练
English 中文 拼音
count 频数 pín shuò
observed count 观测频数 guān cè pín shuò
chi-square/kaɪ skweə/ 卡方 kǎ fāng
chi-square distribution 卡方分布 kǎ fāng fēn bù
right-skewed 右偏的 yòu piān de
degrees of freedom/dɪˈɡriːz ɒv ˈfriːdəm/ 自由度 zì yóu dù
8.2

建立卡方拟合优度检验

教学大纲

持久理解 (VAR-8): 卡方分布可用于对变异进行建模。

学习目标 VAR-8.A: 描述卡方分布。[技能 3.C]

  • VAR-8.A.1 分类数据的期望频数是与零假设一致的计数。通常,期望频数是样本量乘以概率。

    卡方统计量衡量的是观测频数与期望频数之间的距离相对于期望频数的程度。

    卡方分布具有正值且呈右偏态。在密度曲线族中,随着自由度的增加,偏斜程度会变得不那么明显。

学习目标 VAR-8.B: 识别关于一组分类数据中比例分布的检验中的零假设和备择假设。[技能 1.F]

  • VAR-8.B.1 对于卡方拟合优度检验,零假设为每个类别指定了零比例,而备择假设是这些比例中至少有一个与零假设指定的不符。

学习目标 VAR-8.C: 识别适用于一组分类数据中比例分布的适当检验方法。[技能 1.E]

  • VAR-8.C.1 当考虑单个分类变量的比例分布时,适当的检验是卡方拟合优度检验。

学习目标 VAR-8.D: 计算卡方拟合优度检验的期望频数。[技能 3.A]

  • VAR-8.D.1 卡方拟合优度检验的期望频数为(样本量)×(零比例)。

学习目标 VAR-8.E: 验证在对卡方分布进行拟合优度检验时做出统计推断的条件。[技能 4.C]

  • VAR-8.E.1 为了对卡方拟合优度检验进行统计推断,我们必须检查以下几点:
    • a. 为检查独立性:
      • i. 数据应通过随机抽样或随机实验收集。
      • ii. 在不放回抽样时,检查 $n \leq 10\%N$。
    • b. 卡方拟合优度检验随着观测值的增加而变得更加准确,因此应使用较大的计数(形状)。
      • i. 一种保守的大计数检查方法是所有期望频数都应大于 5。

来源:College Board AP 课程与考试说明

English
The chi-square (χ²) test

A goodness-of-fit (GOF) 拟合优度 test checks whether one categorical variable 分类变量 follows a claimed distribution (e.g. "the die is fair"). Hypotheses:

$$H_0:\text{the distribution is as claimed}\qquad H_a:\text{at least one proportion differs}.$$
Expected count 期望频数 for each category $=n\times(\text{claimed proportion})$. Conditions 条件: random sample, all expected counts $\ge 5$, and the 10% condition.

The chi-square distribution and its right-tail rejection region
The chi-square distribution is right-skewed. A large statistic lands in the shaded right tail past the critical value – that is where you reject the model.
词汇 训练
English 中文 拼音
category/ˈkætɪɡəri/ 类别 lèi bié
goodness-of-fit/ˈɡʊdnəs ɒv fɪt/ 拟合优度 nǐ hé yōu dù
categorical variable 分类变量 fēn lèi biàn liàng
expected count/ekˈspektɪd kaʊnt/ 期望频数 qī wàng pín shuò
conditions/kənˈdɪʃnz/ 条件 tiáo jiàn
8.3

执行卡方拟合优度检验

教学大纲

持久性理解 (VAR-8): 卡方分布可用于建模变异。

学习目标 VAR-8.F: 计算拟合优度卡方检验的适当统计量。[技能 3.E]

  • VAR-8.F.1 拟合优度卡方检验的检验统计量为
    • 公式: $\chi^2 = \sum \dfrac{(Observed\ count - Expected\ count)^2}{Expected\ count}$,其中 $degrees\ of\ freedom = number\ of\ categories - 1$。
  • VAR-8.F.2 假设原假设为真时(零分布),检验统计量的分布可以是随机化分布,或者在假设概率模型为真时,是理论分布(卡方分布)。

学习目标 VAR-8.G: 确定拟合优度卡方检验显著性检验的 $p$ 值。[技能 3.E]

  • VAR-8.G.1 对于给定自由度的拟合优度卡方检验,其 $p$ 值是通过使用适当的表格或计算机生成的输出来找到的。

持久性理解 (DAT-3): 显著性检验使我们能够在特定背景下对假设做出决策。

学习目标 DAT-3.I: 解释拟合优度卡方检验的 $p$ 值。[技能 4.B]

  • DAT-3.I.1 拟合优度卡方检验的 $p$ 值的解释是:在原假设和概率模型为真的条件下,获得等于或大于观察到的检验统计量极端程度的统计量的概率。

学习目标 DAT-3.J: 根据拟合优度卡方检验的结果,就总体提出主张并提供理由。[技能 4.E]

  • DAT-3.J.1 拒绝或不拒绝原假设的决定是基于将 $p$ 值与显著性水平 $\alpha$ 进行比较。
  • DAT-3.J.2 拟合优度卡方检验的结果可以作为统计推理的基础,以支持关于所抽样总体的研究问题的答案。

来源:College Board AP 课程与考试说明

English

Compute $\chi^2=\sum\dfrac{(O-E)^2}{E}$ with $df=(\text{number of categories})-1$. Find the $p$-value P值 from the chi-square distribution (upper tail 右尾), compare to $\alpha$, and conclude in context. A large component of the sum points to the category that deviates most.

Chi-square compares observed counts with those expected under the null hypothesis
Chi-square compares observed counts with those expected under the null hypothesis

Worked example. A die rolled $60$ times gives counts $8,10,12,9,11,10$. If it is fair, each expected count is $60/6=10$, so

$$\chi^2=\frac{(8-10)^2}{10}+\frac{(10-10)^2}{10}+\frac{(12-10)^2}{10}+\frac{(9-10)^2}{10}+\frac{(11-10)^2}{10}+\frac{(10-10)^2}{10}=0.4+0+0.4+0.1+0.1+0=1.0,$$
with $df=6-1=5$. Write out every category, including the two that match their expected count exactly and so add $0$ – the sum runs over all six categories, and $df$ counts categories, not just the ones that differ. This $\chi^2$ is small (a large $p$-value), so we fail to reject 不拒绝 $H_0$ – no evidence the die is unfair.

Worked example: unequal claimed proportions. A sweet maker claims its bags are $30\%$ red, $20\%$ green and $50\%$ yellow. A random sample of $200$ sweets has $70$ red, $30$ green and $100$ yellow.

Colour Red Green Yellow
Observed $70$ $30$ $100$
Expected $200(0.30)=60$ $200(0.20)=40$ $200(0.50)=100$
$$\chi^2=\frac{(70-60)^2}{60}+\frac{(30-40)^2}{40}+\frac{(100-100)^2}{100}=1.67+2.50+0=4.17,\qquad df=3-1=2.$$

The $p$-value is about $0.12>0.05$, so fail to reject $H_0$: there is not convincing evidence that the colour distribution differs from the maker's claim. The expected counts come from the claimed percentages, not from dividing $200$ equally by $3$.

探索

探索卡方分布及其 p 值

p 值是测试统计量之后右尾中的面积,因此较大的 $\chi^2$ 意味着较小的 p 值。拖动 $\chi^2$ 观察该面积缩小,并拖动 df 观察整个族形的变化——小自由度时强烈右偏,随着自由度增长变得更加对称。

词汇 训练
English 中文 拼音
upper tail 右尾 yòu wěi
fail to reject/feɪl tə rɪˈdʒekt/ 不拒绝 bù jù jué
8.4

双向表中的期望频数

教学大纲

持久性理解 (VAR-8): 卡方分布可用于建模变异。

学习目标 VAR-8.H: 计算分类数据的列联表中的期望频数。[技能 3.A]

  • VAR-8.H.1 分类数据列联表中特定单元格的期望频数可以使用以下公式计算:
    • 公式: $expected\ count = \dfrac{(row\ total)(column\ total)}{table\ total}$.

来源:College Board AP 课程与考试说明

English

For a two-way table 双向表, the expected count in a cell (under "no association") is

$$E=\frac{(\text{row total})\times(\text{column total})}{\text{grand total}}.$$
This is the count you would see if the row and column variables were unrelated (no association 关联).

Worked example. In a two-way table a cell's row total is $40$, its column total is $50$, and the grand total is $200$. Its expected count is $E=\dfrac{40\times50}{200}=10$. Repeating for every cell gives the expected table to compare against the observed one.

A spreadsheet organises categorical counts before a chi-square test
A spreadsheet organises categorical counts before a chi-square test
Expected count = row total × column total ÷ grand total
Expected count = row total × column total ÷ grand total
词汇 训练
English 中文 拼音
two-way table/tuː weɪ ˈteɪbl/ 双向表 shuāng xiàng biǎo
association/əˌsəʊsɪˈeɪʃn/ 关联 guān lián
8.5

建立卡方齐性或独立性检验

教学大纲

持久理解(VAR-8): 卡方分布可用于对变异进行建模。

学习目标 VAR-8.I: 识别卡方同质性检验或独立性检验的原假设与备择假设。[技能 1.F]

  • VAR-8.I.1 卡方同质性检验的适当假设为:

    $H_0$:分类变量在不同总体或处理组中的分布没有差异。

    $H_a$:分类变量在不同总体或处理组中的分布存在差异。

  • VAR-8.I.2 卡方独立性检验的适当假设为:

    $H_0$:给定总体中两个分类变量之间不存在关联,或者这两个分类变量相互独立。

    $H_a$:总体中的两个分类变量有关联或依赖。

学习目标 VAR-8.J: 识别用于比较分类数据二维表分布的适当检验方法。[技能 1.E]

  • VAR-8.J.1 当通过比较分布来确定从不同总体收集的每个类别的分类数据的比例是否相同时,适当的检验是卡方同质性检验。
  • VAR-8.J.2 为了确定从样本所在的总体中抽取的数据在二维表中行变量和列变量可能存在关联时,适当的检验是卡方独立性检验。

学习目标 VAR-8.K: 验证在进行卡方独立性或同质性检验时的统计推断条件。[技能 4.C]

  • VAR-8.K.1 为了对二维表的卡方检验(同质性或独立性)进行统计推断,我们必须验证以下事项:
    • a. 检查独立性:
      • i. 对于独立性检验:数据应使用简单随机抽样收集。
      • ii. 对于同质性检验:数据应使用分层随机抽样或随机实验收集。
      • iii. 在不放回抽样时,检查 $n \leq 10\%N$。
    • b. 卡方独立性检验和同质性检验随着观测值的增加而更加准确,因此应使用大频数(形状)。
      • i. 关于大频数的保守检查是:所有期望频数都应大于 5。

来源:College Board AP 课程与考试说明

English

Two tests use the same $\chi^2$ math but answer different questions:

  • Test for homogeneity 同质性检验: are the distributions of one categorical variable the same across several populations or groups (separate samples/treatments)?
  • Test for independence 独立性检验: are two categorical variables associated within a single population (one sample, two variables measured)?

The design (several samples vs one sample) decides which name and hypotheses to use.

Homogeneity compares populations on one variable; independence asks about two variables in one sample
Homogeneity compares populations on one variable; independence asks about two variables in one sample
词汇 训练
English 中文 拼音
test for homogeneity/test fɔː ˈhɒməʊdʒneɪti/ 同质性检验 tóng zhì xìng jiǎn yàn
test for independence/test fɔː ˌɪndɪˈpendəns/ 独立性检验 dú lì xìng jiǎn yàn
8.6

执行卡方齐性或独立性检验

教学大纲

持久性理解 (VAR-8): 卡方分布可用于建模变异。

学习目标 VAR-8.L: 计算适用于同质性或独立性卡方检验的统计量。[技能 3.E]

  • VAR-8.L.1 用于同质性或独立性卡方检验的适当检验统计量为卡方统计量:
    • 公式: $\chi^2 = \sum \dfrac{(Observed\ count - Expected\ count)^2}{Expected\ count}$,自由度等于:$(number\ of\ rows - 1)(number\ of\ columns - 1)$。

学习目标 VAR-8.M: 确定独立性或同质性卡方显著性检验的 $p$ 值。[技能 3.E]

  • VAR-8.M.1 对于具有特定自由度的独立性或同质性卡方检验,其 $p$ 值可通过适当的表格或技术工具求得。
  • VAR-8.M.2 对于列联表的独立性或同质性检验,$p$ 值是在具有适当自由度的卡方分布中,等于或大于检验统计量的值的比例。

持久性理解 (DAT-3): 显著性检验使我们能够在特定背景下对假设做出决策。

学习目标 DAT-3.K: 解释同质性或独立性卡方检验的 $p$ 值。[技能 4.B]

  • DAT-3.K.1 对同质性或独立性卡方检验的 $p$ 值的解释是:在原假设和概率模型为真的条件下,获得等于或比观测值更极端的检验统计量的概率。

学习目标 DAT-3.L: 基于同质性或独立性卡方检验的结果,就总体主张提供理由。[技能 4.E]

  • DAT-3.L.1 决定是否拒绝或不拒绝同质性或独立性卡方检验的原假设,是基于将 $p$ 值与显著性水平 $\alpha$ 进行比较。
  • DAT-3.L.2 同质性或独立性卡方检验的结果可作为统计推理的基础,以支持关于所抽样总体(独立性)或所抽样多个总体(同质性)的研究问题的答案。

来源:College Board AP 课程与考试说明

English

Compute expected counts, then $\chi^2=\sum\dfrac{(O-E)^2}{E}$ over all cells, with

$$df=(\text{rows}-1)(\text{columns}-1).$$
Conditions: random data, all expected counts $\ge 5$, 10% condition. Find the $p$-value, compare to $\alpha$, and conclude in context – evidence of a difference between groups (homogeneity) or of an association (independence).

Worked example: a test for independence. A random sample of 200 students at one school is classified by grade and by where they usually study.

Library Home Café Total
Grade 10 30 50 20 100
Grade 11 45 35 20 100
Total 75 85 40 200
  • State. $H_0$: grade and study place are independent for students at this school. $H_a$: they are associated.
  • Plan. Chi-square test for independence: one sample, two variables. Random sample; 200 is less than 10% of the students if the school has more than 2000; expected counts below are all at least 5.
  • Do. Expected counts: $\dfrac{100\times75}{200}=37.5$, then $42.5$ and $20$ in each row. The six components are $1.50,\ 1.32,\ 0,\ 1.50,\ 1.32,\ 0$, so $\chi^2=5.65$ with $df=(2-1)(3-1)=2$, giving $p\approx0.059$.
  • Conclude. Because $p\approx0.059>\alpha=0.05$, fail to reject $H_0$. There is not convincing evidence of an association between grade and study place for students at this school.

The library cells contribute most: Grade 11 students chose the library more often than expected. That is worth noting as a pattern, but with this $p$-value it is not convincing evidence.

Common mistakes. Checking the condition with observed counts: it is the expected counts that must all be at least $5$. Running chi-square on percentages or means instead of counts. Using $df=n-1=199$ instead of $(r-1)(c-1)=2$. Writing $H_0$ as “grade and study place are associated”: the null hypothesis always says no association. Calling a one-sample, two-variable test “homogeneity”.

8.7

技能聚焦:为分类数据选择合适的推断方法

教学大纲

本主题旨在聚焦于在拥有多种选项后,选择恰当推断方法的技能。应为学生提供充分机会,练习何时以及如何应用所有与分类数据推断相关的学习目标。

来源:College Board AP 课程与考试说明

English

Decide by the setup: one categorical variable against a claimed distribution $\Rightarrow$ goodness-of-fit; one sample cross-classified by two variables $\Rightarrow$ independence; several samples/groups compared $\Rightarrow$ homogeneity. Comparing just two proportions can use either a two-proportion $z$-test or a chi-square test, but only for a two-tailed 双尾 alternative, where they agree exactly ($\chi^2=z^2$). The chi-square statistic is compared with the upper tail of its reference distribution. For two proportions it tests a non-directional alternative, so if $H_a$ is one-sided 单侧 (say $p_1>p_2$), use the $z$-test.

Choosing a categorical inference procedure
Choosing a categorical inference procedure
探索

这是哪种卡方检验?

所有三种检验都使用相同的 $\chi^2$ 算术,因此得分关键在于命名正确的检验。设计决定了一切——取了多少个样本,以及每个单位测量了多少个变量。

词汇 训练
English 中文 拼音
two-tailed/tuː teɪld/ 双尾 shuāng wěi
one-sided 单侧 dān cè
8.7

Practice

English

Answer each before reading the answers below.

  1. In a two-way table, a cell's row total is 60, its column total is 50 and the grand total is 200. Find its expected count.
  2. A two-way table has 3 rows and 4 columns. Find the degrees of freedom for a chi-square test.
  3. A die is rolled 60 times, giving counts $6,\ 10,\ 8,\ 12,\ 14,\ 10$ for faces 1 to 6. Find $\chi^2$ for a goodness-of-fit test of a fair die. Its $p$-value is about $0.55$. Conclude.
  4. Name the test: (a) one random sample of 500 adults, classified by phone brand and age group; (b) separate random samples from three cities, comparing favourite sport; (c) the colours in a bag of sweets, compared with the maker's claimed percentages.
  5. A student says: “In the worked example $p=0.059$, so grade and study place are independent.” Correct the student.
8.7

答案

English
  1. $\dfrac{60\times50}{200}=15$.
  2. $(3-1)(4-1)=6$.
  3. Each expected count is 10. $\chi^2=\dfrac{16+0+4+4+16+0}{10}=4.0$, $df=5$. With $p\approx0.55$, fail to reject $H_0$: no convincing evidence that the die is unfair.
  4. (a) Independence; (b) homogeneity; (c) goodness-of-fit.
  5. Failing to reject $H_0$ means the data are not convincing evidence of an association. It does not prove independence: a real but small association could still exist. Write “not convincing evidence of an association”, never “they are independent”.
8.7

考试技巧

English
  • Use $\chi^2=\sum\tfrac{(O-E)^2}{E}$ for categorical data; always divide by the expected count.
  • Pick the right test: goodness-of-fit (one variable), independence, or homogeneity (two-way table).
  • Compute expected counts as $\tfrac{\text{row total}\times\text{column total}}{\text{grand total}}$ and check each is $\ge5$.
  • A large $\chi^2$ (small p-value) means observed counts differ from expected by more than chance.
  • State degrees of freedom correctly (categories $-1$, or $(r-1)(c-1)$).
词汇 训练
English 中文 拼音
p-value/piː ˈvæljuː/ P值 P zhí

该知识点的互动课程

逐步完成,配合即时检查练习。

历年真题

更多 AP 统计学 知识点

登录或创建账户

IGCSE, A-Level & AP