# kolmogorov-smirnov test using package BenfordTests in R

I am using the ks.benftest from the BenfordTests package in R to calculate the D Statistic and p-value of a distribution with respect to a distribution that conforms with Benford Law. The problem I have is that the ks.benftest function gives me a different result from just using function ks.test.

The code I used for both functions with the data is below:

x <- c(rep(1,10),rep(2,5),rep(3,3),rep(4,5),rep(5,6),7)

y <- c(rep(1,9),rep(2,5),rep(3,4),rep(4,3),rep(5,3),rep(6,2),rep(7,2),8,9)


x variable is the distribution I want to confirm follows benford distribution; y variable follows the benford distribution

z<- as.data.frame(t(rbind(x,y)))

pval_bftest <- ks.benftest(z$x,digits=1)$p.value

Dstat_bftest <- ks.benftest(z$x,digits=1)$statistic


pval_bftest = 0.1001

Dstat_bftest = 1.032541

However, when I use the ks.test function, I get very different results

ksTest <- ks.test(z$x,z$y,alternative=c("two.sided"))

ksTest


Two-sample Kolmogorov-Smirnov test

data:  z$x and z$y

D = 0.16667, p-value = 0.799

alternative hypothesis: two-sided


Does anyone know what I'm doing wrong? I should get similar results, but I'm not.

Thanks

T

• Benford's law i a law that describes the frequency of the lead digit in a set of positive integers. For example if we have a book with 210 pages the lead digit is 1 for 1, 10-19 and 100-199. Far from uniform we see the frequency for 1 is 111. For 2 the numbers 2, 20-29 and 200-210 have lead digit 2. So the frequency for 2 is 22. For 3: 3 and 30 -39 a frequency of 11. For 4: 4 and 40-49. a frequency of 11. Similarly all the numbers from 5 -9 also have a frequency. Dec 12 '16 at 22:58
• According to wikipedia Frank Benford was the second person to observe this phenomena. But it was named for him anyway. In my example divide by 210 and you get a discrete distribution for the lead digit of this data. The point noted was that 1 has by far the highest proportion. The distribution is not unique. It depends on the collection of numbers. Did you pick a set of data and compare to the distribution Benford used? If so did you apply one data set with each goodness of fit test that you used? Dec 12 '16 at 23:05
• I guess the answer to my question is that you used the same data. But the question is how does ks.test differ from ks.benftest? Dec 12 '16 at 23:14
• @Michael, that's the question I'm asking really. How is ks.test different from ks.benftest Dec 12 '16 at 23:19
• Since you know R and know what you you input what I was suggesting is that maybe you can help us answer the question. Dec 13 '16 at 0:27

The Kolmogorov-Smirnov test using the usual tables (or some computer implementation of the null distribution) is designed for testing completely specified continuous distributions. (The help for ks.test even tells you this, in the first paragraph under Details -- indeed, the word continuous is emphasized there.)