Can I use Pearson correlation for discrete variables? [closed]

Can I use Pearson correlation for discrete variables, if the level of measurement fits (either ratio or interval). Thanks!

• Could you explain what it means to you to "use" the correlation? Of course you can compute it, but using something usually means you are applying it to make a decision, as an intermediate step in a larger analysis, or to take some action.
– whuber
Commented Aug 11, 2022 at 19:33

Sure!

set.seed(2022)
N <- 100
x1 <- rpois(N, 5) # Poisson(5)
x2 <- rpois(N, 7) # Poisson(7)
cor(x1, x2)


At no point does the Pearson correlation make distribution assumptions beyond the covariance and variances existing.

The correlation coefficient, sure, if you're interested in measuring linear correlation.

If you want to test it, maybe -- you might sometimes need to consider using something else in place of the usual test, though.

The usual test is typically pretty level-robust but for example with count data (and often with other forms of discrete data) you tend to have (a) heteroskedasticity, related to the level of the mean; (b) nonlinear relationships; and (c) changing distribution shape as the mean changes. In particular (a) and (b) might lead to you consider other tests (whether using the same test statistic and a different approach to calculating p-values, or a slightly modified statistic, or even asking somewhat different questions of the data).

• I'd add that substantively a linear relationship between counts $y = a + bx$ seems less likely as a plausible model or reference situation but that is not a barrier to checking how close data are to such a relationship. Commented Aug 11, 2022 at 8:56
• I agree, outside some special cases. (I do at least mention that I'd tend to expect nonlinear relationships.) -- If there was one I'd tend to expect $a=0$. Commented Aug 12, 2022 at 2:36

Yes, of course. Discrete variables belong to numerical data with ratio scale, and not categorical data. So you can use Pearson correlation coefficient to measure the relationship between those two variables.

• A variable can easily be discrete but not ratio scale. Ordinal codes 1 to 5 are one example. Commented Aug 11, 2022 at 8:53

In the case of binary variables, this is even given a special name, either Matthew's Correlation Coefficient (MCC) or the "Phi coefficient". MCC is simply the Pearson correlation of two binary variables.

It depends on what you mean in "discrete". You can use Pearson's R for discrete numeric variable. If the data are in ordinal scale, you should use Spearman's correlation. If the data are in nominal scale, then Pearson's and Spearman's coefficients are not valid, even if you code the categories by numbers.