Skip to content

Instantly share code, notes, and snippets.

@cristianounix
Created March 4, 2018 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianounix/6123472c5c24207d9e2803ba902ea589 to your computer and use it in GitHub Desktop.
Save cristianounix/6123472c5c24207d9e2803ba902ea589 to your computer and use it in GitHub Desktop.
Function that generate a dataset with a given correlation
# 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