Re: [R] 3D correlation

From: Martin Elff <>
Date: Wed, 6 Feb 2008 10:53:38 +0100

On Wednesday 06 February 2008 (01:35:15), wrote:
> how to generate correlated data which is correlated in three variables??

# Your correlation matrix
S <- rbind(



# Three independent normal variates

x1 <- rnorm(1000)
x2 <- rnorm(1000)
x3 <- rnorm(1000)

# Using the cholesky decomposition of S
Y <- cbind(x1,x2,x3)%*%chol(S)

# Three correlated normal variates

y1 <- Y[,1]
y2 <- Y[,2]
y3 <- Y[,3]

# Check

There may be more elegant and general solutions and you can also use package "mvtnorm" to get correlated normal (or t) variates. But the principle comes down to this.

Hope that helps,

Martin mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 06 Feb 2008 - 09:57:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Feb 2008 - 10:30:12 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive