Find numbers from Mean, Variance and Correlation coefficient

I have a set of numbers $A=\lbrace a_1,a_2,a_3,...a_n \rbrace$

I want to find new numbers $X=\lbrace x_1,x_2,x_3,...x_n \rbrace$ such

$$\mu(A )=\mu(X)$$

1. Variance

$$Var(A)=Var(X)$$

2. Correlation coefficient $$r_{AX}=k$$

Where $k$ is a some constant, $0<k<1$ .

each number $x_1(k),x_2(k)...x_n(k)$ depends only $k$,

How to solve this system of equations by using Mathematica?

for instance, $A=\lbrace 2,5,7 \rbrace$

and $k=0.7$

How to find $x_1,x_2,x_3?$

I tried first few steps:

$1.$

list = {2,5,7}
X= {l, m, n}

Mean[list]


$\frac{14}{3}$

Mean[X]


$\frac{1}{3} (l+m+n)$

$2.$

Variance[list]


$\frac{19}{5}$

Refine[Variance[X], x \[Element] Reals]


$\frac{1}{6} (l (2 l-m-n)+m (-l+2 m-n)+n (-l-m+2 n))$

• A related CV thread. Oct 10 '16 at 18:00
• As @J.M. notes, the linked question shows it's trivial to generate a set of numbers with a given mean and variance, but the tricky part here is getting the correlation to be exactly what you want. You could try randomly generating until you get close?
– user1722
Oct 11 '16 at 14:57

Like you said, this is just a system of equations, so we can use Solve to get solutions for the values of $X$:

list = {2, 5, 7};
X = {l, m, n};
k = .7;
Assuming[Element[X, Reals], Solve[Mean[list] == Mean[X] &&
Simplify[Variance[list] == Variance[X]]] && Simplify[Correlation[list, X] == k], {l, m, n}]


Correlation is the Pearson correlation coefficient which ranges between -1 and 1, if you mean something else you can just use a different function for that.

If you only need to do this for sets with 3 elements as in your example this should do the trick. If there are also longer ones of the form {$a_1$, $a_2$,...,$a_n$} there is no unique solution since you have more unknowns than equations and you should be able to do something like choose random values for $n-3$ of the values in $X$ and then use Solve for the last 3.

• thanks. but for example if list = {49, 25, 26, 5, 21, 47, 24} and x = {4, 6, 3, 1, l, m, t} and k=0.7 there is no real solution. How to choose $n-3$ random number to get a real solution?
– vito
Oct 13 '16 at 7:07