double chiSquareCDF(double x, int k) { if (x <= 0) return 0.0; if (k <= 0) return double.nan; return _lowerRegularizedGamma(k / 2.0, x / 2.0); }