1



1. Chi-Squared Tests

We'll now look at how to test statistical hypotheses concerning nominal data, and specifically when nominal data are summarized as tables of frequencies. The tests we will considered are generically called chi-squared (or chi-square) tests. Each test involves computing a test statistic, and then calculating the area in the tail of a theoretical distribution called the chi-squared (χ²) distribution.

The χ² distribution, like the t distribution, is actually a family of distributions – each one corresponding to a certain number of degrees of freedom:

[pic]

However in the case of the χ² distribution, we are almost always concerned with upper-tail probabilities. That is, chi-squared tests are usually 1-tailed.

[pic]

Hypothetical Data

Various Outcomes to Arterial Stent Placement

|Outcome |Observed |Expected |

| |frequency |frequency |

| |(O) |(E) |

|Rejected |15 |7 |

|1 – 100 days |75 |60 |

|> 100 days |118 |156 |

|Replaced |20 |5 |

|Total |228 |228 |

Our observed frequencies come from data on 228 patients who receive the treatment. Our expected frequencies may come from theoretical models or from estimates of probabilities derived from some larger reference population.

Our null hypothesis is that the observed frequencies do not differ from the expected frequencies by more than is expected than chance. Or:

H0: Our sample comes from some specified reference population.

To test the null hypothesis, we may use either of two test statistics.

Pearson X-squared statistic

[pic]

Likelihood ratio statistic

[pic]

Both of these test statistics follow a theoretical χ²-distribution. They are typically, (though not necessarily always), close in value to each other.

Note that in the former case the test statistic is denoted X2. This should be called "ex-squared". It is not the same as the theoretical distribution, χ² (chi-squared). Most textbooks mistakenly call the test statistic (X2) "chi-squared." That is, the name "chi-squared" test comes from the distribution used to test the hypothesis (χ² distribution), and not the test statistic itself.

We perform our test by computing X2 . Our calculations for the example data are shown below:

Hypothetical Data

Various Outcomes to Arterial Stent Placement

|Outcome |Observed |Expected |(O – E)2 |[pic] |

| |frequency |frequency | | |

| |(O) |(E) | | |

|Rejected |15 |7 |64 |9.14 |

|1 – 100 days |75 |60 |225 |3.75 |

|> 100 days |118 |156 |1444 |9.26 |

|Replaced |20 |5 |225 |45 |

|Total |228 |228 | | |

| | | |Sum = X2 = |67.15 |

The area of the χ² distribution (with 4 – 1 = 3 df) above 67.15 is vanishingly small (p = 1.73922E-14). Even assuming a low α (e.g., α = 0.001) then p < α, so we reject the H0 which asserted that our data came from the reference population. That is, our sample comes from some other population, with probabilities of each level that are different from the reference population.

We can check our results here:

As mentioned briefly in the last lecture, our expected frequencies in an analysis like this would come from estimates of the probabilities of observations falling in each category.

Getting Expected Frequencies from Probability or Proportion Estimates

|Outcome |Observed |Population |Expected |

| |frequency |Probability |frequency |

| |(O) |(π) |(E) |

|Rejected |15 |0.031 |7 |

|1 – 100 days |75 |0.263 |60 |

|> 100 days |118 |0.684 |156 |

|Replaced |20 |0.022 |5 |

|Total |228 |1.0 |228 |

These probabilities might come from a theoretical model or from knowledge about the composition of the population. In any case, we would get the expected frequencies for each category (i) by multiplying each probability times the number of cases (n) in our sample:

[pic]

One common application of the above method is to perform a goodness-of-fit test. Suppose, for example, that we have a continuous variable and we wish to know if it's distribution is, for example, normal (or Poisson, or some other known shape).

Our null and alternative hypotheses are as follows:

H0: Our data follow the hypothezied distributional form.

H1: Our data do not follow the hypothesized distributional form.

We conduct the test as follows:

• Divide the continuous variable into discrete ranges.

• Observed frequencies are the numbers of observations that fall in each range.

• Probabilities (π) are what we would expect if the variable had the hypothesized distributional form (e.g., obtained from integral of the normal distribution over each range).

• For expected frequencies, we multiply the probabilities times the n of our sample size.

We then calculate the X2 test statistic and consult the χ² distribution with k – 1 df (where k is the number of levels or categories). Our p-value is the area of the distribution above the calculated value of X2. If p < α, we reject the null hypothesis that our data are normally distributed.

Note that in this case, unlike other applications, we typically *do not* want to reject the null hypothesis (i.e., we wish to conclude that the variable has the predicted distributional shape). For this reason, in a goodness-of-fit test, α is often set higher than usual, e.g., 0.1.

Video:

Pearson's Chi Square Test (Goodness of Fit)



2. Chi-Squared Tests for One Variable in Excel

1. Place level names in Column A

2. In Column B, place observed frequencies (O) for each level.

3. In Column C, place expected probabilities (π) for each level.

4. Multiply probabilities times sample size (n) to produce expected frequencies (E); place in Column D.

5. In Column E, calculate (O – E)2/E for each row.

6. Sum results of Column E. This is your X2 test statistic.

7. Compute p-value as area of χ² distribution (with k – 1 df, where k is the number of levels) above X2. If p < α (e.g., p < 0.05), reject null hypothesis that your O and E frequencies come from the same population or distribution. Use function:

=CHIDIST(x-square, df)

where is the value of X2 and df = k – 1.

[pic]

3. Chi-Squared Tests for Two-way Tables

Another, more common use of chi-squared statistics is to test whether two (or more) nominal variables are statistically independent.

• Two nominal variables are statistically independent if the level of one variable has no influence on or predictive value for the second variable.

Our null and alternative hypotheses are as follows:

H0: The two variables are statistically independent.

H1: The two variables are not statistically independent.

We will illustrate the method using two variables with two levels each, but the same principles can be applied to variables with more than two levels.

Let two nominal variables be measured on the same sample of n subjects. We can summarize the data as a two-way table of frequencies (cross-classification table), where Oij is the number of cases observed with level i of variable 1 and level j of variable 2. Suppose for example we have measured presence/absence of two symptoms on a set of patients:

Table: Cross-classification Frequencies for Presence/Absence of Two Symptoms

| |Symptom 2 |

|Symptom 1 |Absent |Present |Total |

|Absent |O11 |O12 |r1 |

|Present |O21 |O22 |r2 |

|Total |c1 |c2 |N |

The numbers along the edges (bottom and right), are called the marginal totals (also called marginal frequencies, or sometimes just marginals). These are simply row (r1 and r2) and column totals (c1 and c2).

We use the row and column marginal totals to compute the expected frequencies of each cell. Under the assumption of statistical independence, the probability of a randomly selected case falling in cell (i,j) is the probability of falling in row i times the probability of falling in column j.

We estimate these row and column probabilities from the marginal frequencies of our table. For example, r1/N estimates the probability of a case falling in row 1, and c1/N estimates the probability of a case falling on column 1.

The expected frequency of cases falling in cell (i, j) is therefore estimated as follows:

[pic]

If our null hypothesis is correct, then the observed frequencies should differ more than is expected by random sampling variability from the expected frequencies. To test this, we measure the discrepancy of observed and expected frequencies using our previous formula:

[pic]

Or, more precisely:

[pic]

where, for our example above, summation is over i, j = 1, 2

Homework: Use Excel to reproduce the results in section 2, using the data

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download