meandigit.benftest {BenfordTests} | R Documentation |
Judge-Schechter Mean Deviation Test for Benford's Law
Description
meandigit.benftest
takes any numerical vector reduces the sample to the specified number of significant digits and performs a goodness-of-fit test based on the deviation in means of the first digits' distribution and Benford's distribution to assert if the data conforms to Benford's law.
Usage
meandigit.benftest(x = NULL, digits = 1, pvalmethod = "asymptotic", pvalsims = 10000)
Arguments
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. Either |
pvalsims |
An integer specifying the number of replicates used if |
Details
A statistical test is performed utilizing the deviation between the mean digit of signifd(x,digits)
and pbenf(digits)
.
Specifically:
a^*=\frac{|\mu_k^o-\mu_k^e|}{\left(9\cdot10^{k-1}\right)-\mu_k^e}
where \mu_k^o
is the observed mean of the chosen k
number of digits, and \mu_k^e
is the expected/true mean value for Benford's predictions.
a^*
conforms asymptotically to a truncated normal distribution under the null-hypothesis, i.e.,
a^*\sim truncnorm\left(\mu=0,\sigma=\sigma_B,a=0,b=\infty\right)
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.
Value
A list with class "htest
" containing the following components:
statistic |
the value of the |
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 |
Author(s)
Dieter William Joenssen Dieter.Joenssen@googlemail.com
References
Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society. 78, 551–572.
Judge, G. and Schechter, L. (2009) Detecting Problems in Survey Data using Benford's Law. Journal of Human Resources. 44, 1–24.
See Also
Examples
#Set the random seed to an arbitrary number
set.seed(421)
#Create a sample satisfying Benford's law
X<-rbenf(n=20)
#Perform a Judge-Schechter Mean Deviation Test
#on the sample's first digits using defaults
meandigit.benftest(X)
#p-value = 0.1458