-
-
Save cristianounix/6123472c5c24207d9e2803ba902ea589 to your computer and use it in GitHub Desktop.
Function that generate a dataset with a given correlation
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
# tks jerimi ann walker | |
make_data_correlated = function(corr, n){ | |
x = rnorm(n,0,1) | |
y = rnorm(n,0,1) | |
a = corr/(1-corr^2)^0.5 | |
z=a*x+y | |
the_data = data.frame(x,z) | |
return(the_data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment