I would like to generate test data for script used for correlation analysis between quite long variables.
Is it possible for a given length of vectors, to generate in relatively simple way deterministic input data that have Pearson correlation coefficient equal almost exactly given r (e.g. 0.5,0.6.,0.7, etc.) ?
In R I tried something like the following:
#0.7 ---> r = 0.691 cor(1:1000,(1:1000)^8.8) #0.4 ---> r = 0.39918 cor(1:1000,(1:1000)^34.11) #0 ---> r = 6.526891e-06 cor(1:1000,sin(100*(1:1000))^9)
I'm looking for a (relatively) compact formula that generates such input vectors of length $n$ for given $r$ with required precision (e.g.precision=0.000001)
To simplify problem I don't care about p-value/significance.