Chapter page 26 / 3818 Inference for two-way tables
English

18  Inference for two-way tables

In Chapter 17 our focus was on the difference in proportions, a statistic calculated from finding the success proportions (from the binary response variable) measured across two groups (the binary explanatory variable). As we will see in the examples below, sometimes the explanatory or response variables have more than two possible options. In that setting, a difference across two groups is not sufficient, and the proportion of “success” is not well defined if there are 3 or 4 or more possible response levels. The primary way to summarize categorical data where the explanatory and response variables both have 2 or more levels is through a two-way table as in Table 18.1.

Note that with two-way tables, there is not an obvious single parameter of interest. Instead, research questions usually focus on how the proportions of the response variable changes (or not) across the different levels of the explanatory variable. Because there is not a population parameter to estimate, bootstrapping to find the standard error of the estimate is not meaningful. As such, for two-way tables, we will focus on the randomization test and corresponding mathematical approximation (and not bootstrapping).

18.1 Randomization test of independence

We all buy used products – cars, computers, textbooks, and so on – and we sometimes assume the sellers of those products will be forthright about any underlying problems with what they’re selling. This is not something we should take for granted. Researchers recruited 219 participants in a study where they would sell a used iPod1 that was known to have frozen twice in the past. The participants were incentivized to get as much money as they could for the iPod since they would receive a 5% cut of the sale on top of $10 for participating. The researchers wanted to understand what types of questions would elicit the seller to disclose the freezing issue.

Unbeknownst to the participants who were the sellers in the study, the buyers were collaborating with the researchers to evaluate the influence of different questions on the likelihood of getting the sellers to disclose the past issues with the iPod. The scripted buyers started with “Okay, I guess I’m supposed to go first. So you’ve had the iPod for 2 years …” and ended with one of three questions:

  • General: What can you tell me about it?
  • Positive Assumption: It does not have any problems, does it?
  • Negative Assumption: What problems does it have?

The question is the treatment given to the sellers, and the response is whether the question prompted them to disclose the freezing issue with the iPod. The results are shown in Table 18.1, and the data suggest that asking the, What problems does it have?, was the most effective at getting the seller to disclose the past freezing issues. However, you should also be asking yourself: could we see these results due to chance alone if there really is no difference in the question asked, or is this in fact evidence that some questions are more effective for getting at the truth?

Table 18.1: Summary of the iPod study, where a question was posed to the study participant who acted.
Question Disclose problem Hide problem Total
General 2 71 73
Positive assumption 23 50 73
Negative assumption 36 37 73
Total 61 158 219

The ask data can be found in the openintro R package.

The hypothesis test for the iPod experiment is really about assessing whether there is convincing evidence that there was a difference in the success rates that each question had on getting the participant to disclose the problem with the iPod. In other words, the goal is to check whether the buyer’s question was independent of whether the seller disclosed a problem.

18.1.1 Expected counts in two-way tables

While we would not expect the number of disclosures to be exactly the same across the three question classes, the rate of disclosure seems substantially different across the three groups. In order to investigate whether the differences in rates is due to natural variability in people’s honesty or due to a treatment effect (i.e., the question causing the differences), we need to compute estimated counts for each cell in a two-way table.

From the experiment, we can compute the proportion of all sellers who disclosed the freezing problem as \(61/219 = 0.2785.\) If there really is no difference among the questions and 27.85% of sellers were going to disclose the freezing problem no matter the question they were asked, how many of the 73 people in the General group would we have expected to disclose the freezing problem?


We would predict that \(0.2785 \times 73 = 20.33\) sellers would disclose the problem. Obviously we observed fewer than this, though it is not yet clear if that is due to chance variation or whether that is because the questions vary in how effective they are at getting to the truth.

If the questions were actually equally effective, meaning about 27.85% of respondents would disclose the freezing issue regardless of what question they were asked, about how many sellers would we expect to hide the freezing problem from the Positive Assumption group?2

We can compute the expected number of sellers who we would expect to disclose or hide the freezing issue for all groups, if the questions had no impact on what they disclosed, using the same strategies employed in the previous Example and Guided Practice to compute expected counts. These expected counts were used to construct Table 18.2, which is the same as Table 18.1, except now the expected counts have been added in parentheses.

Table 18.2: The observed counts and the expected counts for the iPod experiment.
Disclose problem
Hide problem
Total
General 2 (20.33) 71 (52.67) 73
Positive assumption 23 (20.33) 50 (52.67) 73
Negative assumption 36 (20.33) 37 (52.67) 73
Total 61 158 219

The examples and exercises above provided some help in computing expected counts. In general, expected counts for a two-way table may be computed using the row totals, column totals, and the table total. For instance, if there was no difference between the groups, then about 27.85% of each row should be in the first column:

\[ \begin{aligned} 0.2785\times (\text{row 1 total}) &= 20.33 \\ 0.2785\times (\text{row 2 total}) &= 20.33 \\ 0.2785\times (\text{row 3 total}) &= 20.33 \end{aligned} \]

Looking back to how 0.2785 was computed – as the fraction of sellers who disclosed the freezing issue \((61/219)\) – these three expected counts could have been computed as

\[ \begin{aligned} \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 1 total)} &= 20.33 \\ \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 2 total)} &= 20.33 \\ \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 3 total)} &= 20.33 \end{aligned} \]

This leads us to a general formula for computing expected counts in a two-way table when we would like to test whether there is strong evidence of an association between the column variable and row variable.

Computing expected counts in a two-way table.

To calculate the expected count for the \(i^{th}\) row and \(j^{th}\) column, compute

\[\text{Expected Count}_{\text{row }i,\text{ col }j} = \frac{(\text{row $i$ total}) \times (\text{column $j$ total})}{\text{table total}}\]

18.1.2 The observed chi-squared statistic

The chi-squared test statistic for a two-way table is found by finding the ratio of how far the observed counts are from the expected counts, as compared to the expected counts, for every cell in the table. For each table count, compute:

\[ \begin{aligned} &\text{General formula} && \frac{(\text{observed count } - \text{expected count})^2} {\text{expected count}} \\ &\text{Row 1, Col 1} && \frac{(2 - 20.33)^2}{20.33} = 16.53 \\ &\text{Row 2, Col 1} && \frac{(23 - 20.33)^2}{20.33} = 0.35 \\ & \hspace{9mm}\vdots && \hspace{13mm}\vdots \\ &\text{Row 3, Col 2} && \frac{(37 - 52.67)^2}{52.67} = 4.66 \end{aligned} \]

Adding the computed value for each cell gives the chi-squared test statistic \(X^2:\)

\[X^2 = 16.53 + 0.35 + \dots + 4.66 = 40.13\]

Is 40.13 a big number? That is, does it indicate that the observed and expected values are really different? Or is 40.13 a value of the statistic that we would expect to see just due to natural variability? Previously, we applied the randomization test to the setting where the research question investigated a difference in proportions. The same idea of shuffling the data under the null hypothesis can be used in the setting of the two-way table.

18.1.3 Variability of the statistic

Assuming that the individuals would disclose or hide the problems regardless of the question they are given (i.e., that the null hypothesis is true), we can randomize the data by reassigning the 61 disclosed problems and 158 hidden problems to the three groups at random. Table 18.3 shows a possible randomization of the observed data under the condition that the null hypothesis is true (in contrast to the original observed data in Table 18.1).

Table 18.3: Summary of the iPod study.
Question Disclose problem Hide problem Total
General 29 44 73
Positive assumption 15 58 73
Negative assumption 17 56 73
Total 61 158 219

As before, the randomized data is used to find a single value for the test statistic (here a chi-squared statistic). The chi-squared statistic for the randomized two-way table is found by comparing the observed and expected counts for each cell in the randomized table. For each cell, compute:

\[ \begin{aligned} &\text{General formula} && \frac{(\text{observed count } - \text{expected count})^2} {\text{expected count}} \\ &\text{Row 1, Col 1} && \frac{(29 - 20.33)^2}{20.33} = 3.7 \\ &\text{Row 2, Col 1} && \frac{(15 - 20.33)^2}{20.33} = 1.4 \\ & \hspace{9mm}\vdots && \hspace{13mm}\vdots \\ &\text{Row 3, Col 2} && \frac{(56 - 52.67)^2}{52.67} = 0.211 \end{aligned} \]

