There is a lot of utility in simulating experimental outcomes...for example, when doing a priori power analysis by Monte Carlo, when generating bootstrap distributions, etc.
To simulate paired observations appropriately its important to account for their paired correlations.
Here's a simple R script that accomplishes that, including a check for accuracy, illustrated for a case when 80% correlation is expected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#simulate random variables | |
x1 <- rnorm(1000, 0, 1) | |
x2 <- rnorm(1000, 0, 1) | |
plot(x1,x2) | |
#correlate them | |
r=0.8 | |
k<- sqrt(1-r^2) | |
x2 <- r*x1+k*x2 | |
#confirm | |
plot(x1, x2) | |
cor(x1, x2) |