1
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

let's put in the covariance term so that we can see how correlation impact the variance of 𝑋±𝑌: Var(𝑋±𝑌)=Var(𝑋)+Var(𝑌)±2Cov(𝑋,𝑌)

In your case, it should be: Var(𝑋-𝑌)=Var(𝑋)+Var(𝑌)-2Cov(𝑋,𝑌) where you assumed X positively correlates with Y which means the covariance term is positive.

So the variance/stdev of Z should be theoretically smaller.

$\endgroup$
3
  • $\begingroup$ Thanks but please check stats.stackexchange.com/questions/404799/…. Here the correlation term is positive when the correlation coeff is positive $\endgroup$
    – jpcgandre
    Commented Aug 25, 2023 at 18:46
  • 1
    $\begingroup$ the question in the link is X+Y but the question here it's X-Y. yes, the covariance is positive when correlation is positive. But there are still a sign before that term. $\endgroup$ Commented Aug 25, 2023 at 18:59
  • $\begingroup$ Ok i was honestly having a crisis because of this... Thanks for clarifying $\endgroup$
    – jpcgandre
    Commented Aug 25, 2023 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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