Adding the computed value for each cell gives the chi-squared test statistic \(X^2:\)

\[X^2 = 3.7 + 1.4 + \dots + 0.211 = 8\]

18.1.4 Observed statistic vs. null chi-squared statistics

As before, one randomization will not be sufficient for understanding if the observed data are particularly different from the expected chi-squared statistics when \(H_0\) is true. To investigate whether 40.13 is large enough to indicate the observed and expected counts are substantially different, we need to understand the variability in the values of the chi-squared statistic we would expect to see if the null hypothesis was true. Figure 18.1 plots 1,000 chi-squared statistics generated under the null hypothesis. We can see that the observed value is so far from the null statistics that the simulated p-value is zero. That is, the probability of seeing the observed statistic when the null hypothesis is true is virtually zero. In this case we can conclude that the decision of whether to disclose the iPod’s problem is changed by the question asked. We use the causal language of “changed” because the study was an experiment. Note that with a chi-squared test, we only know that the two variables (question_class and response) are related (i.e., not independent). We are not able to claim which type of question causes which type of response.

A histogram of chi-squared statistics from 1,000 simulations produced under the null hypothesis, where the question is independent of the response. The observed statistic of 40.13 is marked by the red line. None of the 1,000 simulations had a chi-squared value of at least 40.13.
Figure 18.1: A histogram of chi-squared statistics from 1,000 simulations produced under the null hypothesis, \(H_0,\) where the question is independent of the response. The observed statistic of 40.13 is marked by the red line. None of the 1,000 simulations had a chi-squared value of at least 40.13. In fact, none of the simulated chi-squared statistics came anywhere close to the observed statistic!

18.2 Mathematical model for test of independence

18.2.1 The chi-squared test of independence

Previously, in Section 17.3, we applied the Central Limit Theorem to the sampling variability of \(\hat{p}_1 - \hat{p}_2.\) The result was that we could use the normal distribution (e.g., \(z^*\) values (see Figure 16.2) and p-values from \(Z\) scores) to complete the mathematical inferential procedure. The chi-squared test statistic has a different mathematical distribution called the Chi-squared distribution. The important specification to make in describing the chi-squared distribution is something called degrees of freedom. The degrees of freedom change the shape of the chi-squared distribution to fit the problem at hand. Figure 18.2 visualizes different chi-squared distributions corresponding to different degrees of freedom.

The chi-squared distribution for differing degrees of freedom. The larger the degrees of freedom, the longer the right tail extends. The smaller the degrees of freedom, the more peaked the mode on the left becomes.
Figure 18.2: The chi-squared distribution for differing degrees of freedom. The larger the degrees of freedom, the longer the right tail extends. The smaller the degrees of freedom, the more peaked the mode on the left becomes.

18.2.2 Variability of the chi-squared statistic

As it turns out, the chi-squared test statistic follows a Chi-squared distribution when the null hypothesis is true. For two way tables, the degrees of freedom is equal to: \(df = \text{(number of rows minus 1)}\times \text{(number of columns minus 1)}\). In our example, the degrees of freedom parameter is \(df = (2-1)\times (3-1) = 2\).

18.2.3 Observed statistic vs. null chi-squared statistics

The test statistic for assessing the independence between two categorical variables is a \(X^2.\)

The \(X^2\) statistic is a ratio of how the observed counts vary from the expected counts as compared to the expected counts (which are a measure of how large the sample size is).

\[X^2 = \sum_{i,j} \frac{(\text{observed count} - \text{expected count})^2}{\text{expected count}}\]

When the null hypothesis is true and the conditions are met, \(X^2\) has a Chi-squared distribution with \(df = (r-1) \times (c-1).\)

Conditions:

  • Independent observations
  • Large samples: 5 expected counts in each cell

To bring it back to the example, we can safely assume that the observations are independent, as the question groups were randomly assigned. Additionally, there are over 5 expected counts in each cell, so the conditions for using the Chi-square distribution are met. If the null hypothesis is true (i.e., the questions had no impact on the sellers in the experiment), then the test statistic \(X^2 = 40.13\) is expected to follow a Chi-squared distribution with 2 degrees of freedom. Using this information, we can compute the p-value for the test, which is depicted in Figure 18.3.

Computing degrees of freedom for a two-way table.

When applying the chi-squared test to a two-way table, we use \(df = (R-1)\times (C-1)\) where \(R\) is the number of rows in the table and \(C\) is the number of columns.

Chi-square distribution (with df = 2) curve, shaded for p-value for X2 = 40.13. The p-value is so small that it is not visible on the plot.
Figure 18.3: Visualization of the p-value for \(X^2 = 40.13\) when \(df = 2\).

The software R can be used to find the p-value with the function pchisq(). Just like pnorm(), pchisq() always gives the area to the left of the cutoff value. Because, in this example, the p-value is represented by the area to the right of 40.13, we subtract the output of pchisq() from 1.

1 - pchisq(40.13, df = 2)
[1] 1.93e-09

Find the p-value and draw a conclusion about whether the question affects the sellers likelihood of reporting the freezing problem.


Using a computer, we can compute a very precise value for the tail area above \(X^2 = 40.13\) for a chi-squared distribution with 2 degrees of freedom: 0.000000002.

Using a discernibility level of \(\alpha=0.05,\) the null hypothesis is rejected since the p-value is smaller. That is, the data provide convincing evidence that the question asked did affect a seller’s likelihood to tell the truth about problems with the iPod.

Table 18.4 summarizes the results of an experiment evaluating three treatments for Type 2 Diabetes in patients aged 10-17 who were being treated with metformin. The three treatments considered were continued treatment with metformin (met), treatment with metformin combined with rosiglitazone (rosi), or a lifestyle intervention program. Each patient had a primary outcome, which was either lacked glycemic control (failure) or did not lack that control (success). What are appropriate hypotheses for this test?


  • \(H_0:\) There is no difference in the effectiveness of the three treatments.
  • \(H_A:\) There is some difference in effectiveness between the three treatments, e.g., perhaps the rosi treatment performed better than lifestyle.
Table 18.4: Results for the Type 2 Diabetes study.
Treatment Failure Success Total
lifestyle 109 125 234
met 120 112 232
rosi 90 143 233
Total 319 380 699

The diabetes2 data can be found in the openintro R package.

Typically we will use a computer to do the computational work of finding the chi-squared statistic. However, it is always good to have a sense for what the computer is doing, and in particular, calculating the values which would be expected if the null hypothesis is true can help to understand the null hypothesis claim. Additionally, comparing the expected and observed values by eye often gives the researcher some insight into why or why not the null hypothesis for a given test is rejected or not.

A chi-squared test for a two-way table may be used to test the hypotheses in the diabetes Example above. To get a sense for the statistic used in the chi-squared test, first compute the expected values for each of the six table cells.3

Note, when analyzing 2-by-2 contingency tables (that is, when both variables only have two possible options), one guideline is to use the two-proportion methods introduced in Chapter 17.

18.3 Chapter review

18.3.1 Summary

In this chapter we extended the randomization / bootstrap / mathematical model paradigm to research questions involving categorical variables. We continued working with one population proportion as well as the difference in populations proportions, but the test of independence allowed for hypothesis testing on categorical variables with more than two levels. We note that the normal model was an excellent mathematical approximation to the sampling distribution of sample proportions (or differences in sample proportions), but that the questions with categorical variables with more than 2 levels required a new mathematical model, the chi-squared distribution. As seen in Chapter 11, Chapter 12 and Chapter 13, almost all the research questions can be approached using computational methods (e.g., randomization tests or bootstrapping) or using mathematical models. We continue to emphasize the importance of experimental design in making conclusions about research claims. In particular, recall that variability can come from different sources (e.g., random sampling vs. random allocation, see Figure 2.8).

18.3.2 Terms

The terms introduced in this chapter are presented in Table 18.5. If you’re not sure what some of these terms mean, we recommend you go back in the text and review their definitions. You should be able to easily spot them as bolded text.

Table 18.5: Terms introduced in this chapter.
Chi-squared distribution expected counts
chi-squared statistic independence

18.4 Exercises

Answers to odd-numbered exercises can be found in Appendix A.18.

  1. Quitters. Does being part of a support group affect the ability of people to quit smoking? A county health department enrolled 300 smokers in a randomized experiment. 150 participants were randomly assigned to a group that used a nicotine patch and met weekly with a support group; the other 150 received the patch and did not meet with a support group. At the end of the study, 40 of the participants in the patch plus support group had quit smoking while only 30 smokers had quit in the other group.

    1. Create a two-way table presenting the results of this study.

    2. Answer each of the following questions under the null hypothesis that being part of a support group does not affect the ability of people to quit smoking, and indicate whether the expected values are higher or lower than the observed values.

      1. How many subjects in the “patch + support” group would you expect to quit?

      2. How many subjects in the “patch only” group would you expect to not quit?

  1. Act on climate change. The table below summarizes results from a Pew Research poll which asked respondents whether they have personally taken action to help address climate change within the last year and their generation. The differences in each generational group may be due to chance. Complete the following computations under the null hypothesis of independence between an individual’s generation and whether they have personally taken action to help address climate change within the last year. (Pew Research Center 2021)

    Response
    Generation Took action Didn't take action Total
    Gen Z 292 620 912
    Millenial 885 2,275 3,160
    Gen X 809 2,709 3,518
    Boomer & older 1,276 4,798 6,074
    Total 3,262 10,402 13,664

    If there is no relationship between age and action,

    1. how many Gen Z’ers would you expect to have personally taken action to help address climate change within the last year?

    2. how many Millenials would you expect to have personally taken action to help address climate change within the last year?

    3. how many Gen X’ers would you expect to have personally taken action to help address climate change within the last year?

    4. how many Boomers and older would you expect to have personally taken action to help address climate change within the last year?

  1. Lizard habitats, data. In order to assess whether habitat conditions are related to the sunlight choices a lizard makes for resting, Western fence lizard (Sceloporus occidentalis) were observed across three different microhabitats.4 (Adolph 1990; Asbury and Adolph 2007)

    sunlight
    site sun partial shade Total
    desert 16 32 71 119
    mountain 56 36 15 107
    valley 42 40 24 106
    Total 114 108 110 332
    1. If the variables describing the habitat and the amount of sunlight are independent, what proporiton of lizards (total) would be expected in each of the three sunlight categories?

    2. Given the proportions of each sunlight condition, how many lizards of each type would you expect to see in the sun? in the partial sun? in the shade?

    3. Compare the observed (original data) and expected (part b.) tables. From a first glance, does it seem as though the habitat and choice of sunlight may be associated?

    4. Regardless of your answer to part (c), is it possible to tell from looking only at the expected and observed counts whether the two variables are associated?

  1. Disaggregating Asian American tobacco use, data. Understanding cultural differences in tobacco use across different demographic groups can lead to improved health care education and treatment. A recent study disaggregated tobacco use across Asian American ethnic groups including Asian-Indian (n = 4,373), Chinese (n = 4,736), and Filipino (n = 4,912), in comparison to non-Hispanic Whites (n = 275,025). The number of current smokers in each group was reported as Asian-Indian (n = 223), Chinese (n = 279), Filipino (n = 609), and non-Hispanic Whites (n = 50,880). (Rao et al. 2021)

    In order to assess whether there is a difference in current smoking rates across three Asian American ethnic groups, the observed data is compared to the data that would be expected if there were no association between the variables.

    Smoking
    ethnicity don't smoke smoke Total
    Asian-Indian 4,150 223 4,373
    Chinese 4,457 279 4,736
    Filipino 4,303 609 4,912
    Total 12,910 1,111 14,021
    1. If the variables on ethnicity and smoking status are independent, estimate the proporiton of individuals (total) who smoke?

    2. Given the overall proportion who smoke, how many of each Asian American ethnicity would you expect to smoke?

    3. Compare the observed and expected counts. From a first glance, does it seem as though the Asian American ethnicity and choice of smoking may be associated?

    4. Regardless of your answer to part (c), is it possible to tell from looking only at the expected and observed counts whether the two variables are associated?

  1. Lizard habitats, randomize once. In order to assess whether habitat conditions are related to the sunlight choices a lizard makes for resting, Western fence lizard (Sceloporus occidentalis) were observed across three different microhabitats. (Adolph 1990; Asbury and Adolph 2007) Then, the data were randomized once, where sunlight preference was randomly assigned to the lizards across different sites. The original data are shown on the left and the results of the randomization is shown on the right.

    Original data
    sunlight
    site sun partial shade Total
    desert 16 32 71 119
    mountain 56 36 15 107
    valley 42 40 24 106
    Total 114 108 110 332
    Randomized data
    sunlight
    site sun partial shade Total
    desert 44 42 33 119
    mountain 39 31 37 107
    valley 31 35 40 106
    Total 114 108 110 332

    Recall that the Chi-squared statistic \((X^2)\) measures the difference between the expected and observed counts. Without calculating the actual statistic, report on whether the original data or the randomized data will have a larger Chi-squared statistic. Explain your choice.

  1. Disaggregating Asian American tobacco use, randomize once. In a study that aims to disaggregate tobacco use across Asian American ethnic groups (Asian-Indian, Chinese, and Filipino, in comparison to non-Hispanic Whites), respondents were asked whether they smoke tobacco or not. (Rao et al. 2021) Then, the data were randomized once, where smoking status was randomly assigned to the participants across different ethnicities. The original data are shown on the left and the results of the randomization is shown on the right.

    Original data
    Smoking
    ethnicity don't smoke smoke Total
    Asian-Indian 4,150 223 4,373
    Chinese 4,457 279 4,736
    Filipino 4,303 609 4,912
    Total 12,910 1,111 14,021
    Randomized data
    Smoking
    ethnicity don't smoke smoke Total
    Asian-Indian 4,015 358 4,373
    Chinese 4,385 351 4,736
    Filipino 4,510 402 4,912
    Total 12,910 1,111 14,021

    Recall that the Chi-squared statistic \((X^2)\) measures the difference between the expected and observed counts. Without calculating the actual statistic, report on whether the original data or the randomized data will have a larger Chi-squared statistic. Explain your choice.

  1. Lizard habitats, randomization test. In order to assess whether habitat conditions are related to the sunlight choices a lizard makes for resting, Western fence lizard (Sceloporus occidentalis) were observed across three different microhabitats. (Adolph 1990; Asbury and Adolph 2007) The original data were randomized 1,000 times (sunlight variable randomly assigned to the observations across different habitats), and the histogram of the Chi-squared statistic on each randomization is displayed.

    1. The histogram above describes the Chi-squared statistics for 1,000 different randomization datasets. When randomizing the data, is the imposed structure that the variables are independent or that the variables are associated? Explain.

    2. What is the range of plausible values for the randomized Chi-squared statistic?

    3. The observed Chi-squared statistic is 68.8 (marked in red on plot). Does the observed value provide evidence against the null hypothesis? To answer the question, state the null and alternative hypotheses, approximate the p-value, and conclude the test in the context of the problem.

  2. Disaggregating Asian American tobacco use, randomization test. Understanding cultural differences in tobacco use across different demographic groups can lead to improved health care education and treatment. A recent study disaggregated tobacco use across Asian American ethnic groups including Asian-Indian (n = 4373), Chinese (n = 4736), and Filipino (n = 4912), in comparison to non-Hispanic Whites (n = 275,025). The number of current smokers in each group was reported as Asian-Indian (n = 223), Chinese (n = 279), Filipino (n = 609), and non-Hispanic Whites (n = 50,880). (Rao et al. 2021) The original data were randomized 1000 times (smoking status randomly assigned to the observations across ethnicities), and the histogram of the Chi-squared statistic on each randomization is displayed.

    1. The histogram above describes the Chi-squared statistics for 1000 different randomization datasets. When randomizing the data, is the imposed structure that the variables are independent or that the variables are associated? Explain.

    2. What is the range of plausible values for the randomized Chi-squared statistic?

    3. The observed Chi-squared statistic is 209.42 (marked in red on plot). Does the observed value provide evidence against the null hypothesis? To answer the question, state the null and alternative hypotheses, approximate the p-value, and conclude the test in the context of the problem.

  1. Lizard habitats, larger data. In order to assess whether habitat conditions are related to the sunlight choices a lizard makes for resting, Western fence lizard (Sceloporus occidentalis) were observed across three different microhabitats. (Adolph 1990; Asbury and Adolph 2007)

    Consider the situation where the dataset is 5 times larger than the original data (but have the same proportional representation in each category). The distribution of lizards in each of the sites resting in the sun, partial sun, and shade are as follows.

    Larger data
    sunlight
    site sun partial shade Total
    desert 80 160 355 595
    mountain 280 180 75 535
    valley 210 200 120 530
    Total 570 540 550 1,660

    The larger dataset was randomized 1,000 times (sunlight preference randomly assigned to the observations across sites), and the histogram of the Chi-squared statistic on each randomization is displayed.

    1. The histogram above describes the Chi-squared statistics for 1,000 different randomization of the larger dataset. When randomizing the data, is the imposed structure that the variables are independent or that the variables are associated? Explain.

    2. What is the (approximate) range of plausible values for the randomized Chi-squared statistic?

    3. The observed Chi-squared statistic is 343.865 (and seen in red on the graph). Does the observed value provide evidence against the null hypothesis? To answer the question, state the null and alternative hypotheses, approximate the p-value, and conclude the test in the context of the problem.

    4. If the alternative hypothesis is true, how does the sample size effect the ability to reject the null hypothesis? (Hint: Consider the original data as compared with the larger dataset that have the same proportional values.)

  1. Disaggregating Asian American tobacco use, smaller data. Understanding cultural differences in tobacco use across different demographic groups can lead to improved health care education and treatment. A recent study disaggregated tobacco use across Asian American ethnic groups. (Rao et al. 2021)

    Consider the situation where the dataset is 50 times smaller than the original data (but have the same proportional representation in each category). The distribution of smokers in each of the ethnicity groups in the smaller data are as follows.

    Smaller data
    Smoking
    ethnicity don't smoke smoke Total
    Asian-Indian 83 4 87
    Chinese 89 6 95
    Filipino 86 12 98
    Total 258 22 280

    The smaller dataset was randomized 1,000 times (smoking status randomly assigned to the observations across ethnicities), and the histogram of the Chi-squared statistic on each randomization is displayed.

    1. The histogram above describes the Chi-squared statistics for 1,000 different randomization of the smaller dataset. When randomizing the data, is the imposed structure that the variables are independent or that the variables are associated? Explain.

    2. What is the (approximate) range of plausible values for the randomized Chi-squared statistic?

    3. The observed Chi-squared statistic is 4.19 (and seen in red on the graph). Does the observed value provide evidence against the null hypothesis? To answer the question, state the null and alternative hypotheses, approximate the p-value, and conclude the test in the context of the problem.

    4. If the alternative hypothesis is true, how does the sample size effect the ability to reject the null hypothesis? (Hint: Consider the original data as compared with the smaller dataset that have the same proportional values.)

  1. True / False, I. Determine if the statements below are true or false. For each false statement, suggest an alternative wording to make it a true statement.

    1. The Chi-square distribution, just like the normal distribution, has two parameters, mean and standard deviation.

    2. The Chi-square distribution is always right skewed, regardless of the value of the degrees of freedom parameter.

    3. The Chi-square statistic is always greater than or equal to 0.

    4. As the degrees of freedom increases, the shape of the Chi-square distribution becomes more skewed.

  1. True / False, II. Determine if the statements below are true or false. For each false statement, suggest an alternative wording to make it a true statement.

    1. As the degrees of freedom increases, the mean of the Chi-square distribution increases.

    2. If you found \(\chi^2 = 10\) with \(df = 5\) you would fail to reject \(H_0\) at the 5% discernibility level.

    3. When finding the p-value of a Chi-square test, we always shade the tail areas in both tails.

    4. As the degrees of freedom increases, the variability of the Chi-square distribution decreases.

  1. Sleep deprived transportation workers. The National Sleep Foundation conducted a survey on the sleep habits of randomly sampled transportation workers and randomly sampled non-transportation workers that serve as a “control” for comparison. (National Sleep Foundation 2012) The results of the survey are shown below. Conduct a hypothesis test to evaluate if these data provide evidence of an association between sleep levels and profession.

    Profession Less than 6 hours 6 to 8 hours More than 8 hours Total
    Non-transportation workers 35 193 64 292
    Transportation workers 104 499 192 795
    Total 139 692 256 1,087
  1. Parasitic worm. Lymphatic filariasis is a disease caused by a parasitic worm. Complications of the disease can lead to extreme swelling and other complications. Here we consider results from a randomized experiment that compared three different drug treatment options to clear people of the this parasite, which people are working to eliminate entirely. The results for the second year of the study are given below: (King et al. 2018)

    Outcome
    group Clear at Year 2 Not Clear at Year 2 Total
    Three drugs 52 2 54
    Two drugs 31 24 55
    Two drugs annually 42 14 56
    Total 125 40 165
    1. Set up hypotheses for evaluating whether there is any difference in the performance of the treatments, and also check conditions.

    2. Statistical software was used to run a Chi-square test, which output: \(X^2 = 23.7 \quad df = 2 \quad \text{p-value} < 0.0001\). Use these results to evaluate the hypotheses from part (a), and provide a conclusion in the context of the problem.

  1. Shipping holiday gifts. A local news survey asked 500 randomly sampled Los Angeles residents which shipping carrier they prefer to use for shipping holiday gifts. The table below shows the distribution of responses by age group as well as the expected counts for each cell (shown in italics).

    Age
    Shipping method
    18-34
    35-54
    55+
    Total
    USPS 72 81 97 102 76 62 245
    UPS 52 53 76 68 34 41 162
    FedEx 31 21 24 27 9 16 64
    Something else 7 5 6 7 3 4 16
    Not sure 3 5 6 5 4 3 13
    Total 165 209 126 500
    1. State the null and alternative hypotheses for testing for independence of age and preferred shipping method for holiday gifts among Los Angeles residents.

    2. Are the conditions for inference using a Chi-square test satisfied?

  1. Coffee and depression. Researchers conducted a study investigating the relationship between caffeinated coffee consumption and risk of depression in women. They collected data on 50,739 women free of depression symptoms at the start of the study in the year 1996, and these women were followed through 2006. The researchers used questionnaires to collect data on caffeinated coffee consumption, asked each individual about physician- diagnosed depression, and also asked about the use of antidepressants. The table below shows the distribution of incidences of depression by amount of caffeinated coffee consumption. (Lucas et al. 2011)

    Caffeinated coffee consumption
    Clinical depression 1 cup / week or fewer 2-6 cups / week 1 cups / day 2-3 cups / day 4 cups / day or more Total
    Yes 670 ___ 905 564 95 2,607
    No 11,545 6,244 16,329 11,726 2,288 48,132
    Total 12,215 6,617 17,234 12,290 2,383 50,739
    1. What type of test is appropriate for evaluating if there is an association between coffee intake and depression?

    2. Write the hypotheses for the test you identified in part (a).

    3. Calculate the overall proportion of women who do and do not suffer from depression.

    4. Identify the expected count for the empty cell, and calculate the contribution of this cell to the test statistic.

    5. The test statistic is \(\chi^2=20.93\). What is the p-value?

    6. What is the conclusion of the hypothesis test?

    7. One of the authors of this study was quoted on the New York Times as saying it was “too early to recommend that women load up on extra coffee” based on just this study. (O’Connor 2011) Do you agree with this statement? Explain your reasoning.


  1. For readers not as old as the authors, an iPod is basically an iPhone without any cellular service, assuming it was one of the later generations. Earlier generations were more basic.↩︎

  2. We would expect \((1 - 0.2785) \times 73 = 52.67.\) It is okay that this result, like the result from the Example above, is a fraction.↩︎

  3. The expected count for row one / column one is found by multiplying the row one total (234) and column one total (319), then dividing by the table total (699): \(\frac{234\times 319}{699} = 106.8.\) Similarly for the second column and the first row: \(\frac{234\times 380}{699} = 127.2.\) Row 2: 105.9 and 126.1. Row 3: 106.3 and 126.7.↩︎

  4. The lizard_habitat data used in this exercise can be found in the openintro R package.↩︎

