I was a bit confused recently with why two jointly distributed variables will exhibit a smaller scatter as the correlation between the random variables increases (assuming only positive values for the correlation coefficient), but the standard deviation of the function of the sum or difference between these two variables would increase as the correlation between the random variables increases (see example., for the latter).
So I wrote a small code a snippet of which is below:
import numpy as np
from scipy import stats
from statsmodels.distributions.copula.api import (
CopulaDistribution, IndependenceCopula, GaussianCopula)
import random
random.seed(10)
number_sample = 100000
marginals = [stats.norm, stats.norm]
# Case 1: independence
# JOINT PDF
joint_dist = CopulaDistribution(copula=IndependenceCopula(), marginals=marginals)
sample1 = joint_dist.rvs(number_sample, random_state=10)
#PDF X - Y
sample_xy1 = sample1[:, 0] - sample1[:, 1]
print(np.std(sample_xy1))
# Case 2: Dependence
# JOINT PDF
copula = GaussianCopula(corr=[[1,0.5],[0.5,1]], k_dim=2, allow_singular=False)
joint_dist = CopulaDistribution(copula, marginals)
sample2 = joint_dist.rvs(number_sample, random_state=10)
#PDF X - Y
sample_xy2 = sample2[:, 0] - sample2[:, 1]
print(np.std(sample_xy2))
The result is that the stdev of the function $Z=(X-Y)$ when $X$ and $Y$ are independent equals $(X^2+Y^2)^{0.5}$, but when they are correlated the value is smaller, although according to theory it should be larger.... What am I doing wrong?