math.wiki
Statistics › Statistical inference › Chi-square tests › Tests for independence and homogeneity
Open on the map
Statistics

Tests for independence and homogeneity

A survey sorts adults by age group and by the tea they prefer, and the tea shares look different from one age group to the next. Is that a real association among all adults, or the kind of difference random sampling produces anyway? And when separate samples are taken from three cities instead, how does the same arithmetic answer a different question?

Where you are 3 in Chi-square tests

When you reach for it

Kourosh, Roya and Farhad want to know whether tea preference in Isfahan changes with age. In a two-way table of a sample, association shows as conditional shares that differ from row to row. But a sample’s shares always differ a little, even when the variables are unrelated in the population. The question here is whether the differences are too large to blame on chance.

The Goodness of fit test answered that kind of question for one categorical variable against a claimed distribution. This lesson carries the same statistic, conditions and upper-tail P-value over to a two-way table, where there are two designs.

  • Test for independence. One random sample, each individual classified on two categorical variables. Question: are the two variables associated in the population?
  • Test for homogeneity. Separate random samples from two or more populations, or two or more groups formed by random assignment, each classified on one categorical variable. Question: is that variable’s distribution the same in every population or treatment?

The arithmetic of the two is identical. What differs is the design that produced the table, and so the hypotheses and the conclusion. Choosing among all the procedures is the subject of Choosing the right procedure.

The procedure

Day 1: the test for independence

Hypotheses. For one random sample classified by two variables,

  • H_0: the two variables are independent in the population (there is no association);
  • H_a: the two variables are associated in the population.

Independence means that the conditional distribution of one variable is the same for every value of the other: in the population, the share of adults preferring green tea would be the same in every age group. H_0 is the claim that supplies exact expected counts, which is why it is the null.

Conditions.

  • Random. The data come from one random sample of the population.
  • Ten percent. Sampling is without replacement, so the sample should be at most 10\% of the population, so that the observations behave as independent (the The ten percent condition).
  • Large expected counts. Every expected count in the table is at least 5. As in the goodness-of-fit test, the condition is about the expected counts, not the observed ones.

Expected counts. If the variables are independent, each row should split across the columns in the same proportions as the whole table does. That gives the rule from Expected counts and the chi-square statistic, built from the marginal totals:

E = \frac{\text{row total} \times \text{column total}}{\text{grand total}}

Statistic, degrees of freedom, P-value. Sum over all rc cells (the total row and column are not cells):

\chi^2 = \sum \frac{(O - E)^2}{E}, \qquad \text{df} = (r - 1)(c - 1)

Expected counts and the chi-square statistic shows why the df counts the cells that are free once the margins are fixed. The P-value is the area to the right of \chi^2 under the chi-square curve with that df: large values only are evidence against H_0, since every gap, in either direction, raises the statistic.

Conclusion. If P \le \alpha, there is convincing evidence that the two variables are associated in the population. If P > \alpha, there is not convincing evidence of an association, which is not evidence that the variables are independent.

Day 2: the test for homogeneity

Design. Now the table comes from separate random samples, one from each of several populations (or from groups created by randomly assigning subjects to treatments), and every individual is classified on one variable. The row totals are the sample sizes, fixed by the design before any data were collected.

Hypotheses.

  • H_0: the distribution of the variable is the same in every population (or under every treatment);
  • H_a: the distribution is not the same in every population; at least one differs.

Conditions. Each sample is random, or the groups come from random assignment; the samples are independent of each other; each sample is at most 10\% of its own population when sampling without replacement (this check does not arise for randomized groups of volunteers); every expected count is at least 5.

Same arithmetic. If every population had the same distribution, the best estimate of it is the pooled one, the column totals divided by the grand total. Each sample’s expected counts are that pooled distribution times its sample size, which is row total times column total over grand total again. The statistic, df and P-value are computed exactly as on Day 1.