中文

18  双向列联表的推断

第 17 我们的关注点是比例差异,这是一个通过计算两组(二元解释变量)中测得的成功比例(来自二元响应变量)得出的统计量。正如我们将在下面的例子中看到的,有时解释变量或响应变量有两个以上的可能选项。在这种情况下,两组之间的差异是不够的,而且如果有3个、4个或更多可能的响应水平,“成功”的比例也没有很好的定义。当解释变量和响应变量都有2个或更多水平时,汇总分类数据的主要方法是通过双向表,如 表 18.1.

请注意,对于双向表,没有一个明显的单一关注参数。相反,研究问题通常关注响应变量的比例如何(或是否)随解释变量的不同水平而变化。由于没有需要估计的总体参数,通过自助法(bootstrapping)来寻找估计值的标准误是没有意义的。因此,对于双向表,我们将重点关注随机化检验及相应的数学近似(而不是自助法)。

18.1 独立性的随机化检验

我们都会购买二手产品——汽车、电脑、教科书等等——有时我们会假设这些产品的卖家会坦诚说明所售产品存在的潜在问题。这一点我们不应想当然。研究人员招募了219名参与者参与一项研究,在研究中他们将出售一台二手iPod1 这台iPod已知过去曾死机两次。参与者被激励尽可能以更高的价格卖出这台iPod,因为他们除了获得10美元的参与费外,还能得到销售额的5%提成。研究人员想了解什么类型的问题会促使卖家披露死机问题。

