Efficient algorithm to calculate Correlation between two Arrays

11,270

You need to calculate the sample Pearson product-moment correlation coefficient: "The above formula suggests a convenient single-pass algorithm for calculating sample correlations". Write a loop to calculate sum(xi), sum(yi), sum(xi^2), sum(yi^2), and sum(xi*yi). Then insert these sums into the formula.

Share:
11,270
EBAG
Author by

EBAG

Updated on August 21, 2022

Comments

  • EBAG
    EBAG over 1 year

    I'm looking for an algorithm to calculate correlation between two array of doubles.

    What are the names of the algorithms and I need c++ source code if it's possible.

    And by correlation I mean the similarity of data in the array...

    for example:

    Array1: 1 2 3 Array2: 2 3 5

    should have a higher similarity measure than these 2 arrays:

    Array1: 1 2 3 Array2: 9 8 15