Following up. A rejection says only that the distributions are not all the same. Two descriptions say where they differ: the largest components \displaystyle \frac{(O - E)^2}{E}, with the sign of O - E telling which way, and the conditional percentages of each sample, compared side by side or drawn as a segmented bar graph. Neither is a separate test.

Day 3: telling them apart, two by two tables, output, and cause

Which test. The table alone cannot say. Ask how the data were gathered. One sample, two variables recorded on each individual, nothing fixed but the overall n: independence. Several samples or treatment groups whose sizes were set in advance, one variable recorded: homogeneity. The same two-way table can arise either way, and it gets the same \chi^2 and P-value either way; only the hypotheses and the wording of the conclusion change.

The two by two case. With two rows and two columns, \text{df} = 1, and the chi-square statistic equals the square of the pooled z statistic of the Test for a difference of proportions. The two P-values are equal, the chi-square P-value matching the two-sided z test. A one-sided question (is the proportion higher in the first group?) needs the z test, since \chi^2 squares away the direction.

Technology. A graphing calculator’s `χ²-Test` takes the observed table as a matrix, usually `[A]`, with the categories of one variable as rows and the other as columns, totals left out. It returns \chi^2, the P-value p and the df, and stores the expected counts in a second matrix, usually `[B]`, which is where the large expected counts condition is checked.

Association and cause. A test that rejects shows association, not cause. In an observational study, a third variable may drive both (see Correlation is not causation: lurking and confounding variables). Only when the treatments were assigned at random (Random assignment and confounding) does a rejection give evidence that the treatment caused the difference, and then only for subjects like those in the study unless they were also a random sample.

Worked examples

Example 1

Day 1: tea preference by age in Isfahan

Kourosh takes a random sample of 500 adults in Isfahan and records each one’s age group and preferred tea (made-up data):

ageblackgreenherbal
18-34806040
35-541004535
55+902030
total270125105

The row totals are 180, 180 and 140, and the grand total is 500.

Is there convincing evidence, at \alpha = 0.05, of an association between age group and preferred tea among adults in Isfahan?

Solution

Hypotheses. H_0: age group and preferred tea are independent among adults in Isfahan. H_a: age group and preferred tea are associated among adults in Isfahan.

Conditions. The data are one random sample. The adults of Isfahan number far more than 5{,}000, so 500 is under 10\% of them. The expected count for black tea among the youngest group is

E = \frac{180 \times 270}{500} = 97.2

and the full table of expected counts is

ageblackgreenherbal
18-3497.24537.8
35-5497.24537.8
55+75.63529.4

Each row adds to its row total, and the smallest count is 29.4, so every expected count is at least 5.

Statistic. The nine components \displaystyle \frac{(O - E)^2}{E} are

ageblackgreenherbal
18-343.0445.0000.128
35-540.08100.207
55+2.7436.4290.012

and, added without rounding, \chi^2 \approx 17.643. With 3 age groups and 3 teas, \text{df} = (3 - 1)(3 - 1) = 4.

P-value. The area to the right of 17.643 under the chi-square curve with 4 degrees of freedom is about 0.0014.

44.4% black 33.3% green 22.2% herbal 18 to 34 55.6% 25.0% 19.4% 35 to 54 64.3% 14.3% 21.4% 55 and over 0% 25% 50% 75% 100%
Figure 1Preferred tea within each age group of the Isfahan sample (made-up data). If age and tea preference were independent, the three bars would differ only by chance.

Conclusion. Since 0.0014 \le 0.05, reject H_0. There is convincing evidence that age group and preferred tea are associated among adults in Isfahan. In the sample, the share preferring green tea falls from 33.3\% of the youngest group to 14.3\% of the oldest, while the share preferring black tea rises from 44.4\% to 64.3\%. If the variables were independent, a statistic this large would arise in only about 14 samples in 10{,}000.

Example 2

Day 1: when the expected counts are too small

Farhad repeats the survey with a random sample of only 60 adults. His row totals are 25, 20 and 15 (youngest to oldest) and his column totals are 33 black, 15 green and 12 herbal. Check the large expected counts condition, and say what could be done if it fails.