参与研究的卖家并不知情,买家其实是与研究人员的合作者,旨在评估不同问题对促使卖家披露iPod过去问题的可能性的影响。按照脚本行事的买家以“好的,我想应该我先来。所以你用这台iPod已经2年了……”开始,并以以下三个问题之一结束:

  • 一般性提问:关于它你能告诉我些什么?
  • 正面假设提问:它没有任何问题,对吧?
  • 负面假设:它有什么问题?

问题是对卖家所采取的处理方式,而响应则是该问题是否促使他们披露 iPod 的死机问题。结果如 表 18.1所示,数据表明询问“ 它有什么问题?”是最能促使卖家披露过去死机问题的提问方式。然而,你也应该问自己:如果所问的问题确实没有差异,我们是否可能仅凭偶然就看到这些结果?或者这实际上是某些问题更能有效探明真相的证据?

表 18.1: iPod 研究的总结,其中向作为行动者的研究参与者提出一个问题。
问题 披露问题 隐藏问题 总计
一般 2 71 73
正面假设 23 50 73
负面假设 36 37 73
总计 61 158 219

ask 数据可以在 openintro R 包中找到。

iPod 实验的假设检验实际上是评估是否有令人信服的证据表明每种问题在促使参与者披露 iPod 问题方面的成功率存在差异。换句话说,目标是检验买家的问题是否与卖家是否披露问题相互独立。

18.1.1 双向表中的期望计数

虽然我们不会期望三种问题类别下的披露数量完全相同,但三组之间的披露率似乎存在显著差异。为了调查披露率的差异是由于人们诚实度的自然变异,还是由于处理效应(即问题导致了差异),我们需要计算双向表中每个单元格的估计计数。

从实验中,我们可以计算出所有披露死机问题的卖家的比例为 \(61/219 = 0.2785.\) 如果这些问题之间确实没有差异,并且无论被问到什么问题,都有 27.85% 的卖家会披露死机问题,那么 General 组中,我们预期会有多少人披露死机问题?


我们预测会有 \(0.2785 \times 73 = 20.33\) 名卖家披露该问题。显然我们观察到的数量少于此数,尽管目前尚不清楚这是由于随机变异,还是因为这些问题在揭示真相方面的有效性各不相同。

如果这些问题实际上同样有效,即无论被问到什么问题,大约 27.85% 的受访者都会披露死机问题,那么我们预期正面假设组中大约会有多少卖家 隐瞒 死机问题?2

我们可以计算在问题对受访者的披露行为没有影响的情况下,各组中我们预期会披露或隐瞒死机问题的卖家数量,所使用的方法与前面的示例和引导练习中计算期望计数的方法相同。这些期望计数被用于构建 表 18.2,它与 表 18.1相同,只是现在期望计数已添加在括号中。

表 18.2:iPod 实验的观察计数和期望计数。
披露问题
隐瞒问题
总计
一般 2 (20.33) 71 (52.67) 73
正面假设 23 (20.33) 50 (52.67) 73
负面假设 36 (20.33) 37 (52.67) 73
总计 61 158 219

上面的例子和练习为计算期望计数提供了一些帮助。一般来说,双向表的期望计数可以利用行合计、列合计和表的总计来计算。例如,如果两组之间没有差异,那么每一行中大约应有 27.85% 的数据落在第一列:

\[ \begin{aligned} 0.2785\times (\text{row 1 total}) &= 20.33 \\ 0.2785\times (\text{row 2 total}) &= 20.33 \\ 0.2785\times (\text{row 3 total}) &= 20.33 \end{aligned} \]

回顾一下 0.2785 是如何计算的——即披露冻结问题的卖家所占的比例 \((61/219)\) ——这三个期望计数也可以按如下方式计算:

\[ \begin{aligned} \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 1 total)} &= 20.33 \\ \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 2 total)} &= 20.33 \\ \left(\frac{\text{row 1 total}}{\text{table total}}\right) \text{(column 3 total)} &= 20.33 \end{aligned} \]

由此我们得到一个通用公式,用于在双向表中计算期望计数,以检验列变量与行变量之间是否存在关联的强有力证据。

在双向表中计算期望计数。

要计算第 \(i^{th}\) 行与第 \(j^{th}\) 列的期望计数,请计算

\[\text{Expected Count}_{\text{row }i,\text{ col }j} = \frac{(\text{row $i$ total}) \times (\text{column $j$ total})}{\text{table total}}\]

18.1.2 观测到的卡方统计量

双向表的卡方检验统计量是这样求得的:对表中的每一个单元格,计算观测计数相对于期望计数偏离的程度,并与期望计数进行比较(求比值)。对于表中的每个计数,计算:

\[ \begin{aligned} &\text{General formula} && \frac{(\text{observed count } - \text{expected count})^2} {\text{expected count}} \\ &\text{Row 1, Col 1} && \frac{(2 - 20.33)^2}{20.33} = 16.53 \\ &\text{Row 2, Col 1} && \frac{(23 - 20.33)^2}{20.33} = 0.35 \\ & \hspace{9mm}\vdots && \hspace{13mm}\vdots \\ &\text{Row 3, Col 2} && \frac{(37 - 52.67)^2}{52.67} = 4.66 \end{aligned} \]

将每个单元格的计算值相加,即得到卡方检验统计量 \(X^2:\)

\[X^2 = 16.53 + 0.35 + \dots + 4.66 = 40.13\]

40.13 是一个大数吗?也就是说,它是否表明观测值与期望值确实存在很大差异?还是说 40.13 只是我们仅因自然变异就会预期看到的统计量取值?之前,我们将随机化检验应用于研究比例差异的问题。在零假设下打乱数据的同一思想也可以用于双向表的情形。

18.1.3 统计量的变异性

假设个体会披露或隐瞒问题 他们被问到的问题无关(即零假设为真),我们可以通过将 61 个披露的问题和 158 个隐瞒的问题随机重新分配到三个组中来对数据进行随机化。 表 18.3 展示了在零假设为真的条件下(与 表 18.1).

表 18.3:iPod 研究的总结。
问题 披露问题 隐藏问题 总计
一般 29 44 73
正面假设 15 58 73
负面假设 17 56 73
总计 61 158 219

与之前一样,使用随机化数据来计算检验统计量的单一数值(此处为卡方统计量)。随机化列联表的卡方统计量是通过比较 随机化 表中每个单元格的观测计数与期望计数来计算的。对每个单元格,计算:

\[ \begin{aligned} &\text{General formula} && \frac{(\text{observed count } - \text{expected count})^2} {\text{expected count}} \\ &\text{Row 1, Col 1} && \frac{(29 - 20.33)^2}{20.33} = 3.7 \\ &\text{Row 2, Col 1} && \frac{(15 - 20.33)^2}{20.33} = 1.4 \\ & \hspace{9mm}\vdots && \hspace{13mm}\vdots \\ &\text{Row 3, Col 2} && \frac{(56 - 52.67)^2}{52.67} = 0.211 \end{aligned} \]

将每个单元格的计算值相加,即得到卡方检验统计量 \(X^2:\)

\[X^2 = 3.7 + 1.4 + \dots + 0.211 = 8\]

