

These files build C++ programs for computing the (complementary)cdf of the two-sided one sample Kolmogorov-Smirnov (KS) test statistic (Dn) when the underlying cdf (F(x)) is (dis)continuous, using Fast Fourier Transform (FFT) method.


# Building the binaries

I've tried to build the code on Linux and Mac OSX only. Building on Windows will be possible (e.g. using Cygwin or some other GCC installation).

Prerequisite: The [FFTW3](http://www.fftw.org/) library. [Installation instructions](http://www.fftw.org/download.html).


# To calculate the (complementary)cdf of the two-sided one sample KS test statistic, (P(Dn >= q)), when the underlying cdf is (dis)continuous, we follow the procedures below:

1). 
    (I) 
        Define the mixed cdf F(x) in the function “vector<double> MixDF (vector <double> obs)” in the file “crossprob.cc”.

    (II)
        In the file “crossprob.cc”, define the vector containing points where F(x) has jumps,
“vector_input3” in the “int main()” function.


############################################################################################################

2).In the command line tool (e.g., bash), change the current directory to where the folder “Exact_KS_FFT_source_code” is located. 

   Then, run “make” in the command line tool (e.g., bash), to build the program modified from [Moscovich and Nadler 2017].     

## Build errors?

If you installed FFTW3 on your system, the compilation should just work. If FFTW3 is not installed system-wide (e.g. because you do not have root priviliegies) then before configuring and building you need to:
* Build FFTW3.
* Add -I<FFTW include dir location> (pointing to wherever "fftw3.h" is located) to CXXFLAGS in the Makefile.
* Add the directory containing libfftw3 to the path in the environment variable LD_LIBRARY_PATH (on linux) or DYLD_LIBRARY_PATH (on OSX).


############################################################################################################

3). Then, run the following line “./bin/crossprob ecdf <n> Boundary_Crossing_Time.txt” in the command line tool, where n is the input for the sample size. 
    This will create a “Boundary_Crossing_Time.txt” file storing the integer-crossing times (see (7) on Page 5 of the manuscript of Dimitrova et al. (2017)). The “Boundary_Crossing_Time.txt” file will be located in the current directory, that is, where the folder “Exact_KS_FFT_source_code” is located.

(I). Following the screen prompt, the users first choose whether the underlying theoretical distribution function, F(x), is continuous or not, by inputting 1 or 2, respectively.

(II). 
     If the user chooses 1, (continuous F(x)), he/she needs to input the sample size, n.
     Then, the user will need to choose whether the complementary cdf of Dn or the p-value of the KS test is wanted, by inputting 1 or 2, respectively.
   
       If the user chooses 1, (Complementary cdf of Dn), he/she needs to input the quantile, q. 
     
       If the user chooses 2, (p-value of the KS test), he/she needs to input the observed values for the random sample from distribution F(x).
       Then, the value for the KS test statistic will be calculated and printed. 
        
   
     If the user chooses 2, (discontinuous F(x)), he/she needs to choose whether the complementary cdf of Dn or the p-value of the KS test is wanted, by inputting 1 or 2, respectively.
 
       If the user chooses 1, (Complementary cdf of Dn), he/she needs to input the sample size, n, and the quantile, q.
*******The users also have to specify the points where F(x) has jumps (see (II) in Step 1)).
       
 
       If the user chooses 2, (p-value of the KS test), he/she needs to input the observed values for the random sample from distribution F(x).
       Then, the value for the KS test statistic will be calculated and printed.
*******The users also have to specify the points where F(x) has jumps (see (II) in Step 1)).
       
############################################################################################################


# Outputs:   
   
   The value of the (complementary)cdf and the corresponding computation time will be printed on the screen in the command line tool.  

   Also, a “Boundary_Crossing_Time.txt" file containing the upper and lower rectangles of the uniform order statistics will be created in the current directory.
   More precisely, the upper rectangle is B_{i} in Steps 1, 2 of Dimitrova et al. (2017) (cf., (7)).
   The lower bound is A_{i} in Steps 1, 2 of Dimitrova et al. (2017) (cf., (7)).

   Note:
   A_{i}, B_{i} can also be seen as the integer-crossing times of the upper and lower bounds in the two-sided boundary-crossing problem of the process \eta_{n}(t) in Equation (5) on page 5 of Dimitrova et al. (2017).

   A_{i} represents the integer-crossing times of the upper bound h(t)
   B_{i} represents the integer-crossing times of the lower bound g(t)

############################################################################################################




# Contact

Feel free to ask any questions: senren.tan@cass.city.ac.uk

Senren Tan.