Solution

The expected counts depend only on the margins, so they can be checked before looking at a single cell. The smallest row total times the smallest column total gives the smallest expected count:

E = \frac{15 \times 12}{60} = 3

which is below 5. The others below 5 are \displaystyle \frac{15 \times 15}{60} = 3.75 (oldest, green) and \displaystyle \frac{20 \times 12}{60} = 4 (middle, herbal). The condition fails, and the chi-square curve cannot be trusted to give the P-value.

One remedy, chosen for its meaning before any statistic is computed, is to combine green and herbal into one column, “green or herbal”, with total 27. Its smallest expected count is \displaystyle \frac{15 \times 27}{60} = 6.75, and the black column’s smallest is \displaystyle \frac{15 \times 33}{60} = 8.25, so every expected count is now at least 5. The table is 3 by 2, with \text{df} = (3 - 1)(2 - 1) = 2, and the test now asks a coarser question: whether age is associated with preferring black tea over the rest. The other remedy is a larger sample.

Example 3

Day 2: bazaar shoppers in three cities

Roya takes separate random samples of bazaar shoppers in three cities, 200 in Isfahan, 150 in Shiraz and 250 in Tabriz, and asks which of three goods each shopper bought most on that visit. Each of the three bazaars has many thousands of shoppers, far more than ten times its sample (made-up data):

cityspicescarpetssweets
Isfahan705080
Shiraz603555
Tabriz809575
total210180210

The row totals are the sample sizes, and the grand total is 600.

Test at \alpha = 0.05 whether the distribution of the good bought most is the same for bazaar shoppers in the three cities.

Solution

Hypotheses. H_0: the distribution of the good bought most is the same for bazaar shoppers in Isfahan, Shiraz and Tabriz. H_a: the distribution is not the same in all three cities.

Conditions. Three separate random samples, one per city, chosen independently of each other. Since each bazaar has far more than ten times its sample in shoppers, as the problem states, each sample is under 10\% of its population. The expected counts:

cityspicescarpetssweets
Isfahan706070
Shiraz52.54552.5
Tabriz87.57587.5

For example, Shiraz and spices is \displaystyle \frac{150 \times 210}{600} = 52.5: if every city had the pooled distribution, 35\% spices, 30\% carpets and 35\% sweets, then 35\% of Shiraz’s 150 shoppers would choose spices. All are at least 5.

Statistic. The components are

cityspicescarpetssweets
Isfahan01.6671.429
Shiraz1.0712.2220.119
Tabriz0.6435.3331.786

so \chi^2 \approx 14.270, with \text{df} = (3 - 1)(3 - 1) = 4 and a P-value of about 0.0065.

Conclusion. Since 0.0065 \le 0.05, reject H_0. There is convincing evidence that the distribution of the good bought most is not the same for bazaar shoppers in the three cities. Compare Example 1: that conclusion was about one population and two variables; this one is about three populations and one variable.

Example 4

Day 2: where the cities differ

Follow up the rejection in Example 3.

Solution

The largest component, 5.333, is Tabriz and carpets, where O - E = 95 - 75 = 20: more Tabriz shoppers bought carpets most than the pooled distribution predicts. The next two are also in the carpet column, Shiraz (2.222, with 35 against 45 expected, fewer) and Isfahan (1.667, with 50 against 60, fewer). The carpet column gives 1.667 + 2.222 + 5.333 = 9.222, about 65\% of the statistic.

The conditional percentages tell the same story in a form that reads directly:

cityspicescarpetssweets
Isfahan35.0\%25.0\%40.0\%
Shiraz40.0\%23.3\%36.7\%
Tabriz32.0\%38.0\%30.0\%
35.0% spices 25.0% carpets 40.0% sweets Isfahan 40.0% 23.3% 36.7% Shiraz 32.0% 38.0% 30.0% Tabriz 0% 25% 50% 75% 100%
Figure 2The good bought most, within each city’s sample of bazaar shoppers (made-up data). The wide carpet segment for Tabriz marks the largest single component of the chi-square statistic.

