You are here: Symbol Reference > Statistics Namespace > Functions > Statistics.GOFKolmogorov Function
Stats Master VCL
ContentsIndex
PreviousUpNext
Statistics.GOFKolmogorov Function

One sample Kolmogorov-Smirnov GOF test.

Pascal
function GOFKolmogorov(const Data: TVec; out hRes: THypothesisResult; out Signif: double; const CDFx: TVec = nil; const CDFy: TVec = nil; hType: THypothesisType = htTwoTailed; Alpha: double = 0.05): double; overload;
Parameters 
Description 
Data 
Samples to be tested. 
hRes 
Returns the result of the null hypothesis (default assumption is that data comes from specific distribution). 
Signif 
(Significance level) returns the probability of observing the given result by chance given that the null hypothesis is true. 
CDFx 
Defines set of possible x values. 
CDFy 
Defines set of hypothesized CDF values, evaluated at CDFx. 
hType 
Defines the type of the null hypothesis (left, right and two - tailed). 
Alpha 
Defines the desired significance level. If the significance probability (Signif) is bellow the desired significance (Alpha), the null hypothesis is rejected. 

K-S statistics.

Performs one-sample Kolmogorov-Smirnov (KS) goodnes of fit test. The KS test is used to decide if a sample comes from a population with a specific distribution. Test is based on the empirical distribution function (ECDF). An attractive feature of this test is that the distribution of the K-S test statistic itself does not depend on the underlying cumulative distribution function being tested. Another advantage is that it is an exact test (the chi-square goodness-of-fit test depends on an adequate sample size for the approximations to be valid). Despite these advantages, the K-S test has several important limitations:

  • It only applies to continuous distributions.
  • It tends to be more sensitive near the center of the distribution than at the tails.
  • Perhaps the most serious limitation is that the distribution must be fully specified. That is, if location, scale, and shape parameters are estimated from the data, the critical region of the K-S test is no longer valid. It typically must be determined by simulation.

If CDFx and CDFy vectors are not defined, Data values are compared with standard normal distribution. If defined, CDFx and CDfy vectors represent hypothesized distribution x and CDF(x) values. In this case all Data values must lie within the [Min(CDFx),Max(CDFx)] interval. The KS test assumes CDFx and CDFy are predefined - KS test is not very accurate if CDFx and CDFy values are calculated from Data values.

In this example sample is generated using Normal (mu=2,sigma=1) distribution. Then a KS test is used to determine if sample comes from normal distribution. 

 

  Uses MtxExpr, Math387, Statistics;
  procedure Example;
  var d: Vector;
  hres:THypothesisResult;
  signif, KS: double;
  begin
    d.Size(300);
    RandomNormal(2,1,d,-1);

    KS := GOFKolmogorov(d, hRes, Signif, nil, nil, htTwoTailed, 0.05);
    // Result should be significance above 0.05 meaning d values
    // are normally distributed.
#include "MtxExpr.hpp"
#include "Math387.hpp"
#include "Statistics.hpp"
void __fastcall Example()
{
  THypothesisResult hres;
  double signif, KS;
  sVector d;
  d.Length = 300;

  RandomNormal(2,1,d,-1);

  KS = GOFKolmogorov(d, hres, signif, NULL, NULL, htTwoTailed, 0.05);

  // Result should be significance above 0.05 meaning d values
  // are normally distributed.
}
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!