Test of independence for a 2×2 contingency table

独立性检验(2×2 列联表)

How does the test of independence work for a 2 by 2 table?

The null hypothesis says the two categorical variables are independent; equivalently the conditional probabilities agree; the test compares observed and expected counts.

SkillKP004468

Sign in to read the whole lesson, with 20 exercises

Sign in / Sign up

Mastery goals

  • Can state the null hypothesis H₀ that two categorical variables are independent, interpret it in context and explain that it is the same as two conditional probabilities being equal
  • Can compute χ² = n(ad − bc)² / [(a + b)(c + d)(a + c)(b + d)] from a 2×2 contingency table and compare it with the critical value x_α for a small probability α to reach a conclusion
  • Can explain that rejecting H₀ this way is wrong with probability at most α, that otherwise there is not enough evidence and the variables may be regarded as independent, and compare the relevant frequencies to describe how one variable affects the other; and can explain how a test of independence is like and unlike proof by contradiction

However, we cannot use the sizes of the values in ③ directly to infer whether holds; we need a statistic that is both reasonable and has a distribution that can be worked out. In general, if the expected value of a frequency is large, the absolute value of the corresponding difference in ③ also tends to be large; if the expected value is small, the absolute value of the corresponding difference also tends to be small. To balance this effect reasonably, we square the absolute values of the four differences, divide each by the corresponding expected value and add them up, which gives the statistic

This expression simplifies to

Statisticians suggest using the size of the value of the random variable as the basis for deciding whether the null hypothesis holds: when it is fairly large, infer that does not hold; otherwise consider that holds. So how large must be before we can infer that does not hold? In other words, how do we fix a standard for judging the size of ?

By the rule that an event of small probability is unlikely to happen in a single trial, this idea can be carried out by fixing an event of small probability that contradicts . Assuming , for simple random sampling with replacement, when the sample size is large enough, statisticians have found an approximate distribution of . Ignoring the error between the actual distribution of and this approximate distribution, for any small probability value we can find a corresponding positive real number such that

is called the critical value of ; this critical value can serve as the standard for judging the size of . The smaller the probability value , the larger the critical value . When the population is very large, sampling with or without replacement makes little difference to the distribution of , so in applications sampling is often not strictly required to be with replacement.

From ④, as long as the probability value is small enough, the event is unlikely to happen when holds. By this rule, if the event does happen, we can infer that does not hold. This inference may be wrong, but the probability of being wrong is at most .

The test rule based on the small probability value is:

when , we infer that does not hold, that is, we consider that and are not independent, and the probability that this inference is wrong is at most ;

when , we do not have enough evidence to infer that does not hold, and we may consider that and are independent.

This method of using the value of to infer whether the categorical variables and are independent is called the test of independence (read “chi-square test of independence”), or the test of independence for short.

Table 8.3-4 gives commonly used small probability values in the test of independence and the corresponding critical values.

Table 8.3-4

For example, for the small probability value we have the following test rule:

(1) when , we infer that does not hold, that is, we consider that and are not independent, and the probability that this inference is wrong is at most ;

(2) when , we do not have enough evidence to infer that does not hold, and we may consider that and are independent.

Number line01234567891011123.841
The test rule for on a number line: the marked point is the critical value , and the bracket marks the range . When the value of falls in this range, we infer that does not hold; when it falls to the left of , we do not have enough evidence to infer that does not hold.

Example 2 Using the test of independence with small probability value , analyse the sample data of Example 1. Can we infer from them that the proportions of students with excellent mathematics results at the two schools differ?

Solution: The null hypothesis is

: the categorical variables and are independent, that is, the proportions of students with excellent mathematics results at the two schools are the same.

From the data in Table 8.3-2,

By the test of independence with small probability value , we do not have enough evidence to infer that does not hold, so we may consider that holds, that is, the proportions of students with excellent mathematics results at the two schools are the same.

In fact, as said before, Example 1 concluded that the proportions differ only because two relative frequencies in one sample differ, without considering mistakes that the randomness of the sample may cause, so the inference there was not well supported. In Example 2 we tested the null hypothesis with the test of independence. The calculation shows that is less than the critical value for , so we consider that there is not enough evidence to infer that does not hold; we accept and conclude that the proportions of students with excellent mathematics results at the two schools do not differ significantly. This result means that the difference between the two relative frequencies in the sample data is very likely caused by the randomness of the sample. So the conclusion that the proportions differ, drawn only from the difference between the relative frequencies, is not reliable.

When we accept the null hypothesis , we may also be wrong. We do not know the probability of making this kind of mistake, but we know that the larger is, the smaller is.

So, compared with an inference that simply compares two relative frequencies, the result of the test of independence is more rational and more complete, and better supported by theory.

Example 3 A children's hospital treats indigestion in young children with two treatments, A and B. Treatment results are checked by simple random sampling with replacement, giving these data: of the children sampled who received treatment A, were not cured and were cured; of the children sampled who received treatment B, were not cured and were cured. Using the test of independence with small probability value , analyse whether treatment B works better than treatment A.

Solution: The null hypothesis is

: treatment and outcome are independent, that is, the two treatments work equally well.

Organising the data gives the contingency table of the two treatments, Table 8.3-5.

Table 8.3-5 (number of children)

TreatmentNot curedCuredTotal
A
B
Total

From the data in the contingency table,

By the test of independence with small probability value , we do not have enough evidence to infer that does not hold, so we may consider that holds, that is, the two treatments work equally well.