In context: the main difference is that a larger share of Tabriz’s bazaar shoppers buy carpets most, 38\% against about a quarter in the other two cities, with Tabriz’s sweets share correspondingly lower. Isfahan and Shiraz look alike. This is a description of the samples that points at where the populations differ; it is not a separate test of each cell.

Example 5

Day 3: which test does the design call for?

Name the test, state H_0 in context and give the df for each design (all made-up).

(a) Kourosh takes a random sample of 400 adults in Shiraz and records whether each lives in the old city or the new city, and how often each visits the bazaar (weekly, monthly, rarely).

(b) Kourosh instead takes a random sample of 200 adults from the old city and a separate random sample of 200 from the new city, and records how often each visits the bazaar.

(c) Farhad randomly assigns 120 volunteers to tea brewed for 3, 5 or 8 minutes, 40 to each, and records whether each calls it too weak, just right or too strong.

Solution

(a) One sample, two variables recorded on each adult, and neither margin fixed in advance: a test for independence. H_0: where an adult in Shiraz lives (old or new city) and how often the adult visits the bazaar are independent. The table is 2 by 3, so \text{df} = (2 - 1)(3 - 1) = 2.

(b) Same variables, same table shape, but the 200 and 200 were fixed by the design: two samples from two populations, one variable. A test for homogeneity. H_0: the distribution of how often adults visit the bazaar is the same in the old city and the new city. Again \text{df} = 2. The split 200 and 200 says nothing about how many adults live in each part of the city, which is why “is where one lives independent of visiting” is the wrong question for this design.

(c) Three groups formed by random assignment, one response variable: a test for homogeneity. H_0: the distribution of taste ratings is the same under all three brewing times (for volunteers like these). The table is 3 by 3, so \text{df} = 4. Because the brewing times were assigned at random, a rejection here would be evidence that brewing time causes a change in the ratings.

Example 6

Day 3: a two by two table and the z test

At his tea house in Isfahan, Kourosh randomly assigns 300 customers who agree to take part to two menus, 150 each: a printed menu with pictures, or the same menu read aloud by the server. Of the printed-menu group, 54 order dessert; of the spoken-menu group, 36 (made-up data). Carry out the chi-square test at \alpha = 0.05, show that its statistic is the square of the two-sample z statistic, and say what the result allows Kourosh to conclude.

Solution

The table has rows printed and spoken, columns dessert (90 in all) and no dessert (210). H_0: the distribution of ordering dessert is the same for both menus; H_a: it differs. Random assignment; expected counts \displaystyle \frac{150 \times 90}{300} = 45 and \displaystyle \frac{150 \times 210}{300} = 105 in each row, all at least 5.

\begin{aligned} \chi^2 &= 2\left(\frac{9^2}{45} + \frac{9^2}{105}\right) \\ &= 2(1.8 + 0.771) \approx 5.143 \end{aligned}

with \text{df} = 1 and a P-value of about 0.023.

For the z test, \displaystyle \hat{p}_1 = \frac{54}{150} = 0.36, \displaystyle \hat{p}_2 = \frac{36}{150} = 0.24, and the pooled proportion is \displaystyle \hat{p}_c = \frac{90}{300} = 0.3:

z = \frac{0.36 - 0.24}{\sqrt{0.3(0.7)\left(\frac{1}{150} + \frac{1}{150}\right)}} \approx 2.268

and z^2 \approx 5.143, the same as \chi^2. The two-sided P-value of the z test is also about 0.023.

Since 0.023 \le 0.05, reject H_0. Because the menus were assigned at random, this is convincing evidence that the printed menu with pictures causes more dessert orders than the spoken menu, for customers like these volunteers. They were not a random sample of anyone, so extending the result to all tea-house customers rests on judgment, not on the test.

