Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/Benford_tests.R
ks.benftest
takes any numerical vector reduces the sample to the specified number of significant digits and performs the Kolmogorov-Smirnov goodness-of-fit test to assert if the data conforms to Benford's law.
1 | ks.benftest(x = NULL, digits = 1, pvalmethod = "simulate", pvalsims = 10000)
|
x |
A numeric vector. |
digits |
An integer determining the number of first digits to use for testing, i.e. 1 for only the first, 2 for the first two etc. |
pvalmethod |
Method used for calculating the p-value. Currently only |
pvalsims |
An integer specifying the number of replicates used if |
A Kolmogorov-Smirnov test is performed between signifd(x,digits)
and pbenf(digits)
.
Specifically:
D = \sup\limits_{i=10^{k-1},…,10^k-1} ≤ft| \displaystyle∑_{j=1}^{i} ( f_j^o - f_j^e ) \right|\cdot √{n}
where f_i^o denotes the observed frequency of digits i, and f_i^e denotes the expected frequency of digits i.
x
is a numeric vector of arbitrary length. Values of x
should be continuous, as dictated by theory, but may also be integers.
digits
should be chosen so that signifd(x,digits)
is not influenced by previous rounding.
A list with class "htest
" containing the following components:
statistic |
the value of the Kolmogorov-Smirnov D test statistic |
p.value |
the p-value for the test |
method |
a character string indicating the type of test performed |
data.name |
a character string giving the name of the data |
Dieter William Joenssen Dieter.Joenssen@googlemail.com
Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society. 78, 551–572.
Joenssen, D.W. (2013) Two Digit Testing for Benford's Law. Proceedings of the ISI World Statistics Congress, 59th Session in Hong Kong. [available under http://www.statistics.gov.hk/wsc/CPS021-P2-S.pdf]
Kolmogorov, A.N. (1933) Sulla determinazione empirica di una legge di distibuzione. Giornale dell'Istituto Italiano degli Attuari. 4, 83–91.
1 2 3 4 5 6 7 8 | #Set the random seed to an arbitrary number
set.seed(421)
#Create a sample satisfying Benford's law
X<-rbenf(n=20)
#Perform a Kolmogorov-Smirnov Test on the
#sample's first digits using defaults
ks.benftest(X)
#0.7483
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.