3
$\begingroup$

If I have two sets of 2D points, say A and B. Is there a formula for calculating the Pearson correlation coefficient for their union if I know the this coefficient for both A and B?

$\endgroup$
5
  • $\begingroup$ Simpon's paradox gives an intuition that the answer is "no", but I'm curious if someone has a more formal treatment. $\endgroup$
    – Galen
    Commented Feb 10, 2023 at 15:47
  • $\begingroup$ So A is a set of X,Y coordinates and B is another set of X,Y coordinates. When you refer to their "union", do mean the X,Y coordinates that exactly belong to each set? When you refer to a "union", I'm reminded that many early statistician mistakenly believe that Venn diagrams are well defined, rather than just conceptual diagrams. $\endgroup$
    – AdamO
    Commented Feb 10, 2023 at 15:49
  • $\begingroup$ With union I mean just taking the set of all X,Y coordinates, i.e. the set which contains all points from both sets $\endgroup$
    – amh ineoni
    Commented Feb 10, 2023 at 15:55
  • $\begingroup$ @amhineoni You seem to understand calculating a Pearson correlation. Is your question then about the mechanics of "stacking" two datasets? $\endgroup$
    – AdamO
    Commented Feb 10, 2023 at 16:16
  • $\begingroup$ I don't think you could with only the correlation, per @Galen s comment, but you could with the covariance, see for example: math.stackexchange.com/questions/377684/… $\endgroup$
    – David B
    Commented Feb 10, 2023 at 16:20

1 Answer 1

3
$\begingroup$

You can combine all of the points into one data set and calculate the correlation of the combined data set. If all you have (or are willing to use) are the correlations of the two data sets, however, then this cannot be done.

For instance, it is possible to take two data sets that each have zero correlation and drive the correlation arbitrarily high.

x1 <- seq(-1, 1, 0.01)
y1 <- x1^2
shift <- 5
x2 <- x1 + shift
y2 <- y1 + shift
cor(x1, y1) # Basically zero
cor(x2, y2) # Basically zero
cor(c(x1, x2), c(y1, y2)) # 0.9671184

You can fiddle with the shift variable to drive the correlation as high or low as you want.

Likewise, two data sets that each have zero correlation could be combined to give zero correlation.

x1 <- seq(-1, 1, 0.01)
y1 <- x1^2
x2 <- x1
y2 <- -y1 + 1
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # Basically zero
cor(x2, y2) # Basically zero
cor(c(x1, x2), c(y1, y2)) # Basically zero

Further, two data sets with perfect correlatio can be combined to give zero correlation.

x1 <- seq(0, 1, 0.01)
y1 <- x1 
x2 <- x1 + 0.62
y2 <- y1 - 0.60
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # One
cor(x2, y2) # One
cor(c(x1, x2), c(y1, y2)) # Close to zero

(I didn't get the combined correlation to be zero, but fiddling with the +0.62 and -0.60 should get you there.)

However, such a correlation could be perfect, too.

x1 <- seq(0, 1, 0.01)
y1 <- x1 #+ rnorm(length(x1), 0, 0.01)
x2 <- x1 + 1
y2 <- y1 + 1
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # One
cor(x2, y2) # One
cor(c(x1, x2), c(y1, y2)) # One

The presence of noise does not change the story.

set.seed(2023)
x1 <- seq(0, 1, 0.01)
y1 <- x1 + rnorm(length(x1), 0, 0.1)
x2 <- x1 + 1
y2 <- y1 - 1
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # 0.9452742
cor(x2, y2) # 0.9452742
cor(c(x1, x2), c(y1, y2)) # -0.49525

In this example, the combined correlation decreases in magnitude and changes sign. However, the combined correlation could increase in magnitude and maintain its sign.

set.seed(2023)
x1 <- seq(0, 1, 0.01)
y1 <- x1 + rnorm(length(x1), 0, 0.1)
x2 <- x1 + 1
y2 <- y1 + 1
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # 0.9452742
cor(x2, y2) # 0.9452742
cor(c(x1, x2), c(y1, y2)) # 0.985716

However, a decrease in magnitude while keeping the sign is possible, too.

set.seed(2023)
x1 <- seq(0, 1, 0.01)
y1 <- x1 + rnorm(length(x1), 0, 0.1)
x2 <- x1 + 0.1
y2 <- y1 + 0.0
plot(c(x1, x2), c(y1, y2))
cor(x1, y1) # 0.9452742
cor(x2, y2) # 0.9452742
cor(c(x1, x2), c(y1, y2)) # 0.9316725

Overall, the correlation of the combined set can range from $-1$ to $1$.

$\endgroup$

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