📚 Chi-squared tests | 卡方检验
Chi-squared tests are statistical hypothesis tests used to determine whether there is a significant difference between observed frequencies and expected frequencies in categorical data. At A-Level, you will encounter two main types: the test for association (independence) using contingency tables, and the goodness-of-fit test. These tests rely on the chi-squared (χ²) distribution and are essential tools in a data analyst's toolkit.
卡方检验是一种统计假设检验,用于判断分类数据中观测频数与期望频数之间是否存在显著差异。在 A-Level 阶段,你会遇到两种主要类型:使用列联表的关联性(独立性)检验,以及拟合优度检验。这些检验基于卡方(χ²)分布,是数据分析人员的重要工具。
1. Introduction to Chi-squared Tests | 卡方检验简介
A chi-squared test compares observed frequencies (O) with the frequencies we would expect (E) under a null hypothesis. It calculates a test statistic that follows a χ²-distribution with a certain number of degrees of freedom (ν). If the statistic is large, it suggests that the observed data do not fit the expected pattern, leading to a rejection of the null hypothesis.
卡方检验将观测频数(O)与在原假设下我们期望的频率(E)进行比较。它计算一个服从 χ² 分布的检验统计量,该分布具有一定的自由度(ν)。若统计量很大,说明观测数据与期望模式不符,从而导致拒绝原假设。
The χ²-distribution is a family of curves that are positively skewed and become more symmetric as ν increases. It is used to find critical values or p-values for making a decision about the hypothesis.
χ² 分布是一族正偏态的曲线,随着自由度 ν 的增加逐渐趋向对称。它用于查找临界值或 p 值,从而对假设做出决策。
2. The χ² Test Statistic | χ² 检验统计量
The test statistic for all chi-squared tests takes the general form:
所有卡方检验的统计量一般的计算公式为:
χ² = Σ (O − E)² / E
Here, O represents the observed frequency in each category or cell, and E is the corresponding expected frequency. The sum is taken over all categories or cells. A larger value of χ² indicates a greater discrepancy between the observed and expected data.
其中 O 表示每个类别或单元格的观测频数,E 是对应的期望频数。总和覆盖所有类别或单元格。χ² 值越大,表明观测数据与期望数据之间的差异越大。
It is essential to use frequencies, not proportions or percentages. Make sure that all expected frequencies are at least 1, and no more than 20% of them are below 5. If this condition is not met, adjacent categories should be combined.
必须使用频数,不能用比例或百分比。确保所有期望频数至少为 1,且低于 5 的比例不超过 20%。如果不符合条件,需要合并相邻类别。
3. Degrees of Freedom | 自由度
gency table, ν = (r − 1)(c − 1). For a goodness-of-fit test, ν = k − p − 1, where k is the number of categories or groups after any necessary merging, and p is the number of population parameters estimated from the sample.
自由度(ν)取决于检验类型以及从数据中估计的参数个数。对于 r × c 列联表的关联性检验,ν = (r − 1)(c − 1)。对于拟合优度检验,ν = k − p − 1,其中 k 是经过必要合并后的类别或组数,p 是从样本中估计的总体参数个数。
Degrees of freedom determine the shape of the chi-squared distribution used to find critical values or p-values. The test is always one-tailed in the context of chi-squared tests, as we only reject H₀ for large values of χ².
自由度决定了用于查找临界值或 p 值的卡方分布形状。在卡方检验中,检验始终是单尾的,因为我们只在 χ² 值很大时拒绝 H₀。
4. Chi-squared Test for Association (Contingency Tables) | 关联性卡方检验(列联表)
This test determines whether two categorical variables are independent. The null hypothesis is H₀: The two variables are independent (no association). The alternative hypothesis is H₁: There is an association between the variables.
该检验用于判断两个分类变量是否独立。原假设 H₀:两个变量相互独立(无关联)。备择假设 H₁:变量之间存在关联。
To perform the test, first form a contingency table. Calculate expected frequencies using:
执行检验时,首先建立列联表。使用下式计算期望频数:
E = (Row total × Column total) / Grand total
eedom, or use the p-value. If χ² > critical value (or p-value < significance level α), reject H₀ and conclude that there is evidence of an association.
然后计算所有单元格的 χ² 统计量。将统计量与自由度为 ν = (r − 1)(c − 1) 的 χ² 分布临界值比较,或使用 p 值。如果 χ² > 临界值(或 p 值 < 显著性水平 α),则拒绝 H₀,并得出存在关联证据的结论。
pected values are calculated, χ² is found, and the decision is made. Always state the conclusion in the context of the problem.
示例:一个关于冰淇淋偏好与性别的调查得到 2×3 表格,计算期望值,求出 χ² 并做出决策。务必在题目上下文中陈述结论。
5. Yates' Correction for 2×2 Tables | 2×2 表的耶茨校正
² statistic may overestimate significance because the distribution is discrete while we approximate it with a continuous χ²-distribution. Edexcel requires the use of Yates' continuity correction in such cases.
当列联表为 2×2 时,χ² 统计量可能高估显著性,因为数据是离散的,而我们用连续 χ² 分布近似。Edexcel 要求在此情况下使用耶茨连续性校正。
The corrected formula is:
校正后的公式为:
χ² = Σ (|O − E| − 0.5)² / E
That is, subtract 0.5 from the absolute difference before squaring. This adjustment makes the test more conservative and reduces the risk of a Type I error.
即在平方前从绝对值差中减去 0.5。这一调整使检验更为保守,降低第一类错误的风险。
Yates' les; for larger tables, use the uncorrected formula. Always check the syllabus guidance on when to apply it.
耶茨校正仅用于 2×2 表格;对于更大的表格,使用未校正的公式。务必核对考试大纲中关于何时应用的指导。
6. Chi-squared Goodness-of-Fit Test | 卡方拟合优度检验
A goodness-of-fit test checks whether a sample of categorical data comes from a specific population distribution. For instance, we might test whether a die is fair, or if the number of accidents per week follows a Poisson distribution.
拟合优度检验用于检查分类数据样本是否来自某个特定的总体分布。例如,检验骰子是否公平,或者每周事故数是否服从泊松分布。
ted based on the model, using sample estimates for any unknown parameters. The statistic χ² = Σ (O − E)² / E is then computed and compared against a critical value with ν = k − 1 − p.
假设为 H₀:数据服从所述分布,H₁:数据不服从该分布。期望频数基于该模型计算,未知参数用样本估计值替代。然后计算统计量 χ² = Σ (O − E)² / E,并与自由度为 ν = k − 1 − p 的临界值比较。
It is crucial to make sure that no expected frequency is less than 1, and that the proportion of expected frequencies below 5 is not greater than 20%. If necessary, combine adjacent categories.
确保没有任何期望频数低于 1,且低于 5 的期望频数比例不超过 20% 至关重要。必要时需合并相邻类别。
7. Goodness of Fit: Discrete Uniform Distribution | 拟合优度:离散均匀分布
re n trials and k possible outcomes, the expected frequency for each outcome is E = n / k.
当检验离散均匀分布时,例如公平的六面骰子,假定每个结果等可能。如果有 n 次试验和 k 种可能结果,每种结果的期望频数为 E = n / k。
² exceeds the critical value from χ²₅ (α = 0.05), we have evidence that the die is biased.
没有估计参数,因此 p = 0。自由度为 ν = k − 1。对于投掷 120 次的骰子,检验 H₀:骰子是公平的。如果 χ² 超过 χ²₅(α = 0.05)的临界值,就有骰子有偏的证据。
A common mistake is to forget that the total probability is 1; always check that expected frequencies sum to the sample size.
常见错误是忘记总概率为 1;务必检查期望频数之和是否等于样本大小。
8. Goodness of Fit: Binomial and Poisson Distributions | 拟合优度:二项分布和泊松分布
ters p = 1, so ν = k − 2. For a Poisson distribution, the mean λ is estimated by the sample mean, again resulting in ν = k − 2.
对于试验次数 n 固定的二项分布,我们通常从样本均值估计概率 p。估计参数个数 p = 1,所以 ν = k − 2。对于泊松分布,均值 λ 由样本均值估计,同样 ν = k − 2。
Expected frequencies are calculated using the chosen distribution' ues must be merged, typically grouping tail probabilities into one category so that E ≥ 5.
期望频数使用所选分布的概率质量函数乘以总观测数来计算。期望值很小的类别必须合并,通常将尾部概率归入一个类别以使 E ≥ 5。
λ = 1.8, expected probabilities for counts 0, 1, 2, 3, 4+ are found. After combining where necessary, the χ² statistic is computed and compared with a critical value for the appropriate ν.
示例:一位生物学家统计了 80 个随机样方中的蒲公英数量。样本均值为 1.8。在 H₀ 为 λ = 1.8 的泊松分布下,找到计数 0、1、2、3、4⁺ 的期望概率。经必要合并后,计算 χ² 统计量,并与适当自由度的临界值进行比较。
9. Goodness of Fit: Normal Distribution | 拟合优度:正态分布
When testing for a normal distribution with a continuous data set, the data must first be grouped into intervals. The expected frequency for each interval is obtained by finding the area under the normal curve between the interval boundaries and multiplying by the total sample size.
当检验连续数据集的正态分布时,数据必须首先分组为区间。每个区间的期望频数为该区间边界之间正态曲线下的面积乘以总样本量。
n mean μ and standard deviation σ are usually unknown and are estimated from the sample (x̄ racy, make sure intervals cover the full range, and combine any interval with E < 5 with its neighbour.
总体均值 μ 和标准差 σ 通常未知,并从样本估计(x̄ 和 s)。因此估计了 p = 2 个参数,自由度 ν = k − 3。为保证准确性,确保区间覆盖全范围,并将任何 E < 5 的区间与其相邻区间合并。
The calculations require using standard normal distribution tables or a calculator to find probabilities for the intervals defined by class boundaries. Take care that class boundaries are handled consistently.
计算时需要使用标准正态分布表或计算器求出由组边界定义的区间概率。注意组边界的处理方式要保持一致。
10. Combining Categories | 合并类别
frequencies are sufficiently large. The convention is to ensure that all E ≥ 1 and at least 80% of E ≥ 5.
卡方检验依赖于统计量近似服从 χ² 分布。这一近似仅在期望频数足够大时才可靠。惯例是确保所有 E ≥ 1 且至少 80% 的 E ≥ 5。
If these conditions are not satisfied, categories must be merged. For a goodness-of-fit test, this usually means combining the smallest-probability categories into an 'other' or tail group. For contingency tables, you may need to combine rows or columns, but only if the categories have a natural order or the merging makes logical sense. Always adjust the degrees of freedom after merging.
如果不满足这些条件,必须合并类别。对于拟合优度检验,通常意味着将概率最小的类别合并为一个“其他”或尾组。对于列联表,可能需要合并行或列,但仅在类别有自然顺序或合并在逻辑上合理时进行。合并后务必要调整自由度。
Failing to combine small expecting frequencies can lead to a misleading test result and inflated Type I error rate.
未合并小期望频数会导致检验结果误导并增加第一类错误率。
11. Critical Values and p-values | 临界值与 p 值
Once the χ² statistic is calculated, it must be compared to a critical value from χ² tables at a given significance level (α, usually 1%, 5% or 10%). If χ² > critical value, reject H₀. Alternatively, calculate the p-value using a calculator: if p < α, reject H₀.
一旦计算出 χ² 统计量,必须将其与在给定显著性水平(α,通常为 1%、5% 或 10%)下 χ² 分布表中的临界值比较。若 χ² > 临界值,则拒绝 H₀。也可以使用计算器计算 p 值:若 p < α,则拒绝 H₀。
itical value is 9.488. A calculated χ² of 11.2 leads to rejection, suggesting evidence of an association or poor fit.
例如,若 ν = 4 且 α = 0.05,临界值为 9.488。计算出的 χ² 为 11.2 则导致拒绝,表明有关联或拟合较差的证据。
Remember that a non-significant result does not prove the null hypothesis; it merely suggests that the data are consistent with it.
请记住,不显著的结果并不能证明原假设;它仅表明数据与原假设一致。
12. Assumptions and Conditions | 假设条件与注意事项
For a valid chi-squared test, the following assumptions must be met: data are random and independent; each observation belongs to exactly one category; the variables are categorical; no expected frequency is less than 1; and not more than 20% of expected frequencies are less than 5.
要进行有效的卡方检验,必须满足以下假设:数据是随机且独立的;每个观测值仅属于一个类别;变量为分类变量;没有任何期望频数低于 1;且低于 5 的期望频数比例不超过 20%。
Additionally, apply Yates' es. For goodness of fit, remember to subtract the number of estimated parameters when computing ν. If expected frequencies are too small, combine categories.
此外,对 2×2 列联表应用耶茨校正。对于拟合优度,计算自由度时记得减去估计的参数个数。如果期望频数太小,需合并类别。
Expect to be asked to write hypotheses in words and in context, calculate expected frequencies, perform the test, and interpret the result. Always answer with a clear conclusion referring back to the original problem.
考试中会要求用文字和上下文写假设,计算期望频数,执行检验并解释结果。答案务必给出明确的结论,并联系原问题。
Published by TutorHao | Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

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