Learn R Programming

BenfordTests (version 1.2.0)

mdist.benftest: Chebyshev Distance Test (maximum norm) for Benford's Law

Description

mdist.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 Chebyshev distance between the first digits' distribution and Benford's distribution to assert if the data conforms to Benford's law.

Usage

mdist.benftest(x = NULL, digits = 1, pvalmethod = "simulate", 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. Currently only "simulate" is available.
pvalsims
An integer specifying the number of replicates used if pvalmethod = "simulate".

Value

  • A list with class "code{htest}" containing the following components:
  • statisticthe value of the Chebyshev distance (maximum norm) test statistic
  • p.valuethe p-value for the test
  • methoda character string indicating the type of test performed
  • data.namea character string giving the name of the data

Details

A statistical test is performed utilizing the Chebyshev distance between signifd(x,digits) and pbenf(digits). Specifically: $$m = \max\limits_{i=10^{k-1},\ldots,10^k-1}\left|f_i^o - f_i^e\right|\cdot\sqrt{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.

References

Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society. 78, 551--572. Leemis, L.M., Schmeiser, B.W. and Evans, D.L. (2000) Survival Distributions Satisfying Benford's law. The American Statistician. 54, 236--241. Morrow, J. (2010) Benford's Law, Families of Distributions and a Test Basis. [available under http://www.johnmorrow.info/projects/benford/benfordMain.pdf]

See Also

pbenf, simulateH0

Examples

Run this code
#Set the random seed to an arbitrary number
set.seed(421)
#Create a sample satisfying Benford's law
X<-rbenf(n=20)
#Perform a Chebyshev Distance Test on the
#sample's first digits using defaults
mdist.benftest(X)
#p-value = 0.6421

Run the code above in your browser using DataLab