Example 7

Day 3: reading calculator output

Roya takes a random sample of 300 students at a university in Tabriz and records each one’s field (science, humanities, arts) and whether the student mostly drinks tea or coffee (made-up data): science 70 tea and 50 coffee, humanities 66 and 34, arts 44 and 36. She enters the 3 by 2 table into `[A]` and runs `χ²-Test`. The screen shows \chi^2 = 2.472, p = 0.2905, df = 2. Check one expected count and one component by hand, state the conclusion at \alpha = 0.05, and say what changes if Farhad enters the table with rows and columns swapped.

Solution

The margins are 120, 100 and 80 students by field, and 180 tea and 120 coffee. The calculator’s `[B]` should hold, for science and tea,

E = \frac{120 \times 180}{300} = 72

and the whole of `[B]` is 72, 48; 60, 40; 48, 32, all at least 5. The science and tea component is \displaystyle \frac{(70 - 72)^2}{72} \approx 0.056. The df is (3 - 1)(2 - 1) = 2, matching the screen.

Since p = 0.2905 > 0.05, fail to reject H_0. There is not convincing evidence of an association between field of study and drinking mostly tea or coffee among students at this university. This does not show the two are independent.

Swapping rows and columns gives a 2 by 3 matrix with the same cells. Each expected count is still row total times column total over 300, the components are the same numbers in new places, and (2 - 1)(3 - 1) = 2. The output is identical: the test treats the two variables symmetrically.

Boundaries

  • Counts of individuals, each counted once. The cells hold counts, never percentages or means, and the categories of each variable must not overlap and must cover every individual.
  • The conditions. Random sampling or random assignment; independent samples for homogeneity; at most 10\% of each population when sampling without replacement; every expected count at least 5. When an expected count is small, combine categories for a reason fixed in advance, or collect more data.
  • No direction. The P-value is an upper-tail area and H_a has no direction. Which cells differ, and which way, is read from the components and conditional percentages as description.
  • Two by two. There \chi^2 = z^2 for the pooled two-proportion z test, and the chi-square P-value equals the two-sided one. A one-sided alternative needs the z test.
  • Association, not cause. Without random assignment, a rejection shows association only. A failure to reject is never evidence of independence or of identical distributions.
  • Large samples detect small differences. With a very large sample a trivial difference can give a tiny P-value; whether it matters is a separate judgment.

Where this goes next

These two tests finish the chi-square family: one variable against a claim, two variables in one population, one variable across several. Deciding which of these, or which proportion or mean procedure, a study calls for, from the number of samples, the kind of variable and the design, is Choosing the right procedure.

Exercises

All data are made up. Give P-values from technology. Use \alpha = 0.05 unless a part says otherwise.

Day 1: the test for independence

  1. A random sample of 400 adults in Tabriz records each one’s usual way to get around (walk, bus, car) and whether the adult prefers to shop in the morning or the evening. State H_0 and H_a and give the df.
  2. In a two-way table with grand total 400, find the expected count of a cell whose row total is 120 and column total is 150, and of a cell whose row total is 80 and column total is 250.
  3. A random sample of 240 adults in Tabriz gives, for those who take a sugar cube with tea, 70 black, 20 green and 30 herbal, and for those who do not, 50 black, 40 green and 30 herbal. Carry out the test for independence.
  4. Kourosh samples 500 adults from a neighborhood of 4{,}000 adults. Which condition is at risk, and does it hold?
  5. A test for independence on a table with 4 rows and 5 columns gives \chi^2 = 20.1. Find the df and the P-value, and give the decision at \alpha = 0.05 and at \alpha = 0.10.
  6. A table has grand total 200. Its smallest row total is 18 and its smallest column total is 40. Does the large expected counts condition hold?
  7. A random sample of 180 adults in Shiraz, 60 in each age group (18 to 34, 35 to 54, 55 and over), gives the numbers who drink tea after dinner as 30, 36 and 40. Carry out the test for independence between age group and drinking tea after dinner.