18.1.4 观测统计量与零假设卡方统计量的比较

与之前一样,仅一次随机化不足以判断当 \(H_0\) 为真时,观测数据是否与期望的卡方统计量特别不同。为了考察 40.13 是否大到足以表明观测计数与期望计数存在实质性差异,我们需要了解在零假设为真时卡方统计量取值的变异性。 图 18.1 绘制了在零假设下生成的 1,000 个卡方统计量。可以看到,观测值与零假设统计量相距甚远,以至于模拟 p 值为零。也就是说,当零假设为真时,看到该观测统计量的概率几乎为零。在这种情况下,我们可以得出结论:是否披露 iPod 问题的决定会因所提问题的不同而改变。我们使用“改变”这一因果语言,因为该研究是一项实验。注意,对于卡方检验,我们只知道两个变量(question_classresponse)相关(即不独立),但无法断言哪种类型的问题会导致哪种类型的回答。

A histogram of chi-squared statistics from 1,000 simulations produced under the null hypothesis, where the question is independent of the response. The observed statistic of 40.13 is marked by the red line. None of the 1,000 simulations had a chi-squared value of at least 40.13.
图 18.1:在零假设下由 1,000 次模拟产生的卡方统计量的直方图, \(H_0,\) 其中问题与回答相互独立。观测统计量 40.13 用红线标出。1,000 次模拟中没有一次得到至少为 40.13 的卡方值。事实上,没有任何一个模拟的卡方统计量接近观测统计量!

18.2 独立性检验的数学模型

18.2.1 卡方独立性检验

此前,在 第 17.3 节中,我们将中心极限定理应用于 \(\hat{p}_1 - \hat{p}_2.\) 结果是我们可以使用正态分布(例如, \(z^*\) 值(参见 图 16.2)以及来自 \(Z\) 分数的 p 值)来完成数学推断过程。卡方检验统计量遵循一种不同的数学分布,称为卡方分布。在描述卡方分布时,需要确定的一个重要参数是所谓的自由度。自由度会改变卡方分布的形状,以适应当前的问题。 图 18.2 展示了对应于不同自由度的不同卡方分布。

The chi-squared distribution for differing degrees of freedom. The larger the degrees of freedom, the longer the right tail extends. The smaller the degrees of freedom, the more peaked the mode on the left becomes.
图 18.2:不同自由度下的卡方分布。自由度越大,右尾延伸得越长。自由度越小,左侧的众数就越尖。

18.2.2 卡方统计量的变异性

事实证明,当原假设为真时,卡方检验统计量服从 卡方分布 。对于双向表,自由度等于: \(df = \text{(number of rows minus 1)}\times \text{(number of columns minus 1)}\). 在我们的例子中,自由度参数为 \(df = (2-1)\times (3-1) = 2\).

18.2.3 观测统计量与零假设卡方统计量的比较

用于评估两个分类变量之间独立性的检验统计量是 \(X^2.\)

\(X^2\) 统计量是观测计数相对于期望计数的偏差与期望计数(期望计数是样本量大小的一种度量)之比。

\[X^2 = \sum_{i,j} \frac{(\text{observed count} - \text{expected count})^2}{\text{expected count}}\]

当零假设为真且条件满足时, \(X^2\) 服从自由度为 \(df = (r-1) \times (c-1).\)

F 统计量是各组之间差异程度(MSG)与组内观测值变异程度(MSE)的比值。

  • 独立观测
  • 大样本:每个单元格中期望计数为 5

回到这个例子,我们可以放心地假设观测值是相互独立的,因为问题组是随机分配的。此外,每个单元格中的期望计数都超过 5,因此使用卡方分布的条件得到满足。如果零假设为真(即问题对实验中的卖家没有影响),那么检验统计量 \(X^2 = 40.13\) 预期将服从自由度为 2 的卡方分布。利用这一信息,我们可以计算该检验的 p 值,如图所示于 图 18.3.

计算双向表的自由度。

在将卡方检验应用于双向表时,我们使用 \(df = (R-1)\times (C-1)\) ,其中 \(R\) 是表中的行数, \(C\) 是列数。

Chi-square distribution (with df = 2) curve, shaded for p-value for X2 = 40.13. The p-value is so small that it is not visible on the plot.
图 18.3: \(X^2 = 40.13\) 的概率,当 \(df = 2\).

的 p 值可视化 pchisq()软件 R 可以使用函数 pnorm(), pchisq() 总是给出临界值左侧的面积。因为在本例中,p值由40.13右侧的面积表示,所以我们用1减去 pchisq() 的输出结果。

1 - pchisq(40.13, df = 2)
[1] 1.93e-09

求出p值,并就该问题是否影响卖家报告冻结问题的可能性得出结论。


利用计算机,我们可以为自由度为2的卡方分布计算 \(X^2 = 40.13\) 以上尾部面积的一个非常精确的值:0.000000002。

使用可辨别性水平 \(\alpha=0.05,\) ,由于p值更小,因此拒绝原假设。也就是说,数据提供了令人信服的证据,表明所提出的问题确实影响了卖家如实告知iPod问题的可能性。

表 18.4 总结了一项实验的结果,该实验评估了针对10-17岁正在接受二甲双胍治疗的2型糖尿病患者的三种治疗方法。所考虑的三种治疗是:继续使用二甲双胍治疗(met)、二甲双胍联合罗格列酮治疗(rosi),或 lifestyle 干预方案。每位患者都有一个主要结局,即要么血糖控制不佳(失败),要么血糖控制良好(成功)。该检验的适当假设是什么?


  • \(H_0:\) 三种治疗方法的有效性没有差异。
  • \(H_A:\) 三种治疗方法的有效性存在一些差异,例如,也许 rosi 治疗的效果优于 lifestyle.
表18.4:2型糖尿病研究的结果。
治疗 失败 成功 总计
生活方式 109 125 234
met 120 112 232
rosi 90 143 233
总计 319 380 699

diabetes2 数据可以在 openintro R 包中找到。

通常我们会使用计算机来完成计算卡方统计量的工作。然而,对计算机在做什么有一个直观的了解总是有益的,特别是,计算在原假设为真时的期望值有助于理解原假设的主张。此外,通过肉眼比较期望值和观测值,往往能让研究者对为什么某个检验的原假设被拒绝或未被拒绝有所洞察。

双向表的卡方检验可用于检验上文糖尿病示例中的假设。为了对卡方检验中使用的统计量有一个直观认识,首先计算表中六个单元格各自的期望值。3

注意,在分析2×2列联表时(即两个变量都只有两种可能取值),一条指导原则是使用中介绍的两种比例方法 第 17.

18.3 本章复习

18.3.1 小结

在本章中,我们将随机化/自助法/数学模型范式扩展到涉及分类变量的研究问题。我们继续处理单一总体比例以及总体比例之差,但独立性检验使得对具有两个以上水平的分类变量进行假设检验成为可能。我们注意到,正态模型是样本比例(或样本比例之差)抽样分布的一个极好的数学近似,但涉及具有2个以上水平的分类变量的问题需要一个新的数学模型,即卡方分布。如中所见, 第 11, 第 12第 13几乎所有的研究问题都可以通过计算方法(例如随机化检验或自助法)或数学模型来处理。我们继续强调实验设计在得出关于研究结论中的重要性。特别地,请记住变异性可能来自不同的来源(例如随机抽样与随机分配,参见 图 2.8).

18.3.2 术语

本章中介绍的术语列于 表 18.5。如果您不确定其中一些术语的含义,我们建议您回到正文中复习它们的定义。您应该能够很容易地发现它们是 粗体文本.

表 18.5:本章介绍的术语。
卡方分布 期望计数
卡方统计量 独立性

18.4 练习

