# [Rd] ks.test (Kolmogorov-Smirnov) (PR#7725)

jpnolan at american.edu jpnolan at american.edu
Mon Mar 14 06:12:27 CET 2005

Full_Name: John Nolan
Version: 2.0.1
OS: Win XP
Submission from: (NULL) (151.200.9.43)

I think there are two small bugs in the Kolmogorov Smirnov test routines.

(1) In the R function ks.test, toward the bottom, the internal function pkstwo
does:

p[IND] <- .C("pkstwo", as.integer(length(x)), p = as.double(x[IND]),
as.double(tol), PACKAGE = "stats")\$p

Instead of length(x), shouldn't length(x[IND]) be passed?  If there are NAs,
length(x) > length(x[IND]) and the called C routine will try to process more
values than it should.

(2) In C routine ks.c, the function pkstwo describes two series it evaluates,
depending on whether x > 1 or x < 1.  The second case uses a formula described

*   = \sqrt{2\pi/x} \sum_{k=1}^\infty \exp(-(2k-1)^2\pi^2/(8x^2))

The code actually evaluates  \sqrt{2\pi}/x, not \sqrt{2\pi/x}.  I am not sure
which equation is right: both agree at x=1 so there is no easy test here.
If the equation is correct, the code should be changed to have w =
0.5*log(x[i]),
not w = log(x[i]).  If the code is right, change the equation in the comment.

John Nolan
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8269407749176025, "perplexity": 9678.59841384779}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-50/segments/1480698542288.7/warc/CC-MAIN-20161202170902-00257-ip-10-31-129-80.ec2.internal.warc.gz"}