uniform random variables and correlations when value is above a threshold Suppose I have two groups which are uniformly distributed random betwee 0 and 100. So combined score is 200.
I want to know the the number of observations and correlation which obtain a joint score of more than 100.
I have the following:
X = matrix(runif(n = 200, min = 0, max = 100), nrow = 100, ncol = 2)

Which gives me:
         [,1]     [,2]
[1,] 96.31229 42.20657
[2,] 43.52599 10.82431
[3,] 77.54858 76.03796
[4,] 44.03978 72.21440
[5,] 89.06511 57.33148
[6,] 82.68131 41.62273

I compute the rowSums() and find which combination of the two uniform variables have a combined score of > 100.
XX = cbind(X, rowSums(X), rowSums(X) > 100)

Then I can filter and take the correlations.
X_1s = XX[XX[, 4] == 1,]
cor(X_1s[, 1], X_1s[, 2])

Is this the correct approach to the problem?
If I have two uniform randomly distributed variables between 0 and 100 and I want to know the correlation between the first runif and second runif when their join scores are above 100.
EDIT:
corVec <- vector()
for(i in 1:1000){
  X = matrix(runif(n = 200, min = 0, max = 100), nrow = 100, ncol = 2)
  X
  XX = cbind(X, rowSums(X), rowSums(X) > 100)
  
  X_1s = XX[XX[, 4] == 1,]
  corVec[i] = cor(X_1s[, 1], X_1s[, 2])
  i = i + 1
}

hist(corVec)



Yes, this approach is correct. To give some context: You have your two uniformly distributed random variables, let's call them $A$ and $B$, and you have a dependent random variable $G$ that is zero if the sum is greater 100, i.e. $A+B > 100$, and zero otherwise. You then ask for the correlation of $A$ and $B$ under the condition that $G=1$.
This situation can be depicted with the following Bayesian network:

The color of $G$ is darker to indicate that this random variable is conditioned on. Now, this pattern is known as a collider pattern where $G$ is the collider, and it is well-known that, even though $A$ and $B$ don't influence each other directly, they can be dependent when we condition on $G$. And you have computed the correlation of this dependency.
The correlation will be negative because if $A$ is small, $B$ has to be large to get $G$ above 100.
