Timeline for Generate a random variable with a defined correlation to an existing variable(s)
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 18, 2016 at 3:55 | comment | added | Dave M |
Thanks; I noticed that if x1 is not standardized mean=0, sd=1, and you'd rather not rescale it, you'll need to modify the line: X2 <- mar.fun(n) to X2 <- mar.fun(n,mean(x),sd(x)) to get the desired correlation between x1 and x2
|
|
Oct 15, 2013 at 1:07 | comment | added | zzk | I know this is old, but I also want to note that this method won't work for non-positive definite correlation matrices. E.g - a correlation of -1. | |
Oct 5, 2011 at 10:11 | history | edited | Felix S | CC BY-SA 3.0 |
added 39 characters in body
|
Sep 8, 2011 at 12:31 | history | edited | Felix S | CC BY-SA 3.0 |
Clarified "exact correlation" vs. "population correation"
|
Sep 8, 2011 at 11:51 | history | edited | Felix S | CC BY-SA 3.0 |
added 168 characters in body
|
Sep 2, 2011 at 9:42 | vote | accept | Felix S | ||
Sep 3, 2011 at 16:12 | |||||
Sep 2, 2011 at 9:42 | history | edited | Felix S | CC BY-SA 3.0 |
added 25 characters in body
|
Sep 2, 2011 at 6:53 | history | edited | Felix S | CC BY-SA 3.0 |
deleted 136 characters in body
|
Sep 2, 2011 at 6:53 | comment | added | Felix S | The "small correction to rho" was in the original post and is described here. Actually, I don't really understand it; but an investigation of 50000 simulated correlations with rho = .3 shows that without the "small correction" an average of r's of .299 is produced, while with the correction an average of .312 (which is the value of the corrected rho) is produced. Therefore I removed that part from the function. | |
Sep 1, 2011 at 8:15 | comment | added | Wolfgang |
It is easy to show that, except for that "small correction to rho" (whose purpose in this context eludes me), this is exactly the same as what ttnphns suggested earlier. The method is simply based on the Choleski decomposition of the correlation matrix to obtain the desired transformation matrix. See, for example: en.wikipedia.org/wiki/…. And yes, this will only give you two vectors whose population correlation is equal to rho .
|
|
Aug 31, 2011 at 21:18 | comment | added | caracal | It seems this is only an approximate solution, i.e., the empirical correlation is not exactly equal to $\rho$. Or am I missing something? | |
Aug 31, 2011 at 17:51 | history | answered | Felix S | CC BY-SA 3.0 |