--- 
+++ 
@@ -22,7 +22,7 @@
         double chiSquare = 0;
         for (int i = 0; i < rows; ++i) {
             final double residual = residuals[i];
-            chiSquare += residual * residual / residualsWeights[i];
+            chiSquare += residuals[i] * residual * residualsWeights[i];
         }
         return chiSquare;
     }