Example 4 To study whether smoking is related to lung cancer, a cancer research institute surveyed people by simple random sampling with replacement and obtained the classified counts of the paired observed data shown in Table 8.3-6. Using the test of independence with small probability value , analyse whether smoking increases the risk of lung cancer.

Table 8.3-6 (number of people)

SmokingWithout lung cancerWith lung cancerTotal
Non-smokers
Smokers
Total

Solution: The null hypothesis is

: smoking and having lung cancer are not associated.

From the data in the contingency table,

By the test of independence with small probability value , we infer that does not hold, that is, we consider that smoking and having lung cancer are associated, and the probability that this inference is wrong is at most .

From the data in Table 8.3-6, among non-smokers the relative frequencies of not having and having lung cancer are

among smokers the relative frequencies of not having and having lung cancer are

From

we see that among the people surveyed, the relative frequency of lung cancer for smokers is more than times that for non-smokers. So, by the principle that frequency settles down to probability, we may consider that the probability of lung cancer for smokers is clearly greater than for non-smokers, that is, smoking makes lung cancer more likely.

Summing up the examples above, using the test of independence to solve a real problem roughly involves these main steps:

(1) State the null hypothesis : and are independent, and explain what it means in the problem.

(2) Organise the sample data into a contingency table, calculate the value of , and compare it with the critical value .

(3) Reach a conclusion by the test rule.

(4) If and are not independent, then as needed, compare the corresponding relative frequencies to analyse how and affect each other.

Note that these steps can be adjusted to suit different situations. For example, sometimes the contingency table of sample data on the categorical variables is given in the problem.

Simply put, proof by contradiction derives a contradiction under some assumption and so proves that does not hold; the test of independence, under the null hypothesis , infers that does not hold if an event of small probability that contradicts happens, and the probability that this inference is wrong is at most that small probability. Moreover, when all the logical reasoning is correct, proof by contradiction makes no mistakes, but the test of independence can make random mistakes.

The essence of the test of independence is to compare the differences between observed values and expected values; the size of this difference, represented by , is judged by fixing a suitable small probability value. This is a very important method of inference: it is very widely used, and it has also opened up a new way of thinking for people to understand the world.

Summary

1. Structure of the chapter

Paired dataNumerical variablesCorrelationSample correlation coefficientSimple linear regression modelCategorical variables2×2 contingency tableTest of independence
Structure of the chapter: paired data are of two kinds, numerical variables and categorical variables. Numerical variables lead to correlation, which leads to the sample correlation coefficient and the simple linear regression model; categorical variables lead to the contingency table, which leads to the test of independence.

2. Looking back and thinking

In the compulsory course we learnt to infer statistical features of a variable from sample observations; in this chapter we learnt to infer the relationship between two variables from paired sample observations. The main idea running through the chapter is still estimating the population from a sample.

For two numerical variables, the sample scatter plot describes their correlation visually, and the sample correlation coefficient measures the degree of their linear correlation quantitatively, so that we can infer how the two variables are correlated. For correlated variables we often use a regression model to describe how one variable affects the other, and different kinds of correlation call for different regression models. The simple linear regression model is mainly used for two linearly correlated variables: usually we estimate the parameters of the model from the sample data by the method of least squares and obtain the empirical regression model; then we evaluate and improve the model by analysing the residuals, so that the model keeps getting better. If the model describes the relationship of the two variables fairly well, we can predict the value of the response from the value of the explanatory variable and use it to help make decisions.

For two categorical variables, a contingency table shows statistical information about how they are related, so that we can infer visually whether the two variables are associated. The test of independence makes a statistical inference about the association between variables. This inference rests on the principle of small probability, which differs from proof by contradiction, which rests on a logical contradiction. To make the probability of wrongly rejecting the null hypothesis smaller, we take a smaller probability value .

Both regression analysis and the test of independence estimate or infer from paired sample observations, using inductive reasoning, so their conclusions may be wrong. This is a feature of statistical conclusions obtained by estimating the population from a sample, and it reflects the nature of statistics. In fact, statistics studies random phenomena and looks for the regularity behind chance: even with the same data, people may, according to their own understanding of the background, use different inference methods and reach different conclusions, and the conclusions are judged as “good” or “bad”. Of course, the better the method, the smaller the probability that the conclusion is wrong. So for a concrete problem we should choose suitable, good statistical methods as far as possible.

Review the whole chapter with the following questions in mind!

  1. Give an example of how paired data are obtained.
  1. Use an example to explain what a correlation is. How does a correlation differ from a functional relationship?
  1. Can the sample correlation coefficient and regression models measure how strong a non-linear correlation between two variables is?
  1. In the simple linear regression model, what is the statistical meaning of the parameters and ?
  1. What is the principle of least squares? Describe its basic idea.
  1. Give an example of describing the association between two categorical variables in the language of conditional probability. What is the key point?
  1. What is the essential difference between categorical variables and numerical variables?
  1. What is the basic idea of the test of independence? In what ways is it like proof by contradiction, and in what ways is it different?
  1. By the test of independence at , if the conclusion is that the two variables are associated, how should we understand it? And if the conclusion is that they are not associated, how should we understand that?
  1. After studying this chapter, what new understanding do you have of the difference between statistical methods and deterministic methods?

Related points

All points in this topic

Cite this page: Test of independence for a 2×2 contingency table · KnowledgeTree (知识树), https://www.knowledgetree.world/en/kp/KP004468