Day 2: the test for homogeneity

  1. Farhad takes separate random samples of 100 bazaar shoppers in each of Isfahan, Shiraz and Tabriz and records how each paid (cash, card, phone). State H_0 and H_a and give the df. If 120 of the 300 paid cash, what is the expected count of cash payers in each city?
  2. Separate random samples of 150 shoppers in Tabriz and 150 in Shiraz give the time of their bazaar visit as morning, afternoon or evening: Tabriz 60, 50, 40; Shiraz 40, 50, 60. Test whether the distribution of visit time is the same in the two cities.
  3. Follow up Exercise 9 with the components and the conditional percentages.
  4. Roya randomly assigns 150 volunteers at a tea house to three cup sizes, 50 each (small, medium, large), and records whether each asks for a refill. The numbers asking are 15, 25 and 35. Carry out the test, and say whether cup size can be said to cause the difference.
  5. Which sentence correctly states the conclusion of Example 3? (a) “City and good bought most are independent.” (b) “The distribution of the good bought most is not the same in all three cities.” (c) “Tabriz shoppers buy more carpets because they live in Tabriz.”
  6. In Example 3, 250 of the 600 shoppers are from Tabriz. Why does this fraction say nothing about the share of all bazaar shoppers who shop in Tabriz?

Day 3: design, two by two tables, output and cause

  1. A random sample of 600 households in Isfahan records the number of children (0, 1, 2 or more) and whether the household owns a car. Which test, and what df?
  2. Farhad takes a random sample of 80 carpets from each of four workshops and records whether each carpet’s dyes are natural or synthetic. Which test, and what df?
  3. Separate random samples of 200 shoppers in Isfahan and 200 in Tabriz find 64 and 44 who bought saffron. Find \chi^2, the pooled z statistic and the P-value, and show that \chi^2 = z^2.
  4. A calculator runs `χ²-Test` on the observed matrix with rows 30, 20 and 20, 30 and shows \chi^2 = 4, p = 0.0455, df = 1. Check the expected counts and the statistic by hand.
  5. In Example 1, can Kourosh conclude that growing older makes people turn from green tea to black? Explain.
  6. In Exercise 16, a researcher asked in advance whether Isfahan shoppers are more likely than Tabriz shoppers to buy saffron. Which test answers that, and what is its P-value?

Reasoning

  1. Explain why the test for independence and the test for homogeneity give the same \chi^2 for the same table.
  2. Explain why the conclusion of a test for homogeneity is about several populations, while that of a test for independence is about one.
  3. Explain why a test for homogeneity of samples whose sizes were fixed in advance cannot be read as a test of whether the sampling variable is independent of the response in a combined population.
  4. A test for independence on an observational sample rejects with a tiny P-value. Explain why this is not evidence that one variable causes the other, and what design could give such evidence.
