Last active
November 29, 2015 17:51
-
-
Save ngsilverman/2e17a3085c6a3855862b to your computer and use it in GitHub Desktop.
Calculating a correlation on Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* We've collected a week's worth of data about ice cream consumption | |
* and general happiness for a particular individual | |
*/ | |
double[] iceCreamPerDay = new double[] { | |
1, // Day one, had 1 ice cream | |
0, // Day two, no ice cream :( | |
0, // Etc | |
1, | |
2, | |
1, | |
0 }; | |
// Happiness is rated on a 1 to 10 scale | |
double[] happinessPerDay = new double[] { 7, 5, 4, 6, 9, 9, 5 }; | |
PearsonsCorrelation math = new PearsonsCorrelation(); | |
double correlation = math.correlation(iceCreamPerDays, happinessPerDays); | |
// outputs: 0.8713708444711573 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment