@@ -9,34 +9,39 @@ public class CorrelationTest {
99
1010 public static final double DELTA = 1e-9 ;
1111
12+ // Regular correlation test
1213 public void testCorrelationFirst () {
1314 double [] x = {1 , 2 , 3 , 4 };
1415 double [] y = {7 , 1 , 4 , 9 };
1516 int n = 4 ;
1617 assertEquals (0.3319700011 , Correlation .correlation (x , y , n ), DELTA );
1718 }
1819
20+ // Regular correlation test (zero correlation)
1921 public void testCorrelationSecond () {
2022 double [] x = {1 , 2 , 3 , 4 };
2123 double [] y = {5 , 0 , 9 , 2 };
2224 int n = 4 ;
2325 assertEquals (0 , Correlation .correlation (x , y , n ), DELTA );
2426 }
2527
28+ // Correlation with a constant variable is taken to be zero
2629 public void testCorrelationConstant () {
2730 double [] x = {1 , 2 , 3 };
2831 double [] y = {4 , 4 , 4 };
2932 int n = 3 ;
3033 assertEquals (0 , Correlation .correlation (x , y , n ), DELTA );
3134 }
3235
36+ // Linear dependence gives correlation 1
3337 public void testCorrelationLinearDependence () {
3438 double [] x = {1 , 2 , 3 , 4 };
3539 double [] y = {6 , 8 , 10 , 12 };
3640 int n = 4 ;
3741 assertEquals (1 , Correlation .correlation (x , y , n ), DELTA );
3842 }
3943
44+ // Inverse linear dependence gives correlation -1
4045 public void testCorrelationInverseLinearDependence () {
4146 double [] x = {1 , 2 , 3 , 4 , 5 };
4247 double [] y = {18 , 15 , 12 , 9 , 6 };
0 commit comments