I am interested in the relationship between the Pearson correlation coefficients and the permutations of two random number sequences.
An initial Mathematica study is as below:
SeedRandom[1]
(data=RandomReal[1,{30,2}])//MatrixForm;
Correlation[data[[All,1]],data[[All,2]]]
Correlation[Sort@data[[All,1]],data[[All,2]]]
Correlation[Sort@data[[All,1]],Sort@data[[All,2]]]
Correlation[Sort@data[[All,1]],Sort[#,Greater]&@data[[All,2]]]
Outputs are:
-0.0615673 (*correlation coefficient of the original order*)
0.209375 (*sorting the first sequence*)
0.981946 (*sorting both the two sequences in the same order*)
-0.964172 (*sorting both the two sequences in converse order*)
My questions are:
How can I find the permutation(s) when the correlation coefficient of the two sequences is the closest to zero?
Given a number between the minimum (-0.964172 for this case) and the maximum (0.981946 for this case), how to find the right permutations of which the correlation coefficient of the two sequences are closest to the given number?
I tried to use Permutations
and then search
(or Optimize/NMinimize) in the permutation
space, but always encountered into SystemException["MemoryAllocationFailure"]