Joint Random Variables, Covariance, and Correlation
SD04 — Random Variables
Author
Samer El Kababji
Course: Statistics and Probability for Data Science (DS14270). Source deck: Samer El Kababji, SD04 — Random Variables.
This lesson develops the deck’s joint-distribution example, derives marginal distributions, covariance, and correlation, and clarifies how zero covariance differs from independence. The practice questions and computational examples extend the deck’s concepts.
Joint and marginal distributions
For discrete random variables \(X\) and \(Y\), the joint PMF is
X Y probability XY
1 1 2 0.2 2
2 3 2 0.1 6
3 1 4 0.3 4
4 3 4 0.4 12
Code
c(E_X = E_X, E_Y = E_Y, E_XY = E_XY)
E_X E_Y E_XY
2.0 3.4 7.0
R matrices are stored column by column. expand.grid() changes its first column fastest, so as.vector(joint_pmf) aligns the four joint probabilities with the displayed \((X,Y)\) pairs.
Covariance
Covariance measures whether deviations from the two means tend to have the same sign or opposite signs:
a <-100b <--2transformed_covariance <-with( joint_grid,sum( ((a * X +5) - (a * E_X +5)) * ((b * Y -10) - (b * E_Y -10)) * probability ))c(transformed_direct = transformed_covariance,transformed_rule = a * b * covariance_moments)
transformed_direct transformed_rule
-40 -40
Independence and covariance
Discrete \(X\) and \(Y\) are independent when the joint PMF factors at every pair:
\[
p_{X,Y}(x,y)=p_X(x)p_Y(y)
\quad\text{for every }x,y.
\]
The sign describes direction and the magnitude describes the strength of a linear relationship:
Correlation
Interpretation
\(\rho=1\)
Perfect positive linear relationship
\(0<\rho<1\)
Positive linear association
\(\rho=0\)
No linear association; a nonlinear relationship may remain
\(-1<\rho<0\)
Negative linear association
\(\rho=-1\)
Perfect negative linear relationship
Correlation has no units and is unchanged by positive changes of scale and location. Multiplying exactly one variable by a negative number reverses its sign.
original positive_rescaling sign_reversal
0.2182179 0.2182179 -0.2182179
Correlation patterns in fictional data
The following simulation extends the deck’s correlation sketches. The same \(X\) values are paired with different amounts of noise to show why points spread farther from a straight line as \(|r|\) decreases.
From the joint table, compute \(P(X=3)\), \(P(Y=4)\), and \(P(X=3,Y=4)\).
Compute \(P(X=3\mid Y=4)\). Does it equal \(P(X=3)\)?
Verify \(\operatorname{Var}(Y)=0.84\) from the marginal PMF of \(Y\).
If \(U=5X+2\) and \(V=-3Y+1\), find \(\operatorname{Cov}(U,V)\) and \(\operatorname{Corr}(U,V)\).
Give a short reason why \(\rho=0\) does not prove independence.
NoteCheck your answers
The probabilities are \(0.5\), \(0.7\), and \(0.4\), respectively.
\(P(X=3\mid Y=4)=0.4/0.7\approx0.571\), which is not \(P(X=3)=0.5\).
\(E(Y^2)=2^2(0.3)+4^2(0.7)=12.4\), so \(\operatorname{Var}(Y)=12.4-3.4^2=0.84\).
\(\operatorname{Cov}(U,V)=5(-3)(0.2)=-3\). Because exactly one scale factor is negative, \(\operatorname{Corr}(U,V)=-0.2182\) approximately.
Correlation detects linear association only. For example, \(Y=X^2\) with a symmetric \(X\) can have covariance and correlation 0 while \(Y\) is fully determined by \(X\).