Would it be possible for two variables to be negatively correlated with one another, yet be positively correlated with a third variable? Are there any concrete examples?

**Answer**

Certainly. Consider multivariate normally distributed data with a covariance matrix of the form

(1−+−1+++1).

As an example, we can generate 1000 such observations with covariance matrix

(1−0.50.5−0.510.50.50.51)

in R as follows:

```
library(mixtools)
set.seed(1)
xx <- rmvnorm(1e3,mu=rep(0,3),
sigma=rbind(c(1,-.5,.5),c(-.5,1,.5),c(.5,.5,1)))
cor(xx[,c(1,2)])
cor(xx[,c(1,3)])
cor(xx[,c(2,3)])
```

The first two columns are negatively correlated (ρ=−0.5), the first and the third and the second and the third are positively correlated (ρ=0.5).

**Attribution***Source : Link , Question Author : aquaplane , Answer Author : Stephan Kolassa*