Skip to content

Instantly share code, notes, and snippets.

@ngsilverman
Last active November 29, 2015 17:51
Show Gist options
  • Save ngsilverman/2e17a3085c6a3855862b to your computer and use it in GitHub Desktop.
Save ngsilverman/2e17a3085c6a3855862b to your computer and use it in GitHub Desktop.
Calculating a correlation on Android
/*
* 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