Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @brief Performs one sample Kolmogorov-Smirnov test
- * @param x points
- * @param d distribution name ('normal',...)
- * @return probability that points have given distribution
- */
- double StatUtils::kolmogorovSmirnovTest(Points1D x, const QString &d) {
- // Calculate size of array and sort it
- int n = x.size();
- qSort(x);
- // Choose distribution
- if (d.compare("normal") == 0 || d.compare("gauss")) {
- x = normcdf(zscore(x));
- } else {
- QString msg = QString("Kolmogorov-Smirnov test for %1 not implemented");
- logError(msg.arg(d));
- return -1;
- }
- // Calculate probability that given sequence of points belong to distribution
- Points1D a1 = MathUtils::div(MathUtils::sequence(0.0, (double) n + 0), n);
- Points1D a2 = MathUtils::div(MathUtils::sequence(1.0, (double) n + 1), n);
- Points1D asub1 = MathUtils::abs(MathUtils::sub(x, a1));
- Points1D asub2 = MathUtils::abs(MathUtils::sub(x, a2));
- double ks = sqrt(n) * MathUtils::max(MathUtils::max(asub1, asub2));
- return 1 - kolmogorovcdf(ks);
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement