Fix confidence interval computation bugs for edge cases
In the case where the standard deviations were 0, the values for the
confidence intervals blew up to infinity due to divisions by zero. These
cases are now handled correctly.
@@ -145,14 +145,20 @@ function getConfidenceIntervalBorders(
regressionFunction,
);
- const diffMargins = dataPointsOfRegression.map(
- (data) =>
+ const diffMargins =
+ stdErr === 0 || stdOfX === 0
+ ? dataPointsOfRegression.map((data) => 0)
+ : dataPointsOfRegression.map((data) =>
+ Number.parseFloat(
+ (
tValue *
stdErr *
Math.sqrt(
1 / actualData.length +
Math.pow(getXValue(data) - meanOfX, 2) /
((actualData.length - 1) * Math.pow(stdOfX, 2)),
+ )
+ ).toPrecision(4),
),
);