Answers
  1. H_0: way of getting around and preferred shopping time are independent among adults in Tabriz; H_a: they are associated. The table is 3 by 2, so \text{df} = (3 - 1)(2 - 1) = 2.
  2. \displaystyle \frac{120 \times 150}{400} = 45 and \displaystyle \frac{80 \times 250}{400} = 50.
  3. Margins: 120 and 120; 120 black, 60 green, 60 herbal. Expected 60, 30, 30 in each row, all at least 5; one random sample, well under 10\% of Tabriz adults. \displaystyle \chi^2 = 2\left(\frac{100}{60} + \frac{100}{30} + 0\right) = 10, \text{df} = 2, P-value about 0.0067. Reject: convincing evidence that taking sugar with tea and preferred tea are associated among adults in Tabriz.
  4. The ten percent condition. 10\% of 4{,}000 is 400, and 500 > 400, so it fails.
  5. \text{df} = (4 - 1)(5 - 1) = 12; P-value about 0.065. At \alpha = 0.05 fail to reject; at \alpha = 0.10 reject.
  6. No. The smallest expected count is \displaystyle \frac{18 \times 40}{200} = 3.6 < 5.
  7. Tea after dinner: 106 in all, so expected \displaystyle \frac{60 \times 106}{180} \approx 35.333 yes and 24.667 no in each age group, all at least 5. \chi^2 \approx 3.488, \text{df} = 2, P-value about 0.175. Fail to reject: not convincing evidence of an association between age group and drinking tea after dinner among adults in Shiraz.
  8. H_0: the distribution of payment method is the same for bazaar shoppers in the three cities; H_a: it is not the same in all three. \text{df} = (3 - 1)(3 - 1) = 4. Expected cash payers \displaystyle \frac{100 \times 120}{300} = 40 in each city.
  9. Column totals 100 each, so every expected count is 50. \displaystyle \chi^2 = \frac{100}{50} + 0 + \frac{100}{50} + \frac{100}{50} + 0 + \frac{100}{50} = 8, \text{df} = 2, P-value about 0.018. Reject: convincing evidence that the distribution of visit time differs between Tabriz and Shiraz.
  10. Morning and evening each give components of 2 in both cities; afternoon gives 0. Tabriz: 40\% morning, 33.3\% afternoon, 26.7\% evening; Shiraz: 26.7\%, 33.3\%, 40\%. Tabriz shoppers lean to the morning, Shiraz shoppers to the evening.
  11. Expected 25 asking and 25 not in each group. \chi^2 = 4 + 0 + 4 + 4 + 0 + 4 = 16, \text{df} = 2, P-value about 0.0003. Reject. Yes: the sizes were assigned at random, so this is evidence that cup size affects asking for a refill, for volunteers like these.
  12. (b). (a) states H_0, which was rejected, and is the wrong question for separate samples; (c) claims a cause no observational study can show.
  13. Roya chose the sample sizes 200, 150 and 250 herself, so the row totals reflect her design, not the populations.
  14. One sample, two variables: test for independence. The table is 3 by 2, \text{df} = 2.
  15. Four separate samples, one variable: test for homogeneity. The table is 4 by 2, \text{df} = 3.
  16. Expected 54 and 146 in each row. \displaystyle \chi^2 = 2\left(\frac{100}{54} + \frac{100}{146}\right) \approx 5.074, \text{df} = 1. With \hat{p}_1 = 0.32, \hat{p}_2 = 0.22, \hat{p}_c = 0.27: \displaystyle z = \frac{0.10}{\sqrt{0.27(0.73)(0.01)}} \approx 2.252 and z^2 \approx 5.074. P-value about 0.024 for both.
  17. Margins are all 50 out of 100, so every expected count is \displaystyle \frac{50 \times 50}{100} = 25. Each component is \displaystyle \frac{5^2}{25} = 1, and \chi^2 = 4 with \text{df} = (2 - 1)(2 - 1) = 1.
  18. No. The sample is observational, and it compares different people at one time: older adults may differ from younger ones in what tea was common when they were young, not because of aging. The test shows association only.
  19. The one-sided two-sample z test with H_a\colon p_1 > p_2: z \approx 2.252, P-value about 0.012, half the two-sided value.
  20. The expected counts, row total times column total over grand total, are the same in both: for independence they come from the product of the two marginal shares, for homogeneity from applying the pooled distribution to each sample. Same expected counts and the same observed cells give the same components and sum.
  21. In homogeneity each row is a sample from its own population (or a treatment group), and the question is whether those populations share a distribution. In independence one sample comes from one population, and the question is about two variables within it.
  22. The row totals are set by the researcher, so they carry no information about how the populations compare in size; there is no single combined population that the sample represents, and joint shares such as “the share of all shoppers who are in Tabriz and buy carpets” cannot be estimated.
  23. A confounding variable may be associated with both variables and produce the association. Random assignment of the explanatory variable to subjects, as in Example 6, balances such variables across groups, so a rejection then supports cause.
kg1128 · updated 2026-10-20 · CC-BY-SA-4.0