I'm trying to use a statistical test to determine whether two different populations have the same distribution of a given categorical variable.

Note: In some cases, the categorical variable is ordered (e.g., short < medium < tall), like in the example below; but in other cases it may be unordered (e.g., apple, banana, or cherry).

To illustrate the problem that I am trying to solve, let's consider an example where we have Caucasian and Hispanic students, and we have the following counts of their heights, as belonging to one of 3 categories: short, medium, tall.

Short Medium Tall
Caucasian 200 400 600
Hispanic 300 200 100

Question: What statistical test should I use to test if Caucasians and Hispanics have the same distribution of (the categorical variable) height?

  • $\begingroup$ This is the central use case of a Chi squared test $\endgroup$
    – rishi-k
    Commented Jul 14, 2021 at 19:23
  • 1
    $\begingroup$ One of your categories is ordered. This may be important if you're interested in alternatives like "tends to be taller". $\endgroup$
    – Glen_b
    Commented Jul 15, 2021 at 14:42

1 Answer 1


A chi-squared test could assess whether proportions in the categories are homogeneous across the two populations. (This test treats categories as if nominal--without regard to order.)

For your (pretty obviously fictitious data) the test in R goes as shown below:

cau = c(200, 400, 600);  his = c(300, 200, 100)
TBL = rbind(cau, his);  TBL
    [,1] [,2] [,3]
cau  200  400  600
his  300  200  100

The null hypothesis of homogeneity is strongly rejected, with a P-value near $0.$


        Pearson's Chi-squared test

data:  TBL
X-squared = 274.29, df = 2, p-value < 2.2e-16

Under the null hypothesis of homogeneity, the expected counts in the six cells of the table are:

        [,1] [,2]     [,3]
cau 333.3333  400 466.6667
his 166.6667  200 233.3333

The sum of the squared Pearson residuals is the chi-squared statistic $274.29.$ Looking at residuals with largest absolute values gives an idea which cells of the table contribute most to this significant result.

         [,1] [,2]      [,3]
cau -7.302967    0  6.172134
his 10.327956    0 -8.728716

The largest discrepancies between observed and expected counts are in the short and tall categories.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.