# What statistical tools can I use to evaluate class comparison over a categorical variable?

I'm a noob in statistics so forgive me in advance for misusing some concepts.

I've constructed an analysis counting a categorical variable over 1 million records and got the results below:

Class | Count
---------------
A     | 328362
B     | 328129
C     | 327950
D     | 327220


I'd like to show although class A has the maximum count this may occur by chance and is not that special.

It seems you want to test whether all four categories are equally likely. An appropriate test is a one-sample chi-squared test of the null hypothesis that the four Class probabilities are all $$1/4.$$

In this case the test statistic is

$$Q = \sum_{j=1}^4 \frac{(X_j - E)^2}{E},$$

where $$X_i$$ are the frequencies $$X_1 = 328,362,$$ and so on, and where the expected count in each Class is the average $$E = 327,915.2$$ of the four frequencies. Under $$H_0,$$ the test statistic $$Q \stackrel{aprx}{\sim} \mathsf{Chisq}(\text{df}= 5-1=3).$$ (For your large counts, the approximation is quite good.)

In R, the procedure chisq.test computes the test statistic $$Q$$ and its P-value as follows:

x = c(328362, 328129, 327950, 327220)
chisq.test(x)

Chi-squared test for given
probabilities

data:  x
X-squared = 2.2257, df = 3, p-value = 0.5269


Because no probability vector was provided the default probability $$1/4$$ are used for each Class.

Because the P-value $$0.527 > 0.05$$ we have no evidence at the 5% level to reject $$H_0.$$ So the data are consistent with the null hypothesis that all four groups are equally likely.

The P-value $$0.527$$ is the area to the right of the solid vertical line at $$Q = 2.2257$$ under the $$\mathsf{Chisq}(3)$$ density function. We would have rejected $$H_0$$ at the 5% level if $$Q > 7.815,$$ the "critical value" at the vertical dotted line.

1 -pchisq(2.2257, 3)
[1] 0.526904
qchisq(.95, 3)
[1] 7.814728


• I believe you meant "Because the P-value 0.527>**0.05** we have no evidence ....". Apr 22, 2019 at 23:34
• Yes. Thanks for catching the typo. Fixing it. Apr 22, 2019 at 23:38
• The quantities in the problem are births by moon phases from brazilian candidates for election polls from 1996 to 2016. The intent is to test whether the Full Moon, Class A, had some influence in the number of births. Last Quarter is Class B, New Moon is Class C and First Quarter is Class D. I didn't explained this before because I dind't want to atract any bias from respondents. Thanks for your help. Apr 22, 2019 at 23:58