**Introduction to Analyzing Categorical Data**

*In recent lessons, the responses have been numerical. When working with two treatments or populations, the treatments or populations may be thought of as categorical explanatory variables. In this lesson, we will discuss what to do if the responses, and not just the explanatory variables, are categorical.*

**Univariate Categorical Data**

Univariate categorical data may arise in a variety of settings. In a study of sea turtles, the number of males and females hatched during a season may be recorded. Here two categories exist, male and female, and the data consist of the number of observations falling within each category. A car arriving at an intersection, may continue forward, turn left, turn right, or reverse directions (do a U-turn), resulting in four categories of a univariate response.

The proportion *pi* of the population within category *i*, *i* = 1, 2, . . . , *r*, tends to be of primary interest in such studies. As an example, we might hypothesize that the proportion of male and female sea turtles hatched each season is the same (0.50). For the car's movement at a particular intersection, one hypothesis would be that 50% continue forward, 30% turn right, 15% turn left, and 5% do a U-turn. Hypothesis tests are conducted to determine whether or not the observed data are compatible with these hypotheses.

**Example**

A large grocery store wants to decrease the time needed to check out a customer. One aspect of this is the method by which the customer pays. Payment by cash, check, debit card, or credit card is accepted. The store manager believes that 35% of the transactions are by cash, 5% are by check, 50% are by debit card, and 10% are by credit card. Here the percentages are referring to the number of transactions and not the amount of a transaction. She plans a study to determine whether or not these percentages are correct.

- Give the response variable and identify the parameters associated with its categories.
- Set the hypotheses to be tested.

**Solution**

- The response variable of interest is a customer's method of payment.
- We may define the following:
*p*= proportion of cash transactions_{1}*p*= proportion of check transactions_{2}*p*= proportion of debit card transactions_{3}*p*= proportion of credit card transactions_{4}

It is not important whether we use *p _{1}* to denote the proportion of cash transactions or the proportion of some other type of transaction. However, clearly stating what

*p*represents is important. The set of hypotheses of interest is

_{1}*H*_{0}: *p _{1}* = 0.35,

*p*= 0.05,

_{2}*p*= 0.50,

_{3}andp= 0.10_{4}

*H*_{a}: not *H*_{0}

**Goodness-of-Fit Tests and the ***x*^{2}-Distribution

*x*

^{2}-Distribution

To test null hypotheses of the type just described, we select a random sample from the population of interest and classify each observation into one of the *r* categories. Let *n _{i}* be the number of observations in category

*i*,

*i*=1,2, . . . ,

*r*. The observed proportion in each category is ; notice that . Under the null hypothesis, we expect , observations to be in category

*i*. If the observed

*n*and expected

_{i}*e*counts are equal, the data are fully compatible with the null hypothesis. However, because we expect variability in the sample, we also expect the observed and expected counts to differ to some extent even if the null hypothesis is true. How far apart can they be before we doubt the null hypothesis? The statistical methods that help us make that decision are called goodness-of-fit tests. A

_{i}*goodness-of-fit*test assesses whether the observed counts in each category are compatible with the hypothesized proportions.

The test statistic for a goodness-of-fit test is . Again, notice that if *n _{i}* and

*e*are equal for

_{i}*i*= 1, 2, . . . ,

*r*,

*x*

^{2}= 0. As the observed and expected counts become farther apart,

*x*

^{2}gets larger. We want to reject the null hypothesis when

*x*

^{2}gets too large. If the null hypothesis is true and the expected counts in each category are not too small, the distribution of

*x*

^{2}is approximately a

*x*

^{2}- distribution (pronounced

*chi-squared distribution*). Two conditions must be satisfied for this test to be appropriate. First, the sample must be randomly selected from the population of interest. Second, the expected counts in each cell must not be too small. In general, the expected counts should be at least five.

The *x*^{2}- distribution has an area associated with only nonnegative values. The distribution is skewed to the right. The amount of skew, depends on its parameter and the degrees of freedom. Figure 20.1 illustrates how the shape of the distribution changes with degrees of freedom. It illustrates the shape of the distribution for 4, 6, and 10 degrees of freedom. Because we want to reject the null hypothesis if the test statistic *x*^{2} gets too large, the *p*-value is the area under the curve to the right of the test statistic. Although calculators and computers can be used to find these areas precisely, we will use Table 20.1 to help us approximate it.

The degrees of freedom associated with a goodness-of-fit test are the number of categories minus 1 minus the number of parameters estimated. When no parameters are estimated, the degrees of freedom are *r* – 1, or the number of categories minus one. As in earlier tests of hypotheses, we reject the null hypothesis if the *p*-value gets too small. Typically, a value less than 0.05 is significant, and a value less than 0.01 is highly significant.

This type of hypothesis test differs from the others we have considered. We are unable to have the research hypothesis as the alternative hypothesis. Here, we want to show that the null hypothesis is true. However, at best, our conclusion will be that the data are consistent or compatible with the null hypothesis. If we reject the null hypothesis, we have strong evidence that it is not true.

We should make one final note. If only two categories exist, the *x*^{2}-test is an alternative to a two-sided test for a population proportion. The two often provide similar but not exactly the same results. If a one sided test of a proportion is needed, the *x*^{2}-test as presented here cannot be used.

### Ask a Question

Have questions about this article or topic? Ask### Related Questions

See More Questions### Popular Articles

- Kindergarten Sight Words List
- First Grade Sight Words List
- 10 Fun Activities for Children with Autism
- Signs Your Child Might Have Asperger's Syndrome
- Theories of Learning
- A Teacher's Guide to Differentiating Instruction
- Child Development Theories
- Social Cognitive Theory
- Curriculum Definition
- Why is Play Important? Social and Emotional Development, Physical Development, Creative Development