返回题库

生成相关的标准正态(相关系数 ρ\rho

Generate Correlated N(0,1)N(0,1)

专题
Algorithmic Programming / 算法编程
难度
L4

题目详情

已能生成独立的标准正态 N(0,1)N(0,1)。如何生成两个相关系数为 ρ\rhoN(0,1)N(0,1) 随机变量?

LU: For an invertible matrix AA, A=LUA=LU with LL lower-triangular, UU upper-triangular. Then Ax=bLUx=bAx=b\Rightarrow LUx=b, solve Ly=bLy=b then Ux=y.Ux=y.
Cholesky: If AA is symmetric PD, then A=RTRA=R^TR where RR is upper-triangular with positive diagonal.

Singular Value Decomposition (SVD): For any n×pn\times p matrix XX, there is a factorization
Xn×p=Un×pDp×pVp×pT,X_{n\times p}=U_{n\times p}D_{p\times p}V_{p\times p}^T,
with orthogonal U,VU,V and diagonal DD of singular values.

Question: Using a standard normal generator (for N(0,1)N(0,1)), how to generate two correlated N(0,1)N(0,1) variables with correlation ρ\rho?

解析

取独立 z1,z2N(0,1)z_1,z_2\sim N(0,1),令

x1=z1,x2=ρz1+1ρ2z2.x_1=z_1,\quad x_2=\rho z_1+\sqrt{1-\rho^2}\,z_2.

Var(x1)=Var(x2)=1\mathrm{Var}(x_1)=\mathrm{Var}(x_2)=1Corr(x1,x2)=ρ\mathrm{Corr}(x_1,x_2)=\rho


Original Explanation

Let z1,z2z_1,z_2 be i.i.d. N(0,1).N(0,1). Then define x1=z1,x2=ρz1+1ρ2z2.x_1 = z_1, \quad x_2 = \rho\,z_1 + \sqrt{1-\rho^2}\,z_2. Check var and cov to confirm the correlation is ρ.\rho.

In higher dimensions for N(μ,Σ)N(\mu,\Sigma), do a Cholesky factor Σ=RTR,\Sigma=R^T R, and set x=μ+RTz.x=\mu+R^T z. Or use Σ=UDUT\Sigma=U\,D\,U^T etc.