What statistical test should I use to compare the distribution of a categorical variable across two populations? 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?
 A: 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.$
chisq.test(TBL)

        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:
chisq.test(TBL)$exp
        [,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.
chisq.test(TBL)$res
         [,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.