奇数编号习题的答案见 附录 A.18.

  1. 戒烟者。 参加支持小组是否会影响人们戒烟的能力?某县卫生部门招募了300名吸烟者参加一项随机实验。150名参与者被随机分配到一个使用尼古丁贴片并每周与支持小组会面的组;另外150名接受贴片但不与支持小组会面。在研究结束时,贴片加支持小组中有40名参与者成功戒烟,而另一组中只有30名吸烟者戒烟。

    1. 创建一个双向表来呈现这项研究的结果。

    2. 在“参加支持小组不影响人们戒烟能力”的原假设下,回答以下每个问题,并指出期望值是高于还是低于观测值。

      1. 你预计“贴片+支持”组中会有多少名受试者戒烟?

      2. 你预计“仅贴片”组中会有多少名受试者不戒烟?

  1. 针对气候变化采取行动。 下表总结了皮尤研究中心(Pew Research)一项民意调查的结果,该调查询问受访者在过去一年中是否亲自采取过行动帮助应对气候变化,以及他们所属的世代。每个世代组之间的差异可能是由偶然因素造成的。请在“个人世代与其过去一年是否亲自采取行动帮助应对气候变化”相互独立的原假设下完成以下计算。 (皮尤研究中心 2021)

    回答
    世代 采取了行动 未采取行动 总计
    Z世代 292 620 912
    千禧一代 885 2,275 3,160
    X世代 809 2,709 3,518
    婴儿潮及更早世代 1,276 4,798 6,074
    总计 3,262 10,402 13,664

    如果年龄与行动之间没有关系,

    1. 你预计过去一年中会有多少名Z世代亲自采取行动帮助应对气候变化?

    2. 你预计过去一年中会有多少名千禧一代亲自采取行动帮助应对气候变化?

    3. 你预计过去一年内有多少X世代的人会亲自采取行动帮助应对气候变化?

    4. 你预计过去一年内有多少婴儿潮一代及更年长的人会亲自采取行动帮助应对气候变化?

  1. 蜥蜴栖息地数据。 为了评估栖息地条件与蜥蜴休息时对阳光的选择是否相关,研究人员在三种不同的微栖息地中观察了西部强棱蜥(Sceloporus occidentalis)。4 (Adolph 1990; Asbury and Adolph 2007)

    阳光
    地点 阳光 半阴 阴凉 总计
    沙漠 16 32 71 119
    山脉 56 36 15 107
    山谷 42 40 24 106
    总计 114 108 110 332
    1. 如果描述栖息地和光照量的变量是独立的,那么三个光照类别中(总共)预计各有多大比例的蜥蜴?

    2. 已知每种光照条件的比例,你预计在阳光充足、半阴和遮荫处分别会看到多少只每种类型的蜥蜴?

    3. 比较观察(原始数据)表和期望(b部分)表。乍一看,栖息地和光照选择之间是否可能存在关联?

    4. 无论你对(c)部分的答案如何,仅通过查看期望计数和观察计数,能否判断这两个变量是否相关联?

  1. 细分亚裔美国人烟草使用情况的数据。 了解不同人口群体在烟草使用方面的文化差异可以改善健康教育与治疗。最近一项研究按亚裔美国人的族裔群体细分了烟草使用情况,包括亚裔印度人(n = 4,373)、华人(n = 4,736)和菲律宾裔(n = 4,912),并与非西班牙裔白人(n = 275,025)进行比较。各组当前吸烟者人数报告如下:亚裔印度人(n = 223)、华人(n = 279)、菲律宾裔(n = 609)、非西班牙裔白人(n = 50,880)。 (Rao et al. 2021)

    为了评估三个亚裔美国族裔群体之间的当前吸烟率是否存在差异,将观察数据与假设变量之间无关联时的期望数据进行比较。

    吸烟
    种族 不吸烟 吸烟 总计
    亚裔印度人 4,150 223 4,373
    华人 4,457 279 4,736
    菲律宾裔 4,303 609 4,912
    总计 12,910 1,111 14,021
    1. 如果族裔和吸烟状况这两个变量是独立的,估计(总共)有多大比例的人吸烟?

    2. 已知总体吸烟比例,你预计每个亚裔美国族裔中会有多少人吸烟?

    3. 比较观察计数和期望计数。乍一看,亚裔美国人这一族裔与吸烟选择之间似乎可能存在关联吗?

    4. 无论你对(c)部分的答案如何,仅通过查看期望计数和观察计数,能否判断这两个变量是否相关联?

  1. 蜥蜴栖息地,随机化一次。 为了评估栖息地条件与蜥蜴休息时对阳光的选择是否相关,研究人员在三种不同的微栖息地中观察了西部强棱蜥(Sceloporus occidentalis)。 (Adolph 1990; Asbury and Adolph 2007) 然后,对数据进行了一次随机化,即将对阳光的偏好随机分配给不同地点的蜥蜴。原始数据显示在左侧,随机化的结果显示在右侧。

    原始数据
    阳光
    地点 阳光 半阴 阴凉 总计
    沙漠 16 32 71 119
    山脉 56 36 15 107
    山谷 42 40 24 106
    总计 114 108 110 332
    随机化后的数据
    阳光
    地点 阳光 半阴 阴凉 总计
    沙漠 44 42 33 119
    山脉 39 31 37 107
    山谷 31 35 40 106
    总计 114 108 110 332

    回想一下卡方统计量 \((X^2)\) 测量期望计数与观察计数之间的差异。在不计算实际统计量的情况下,说明原始数据还是随机化数据会具有更大的卡方统计量,并解释你的选择。

  1. 细分亚裔美国人的烟草使用情况,随机化一次。 在一项旨在按亚裔美国人族群(亚裔印度人、华人和菲律宾人,与非西班牙裔白人进行比较)细分烟草使用情况的研究中,受访者被问及他们是否吸烟。 (Rao et al. 2021) 然后,对数据进行了一次随机化处理,即将吸烟状态在不同族裔的参与者之间随机分配。原始数据显示在左侧,随机化的结果显示在右侧。

    原始数据
    吸烟
    种族 不吸烟 吸烟 总计
    亚裔印度人 4,150 223 4,373
    华人 4,457 279 4,736
    菲律宾裔 4,303 609 4,912
    总计 12,910 1,111 14,021
    随机化后的数据
    吸烟
    种族 不吸烟 吸烟 总计
    亚裔印度人 4,015 358 4,373
    华人 4,385 351 4,736
    菲律宾裔 4,510 402 4,912
    总计 12,910 1,111 14,021

    回想一下卡方统计量 \((X^2)\) 测量期望计数与观察计数之间的差异。在不计算实际统计量的情况下,说明原始数据还是随机化数据会具有更大的卡方统计量,并解释你的选择。

  1. 蜥蜴栖息地,随机化检验。 为了评估栖息地条件与蜥蜴休息时对阳光的选择是否相关,研究人员在三种不同的微栖息地中观察了西部强棱蜥(Sceloporus occidentalis)。 (Adolph 1990; Asbury and Adolph 2007) 原始数据被随机化了1,000次(将阳光变量随机分配到不同栖息地的观察中),并显示了每次随机化的卡方统计量直方图。

    1. 上面的直方图描述了1,000个不同随机化数据集的卡方统计量。在随机化数据时,所施加的结构是变量相互独立还是变量相关联?请解释。

    2. 随机化卡方统计量的合理取值范围是多少?

    3. 观察到的卡方统计量为68.8(在图中用红色标出)。该观察值是否提供了反对原假设的证据?为回答该问题,请陈述原假设和备择假设,近似计算p值,并结合问题背景得出检验结论。

  2. 细分亚裔美国人烟草使用情况,随机化检验。 了解不同人口群体中烟草使用的文化差异可以改善健康教育与治疗。最近的一项研究细分了亚裔美国人各族群(包括亚裔印度人(n = 4373)、华人(n = 4736)和菲律宾裔(n = 4912))与非西班牙裔白人(n = 275,025)相比的烟草使用情况。各组当前吸烟者人数报告如下:亚裔印度人(n = 223)、华人(n = 279)、菲律宾裔(n = 609)、非西班牙裔白人(n = 50,880)。 (Rao et al. 2021) 原始数据被随机化了1000次(将吸烟状态随机分配到不同族裔的观察中),并显示了每次随机化的卡方统计量直方图。

    1. 上面的直方图描述了1000个不同随机化数据集的卡方统计量。在随机化数据时,所施加的结构是变量相互独立还是变量相关联?请解释。

    2. 随机化卡方统计量的合理取值范围是多少?

    3. 观测到的卡方统计量为 209.42(在图中以红色标出)。观测值是否提供了反对原假设的证据?要回答这个问题,请陈述原假设和备择假设,近似计算 p 值,并结合问题背景得出检验结论。

  1. 蜥蜴栖息地,更大数据。 为了评估栖息地条件与蜥蜴休息时对阳光的选择是否相关,研究人员在三种不同的微栖息地中观察了西部强棱蜥(Sceloporus occidentalis)。 (Adolph 1990; Asbury and Adolph 2007)

    考虑数据集是原始数据的 5 倍 较大 的情况(但每个类别的比例表示相同)。各地点在阳光下、半阴处和阴凉处休息的蜥蜴分布如下。

    更大数据
    阳光
    地点 阳光 半阴 阴凉 总计
    沙漠 80 160 355 595
    山脉 280 180 75 535
    山谷 210 200 120 530
    总计 570 540 550 1,660

    将较大的数据集随机化1,000次(将阳光偏好随机分配到各站点的观测值中),并显示每次随机化的卡方统计量的直方图。

    1. 上方的直方图描述了较大数据集1,000次不同随机化的卡方统计量。在对数据进行随机化时,所施加的结构是变量相互独立,还是变量相关联?请解释。

    2. 随机化卡方统计量的合理值的(近似)范围是多少?

    3. 观测到的卡方统计量为343.865(在图中以红色显示)。该观测值是否提供了反对原假设的证据?要回答这个问题,请陈述原假设和备择假设,近似计算p值,并结合问题背景得出检验结论。

    4. 如果备择假设为真,样本量如何影响拒绝原假设的能力?(提示: 将原始数据与具有相同比例值的较大数据集进行比较。)

  1. 细分亚裔美国人烟草使用情况,较小的数据。 了解不同人口群体在烟草使用方面的文化差异,可以改善健康教育与治疗。最近一项研究对亚裔美国各族裔群体的烟草使用情况进行了细分。 (Rao et al. 2021)

    考虑数据集为原始数据的50倍 较小 的情况(但各类别中具有相同的比例代表性)。较小数据中每个族裔群体的吸烟者分布如下。

    较小数据
    吸烟
    种族 不吸烟 吸烟 总计
    亚裔印度人 83 4 87
    华人 89 6 95
    菲律宾裔 86 12 98
    总计 258 22 280

    将较小的数据集随机化1,000次(在各个种族之间随机分配吸烟状态),并显示每次随机化的卡方统计量的直方图。

    1. 上方的直方图描述了较小数据集1,000次不同随机化的卡方统计量。在随机化数据时,所施加的结构是变量相互独立还是变量相关联?请解释。

    2. 随机化卡方统计量的合理值的(近似)范围是多少?

    3. 观测到的卡方统计量为4.19(在图中以红色显示)。该观测值是否提供了反对原假设的证据?要回答这个问题,请陈述原假设和备择假设,近似计算p值,并结合问题的背景得出检验结论。

    4. 如果备择假设为真,样本量如何影响拒绝原假设的能力?(提示: 将原始数据与具有相同比例值的较小数据集进行比较。)

  1. 判断对错,I. 判断以下陈述是正确还是错误。对于每个错误的陈述,请提出另一种措辞使其成为正确的陈述。

    1. 卡方分布与正态分布一样,有两个参数:均值和标准差。

    2. 无论自由度参数的值是多少,卡方分布总是右偏的。

    3. 卡方统计量总是大于或等于0。

    4. 随着自由度的增加,卡方分布的形状变得更加偏斜。

  1. 判断对错,II。 判断以下陈述是正确还是错误。对于每个错误的陈述,请提出另一种措辞使其成为正确的陈述。

    1. 随着自由度的增加,卡方分布的均值增大。

    2. 如果你得到 \(\chi^2 = 10\)\(df = 5\) ,你将在5%的显著性水平上无法拒绝 \(H_0\)

    3. 在求卡方检验的p值时,我们总是在两侧尾部都涂阴影区域。

    4. 随着自由度的增加,卡方分布的变异性减小。

  1. 睡眠不足的交通行业工作者。 美国国家睡眠基金会(National Sleep Foundation)对随机抽取的交通行业工作者以及作为对照用于比较的随机抽取的非交通行业工作者的睡眠习惯进行了一项调查。 (National Sleep Foundation 2012) 调查结果如下表所示。进行假设检验,以评估这些数据是否提供了睡眠水平与职业之间存在关联的证据。

    职业 少于6小时 6至8小时 超过8小时 总计
    非运输业工人 35 193 64 292
    运输业工人 104 499 192 795
    总计 139 692 256 1,087
  1. 寄生蠕虫。 淋巴丝虫病是一种由寄生蠕虫引起的疾病。该疾病的并发症可导致极度肿胀及其他问题。这里我们考虑一项随机实验的结果,该实验比较了三种不同的药物治疗方案,以清除人体内的这种寄生虫——人们正努力彻底消灭这种寄生虫。该研究第二年的结果如下所示: (King et al. 2018)

    结果
    组别 第2年已清除 第2年未清除 总计
    三种药物 52 2 54
    两种药物 31 24 55
    每年两种药物 42 14 56
    总计 125 40 165
    1. 建立假设以评估各治疗方案的效果是否存在差异,并检查条件。

    2. 使用统计软件进行了卡方检验,其输出结果为: \(X^2 = 23.7 \quad df = 2 \quad \text{p-value} < 0.0001\)。请利用这些结果评估第(a)部分中的假设,并结合问题背景给出结论。

  1. 邮寄节日礼物。 一项本地新闻调查询问了500名随机抽取的洛杉矶居民,他们在邮寄节日礼物时更喜欢使用哪家快递公司。下表按年龄组显示了回答的分布,以及每个单元格的期望计数(以斜体显示)。

    年龄
    邮寄方式
    18-34
    35-54
    55+
    总计
    USPS 72 81 97 102 76 62 245
    UPS 52 53 76 68 34 41 162
    FedEx 31 21 24 27 9 16 64
    其他 7 5 6 7 3 4 16
    不确定 3 5 6 5 4 3 13
    总计 165 209 126 500
    1. 陈述用于检验洛杉矶居民中年龄与邮寄节日礼物首选方式之间是否独立的原假设和备择假设。

    2. 使用卡方检验进行推断的条件是否满足?

  1. 咖啡与抑郁症。 研究人员进行了一项研究,调查女性饮用含咖啡因咖啡与患抑郁症风险之间的关系。他们收集了1996年研究开始时无抑郁症状的50,739名女性的数据,并对这些女性进行了随访直至2006年。研究人员使用问卷收集含咖啡因咖啡消费量的数据,询问每个人是否被医生诊断出抑郁症,并询问抗抑郁药物的使用情况。下表按含咖啡因咖啡消费量显示了抑郁症发病情况的分布。 (Lucas et al. 2011)

    含咖啡因咖啡的消费量
    临床抑郁症 每周1杯或更少 每周2-6杯 每天1杯 每天2-3杯 每天4杯或更多 总计
    670 ___ 905 564 95 2,607
    11,545 6,244 16,329 11,726 2,288 48,132
    总计 12,215 6,617 17,234 12,290 2,383 50,739
    1. 评估咖啡摄入量与抑郁症之间是否存在关联时,哪种检验是合适的?

    2. 写出你在(a)部分中确定的检验的假设。

    3. 计算患有和不患有抑郁症的女性总体比例。

    4. 计算空单元格的期望计数,并计算该单元格对检验统计量的贡献。

    5. 检验统计量为 \(\chi^2=20.93\)。p 值是多少?

    6. 假设检验的结论是什么?

    7. 该研究的一位作者在《纽约时报》上被引述称,仅基于这项研究就“建议女性多喝咖啡还为时过早”。 (O’Connor 2011) 你同意这一说法吗?请解释你的理由。


  1. 对于不像作者那么年长的读者来说,iPod 基本上就是一部没有蜂窝网络服务的 iPhone(假设是较新的几代产品)。更早的几代则更为简单。↩︎

  2. 我们预期 \((1 - 0.2785) \times 73 = 52.67.\) 这个结果像上面示例中的结果一样是小数,这是没问题的。↩︎

  3. 第一行/第一列的期望计数是通过将第一行的总数(234)与第一列的总数(319)相乘,再除以表格总数(699)得到的: \(\frac{234\times 319}{699} = 106.8.\) 对于第二列和第一行同理: \(\frac{234\times 380}{699} = 127.2.\) 第2行:105.9 和 126.1。第3行:106.3 和 126.7。↩︎

  4. lizard_habitat 本练习中使用的数据可在 openintro R 包中找到。↩︎