各位好:
请问如何生成三组uniform random variable (x, Y, Z)且Corr(X,Y)不等於零,Corr(X,Z)不等於零,Corr(Y,Z)不等於零?谢谢
下面为生成两组correlation不等於零的uniform random variable。
This can be implemented by the following code: n <- 100 p <- 0.6 # (say) X <- runif(n)-1/2 Z <- runif(n)-1/2 U <- rbinom(n,1,p) # =1 where Y=X, = 0 when Y independent of X Y <- X*U + Z*(1-U) XY <- cbind(X,Y) # your n by 2 matrix of bivariate (X,Y)Now the marginal distributions of X and Y are both uniform.var(X) = 1/12 and var(Y) = 1/12. Since the means are 0,cov(X,Y) = Exp(X*Y) = p*Exp(X^2) = p/12cor(X,Y) = cov(X,Y)/sqrt(var(X)*var(Y)) = (p/12)/(1/12) = p.So all you need to do to get a desired correlation rho betweenX and Y is to set p = rho.


雷达卡




京公网安备 11010802022788号







