Suppose one has a list of vectors v1, v2, … vn. One wants to construct a new vector w such that the correlation between the new vector w and v1 is r1, the correlation between w and v2 is r2, … and the correlation between the new vector w and vn is rn. How do you do it? Here’s code adapted from an R version that does it for the special case when n = 1. But I haven’t figured out how to extend it to settings where n = 2, n = 3, etc. I am pretty confident there will be vectors v1, v2, …, vn and correlations r1, r2, … rn where no solution exists, but I am confident here will be situations where such a vector does exist.
simcor[x_, ymean_, ysd_, \[Rho]_ : 0] :=
Module[{y, z, lmf},
y = RandomVariate[NormalDistribution[], Length[x]];
lmf = LinearModelFit[{Transpose[{ConstantArray[1, Length[x]], x}],
y}];
z = \[Rho]*Standardize[x] +
Sqrt[1 - \[Rho]^2] Standardize[lmf["FitResiduals"]];
ymean + ysd*z
]
Bonus: the new vector here is normally distributed since its the sum of normally distributed variables. But what if one wants the new vector to be a 0-1 variable instead? Any ideas in either the one dimensional case or the multi-dimensional case whereby one can specify some correlation measure between the continuous variables v1 .. vn and the binary variable w, and out pops a vector w that has the requisite correlation measure(s)? I’m wondering if conceivably one could do some sort of thresholding or if one would use LogisticRegression and some other form of residuals instead of LinearRegression and FitResiduals. But, as you can probably tell, I really have no idea.
Note: I know one can use CopulaDistributions to generate vectors with various correlation matrices. And you should get variables that are correlated. But that isn’t quite my problem. One can’t, so far as I know, use RandomVariate on a Copula to hold all but one of the vectors fixed and generate a new vector.
All help appreciated!