I am more or less familiar with the stats. However, recently I ran in the following problem.

Problem: I would like to compare two distributions that are zero inflated (to some extend). The two distr. y and z I would like to compare with look as follows (I am using R code to illustrate the issue):

y <- c(521.0,13319.0,67860.0,143780.0,158374.0,81496.0,15612.0,538.0)

z <- c(0.0,404.0,39788.0,217048.0,191345.0,32335.0,580.0,0.0)

As you can see, the counts are quite huge and in the variable z we have two zeros. The bins can be described as follows:

x <- c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)

which reflect a likert-scale from 0-7. Hence, if you would plot the count in a histogram, the x-axis would be of ordinal nature.

Using a chi-square test:

t <- cbind(y,z)

chisq.test(t,correct = TRUE)

gives me the following output: Pearson's Chi-squared test

data: t X-squared = 73707, df = 7, p-value < 2.2e-16

suggesting that the two distr. are sign different to each other. Now, I learned that a chi-squared test is only useful, if there are no zeros in any of the bins, nor the number of observations should be at least 5 per bin. Hence, a chi-squared test shouldn't be the right procedure to go for. In some books, a fisher's exact test is suggested in this case, though this fails as the counts are too large.

If you plot the two distributions:

p <- ggplot(data=df, aes(x))

p <- p + geom_line(aes(y = prop.table(y), colour = "Combined"),size=2) + geom_line(aes(y = prop.table(z), colour = "Seperated"),size=2)

p <- p + labs(aesthetic='custom text') + theme(legend.title=element_blank())

p <- p + scale_x_discrete(name ="Rating score", limits=c(0,1,2,3,4,5,6,7))

p <- p + ylab("Probability (%)")

p <- p + theme(axis.text = element_text(size = 15)) + theme(axis.title = element_text(size = 25))

p <- p + theme(legend.text=element_text(size=15))


enter image description here

you can see that they are quite similar in shape.

Now comes the issue, what test is the right way to go here? Is the chi-squared test still appropriate to use? In some other books and also here (http://www.basic.northwestern.edu/statguidefiles/conting_anal_alts.html#Zeroes) it is suggested to use a logistic regression model in this case, as the X is ordinal.

However, I have no experience with this kind of analysis, and would very much appreciate it, if there would be someone to show me the right R code (if possible, based on my example) and help me to understand and interpret the outcomes.

Thanks a lot in advance for your help!

  • $\begingroup$ This statement is incorrect: "... a chi-squared test is only useful, if there are no zeros in any of the bins, nor the number of observations should be at least 5 per bin." It confuses the data with expected values. It's fine for data to have zeros! $\endgroup$ – whuber Aug 4 '16 at 22:10
  • 1
    $\begingroup$ Adding to @whuber's comment: You can easily extract the expected values for your table with chisq.test(t,correct = TRUE)$expected. Given the large sample size it is not surprising that these are all larger than 5. Also with close to a million observations you probably won't find a test that doesn't tell you that the differences in distributions are significant... $\endgroup$ – Achim Zeileis Aug 4 '16 at 23:51
  • $\begingroup$ Thanks a lot for your answers. So you think a chi-squared test is ok? $\endgroup$ – Stats newbee Aug 5 '16 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.