1
$\begingroup$

I could not find anywhere, how to calculate correlation between two arrays. Say I do have Array1 with X and Y values and also Array2 with X and Y values. I tried to do some calculation and inserting two same arrays and expecting the correlation to be 1, but the result was something like -0.16...

I would be glad for any suggestion. Btw. I've found this Correlation coefficient between two arrays of 2D points? but still didnt find anything what could help me.

$\endgroup$
  • 1
    $\begingroup$ To be clear, you want to compute the correlation between two matrices? Look into the RV coefficient, it is a multivariate extension of the R-squared. $\endgroup$ – Slow loris May 11 '16 at 15:36
  • $\begingroup$ Wel, I have two arrays full of data like this. [0] => Array ( [x] => 964 [y] => 844 ). The arrays are same size. And now I would like to find programmatically correlation between this. Was googling for RV coefficient matlab examples, but did not find anything useful. $\endgroup$ – Wiggler Jtag May 11 '16 at 15:49
  • $\begingroup$ I don't use MatLab, but you can do it in R using the coeffRV function in the FactoMineR package. $\endgroup$ – Slow loris May 11 '16 at 16:56
2
$\begingroup$

An array with 2 dimensions is a matrix. Since your arrays have 2 dimensions, you are looking to find the correlation between these two matrices.

Here is a question with answers in R: "Correlation between matrices in R"

Here is a question with answers in MATLAB: "Matlab correlation between two matrices"

$\endgroup$
  • $\begingroup$ Thanks for the answer, but I dont understand, why in one example I am getting output one value and in the other example I am getting an output matrix. And also, should this 2D array be stored in matrix as MAT[vec2(X,Y), vec2(X,Y)....] and so? Or what is the best way to store these X and Y values in the matrix to pass to matlab for example? $\endgroup$ – Wiggler Jtag May 11 '16 at 16:44
  • $\begingroup$ For those answers you need to read the MATLAB's documentation for the function you are using. For instance, here is the documentation for the function "corrcoef": se.mathworks.com/help/matlab/ref/corrcoef.html $\endgroup$ – PeyM87 May 12 '16 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.