00001 /* correlate - calculate r, also known as Pearson's correlation 00002 * coefficient. r*r has the nice property that it explains 00003 * how much of one variable's variation can be explained as 00004 * a linear function of the other variable's variation. */ 00005 #ifndef CORRELATE_H 00006 #define CORRELATE_H 00007 00008 struct correlate 00009 /* This helps manage correlations. */ 00010 { 00011 struct correlate *next; /* Next in list */ 00012 double sumX; /* Sum of all X's so far. */ 00013 double sumY; /* Sum of all Y's so far. */ 00014 double sumXY; /* Sum of all X*Y */ 00015 double sumXX; /* Sum of all X*X */ 00016 double sumYY; /* Sum of all Y*Y */ 00017 int n; /* Number of samples. */ 00018 }; 00019 00020 struct correlate *correlateNew(); 00021 /* Return new correlation handler. */ 00022 00023 void correlateFree(struct correlate **pC); 00024 /* Free up correlator. */ 00025 00026 void correlateNext(struct correlate *c, double x, double y); 00027 /* Add next sample to correlation. */ 00028 00029 double correlateResult(struct correlate *c); 00030 /* Returns correlation (aka R) */ 00031 00032 double correlateArrays(double *x, double *y, int size); 00033 /* Return correlation of two arrays of doubles. */ 00034 00035 #endif /* CORRELATE_H */ 00036
1.5.2