edist.benftest: Euclidean Distance Test for Benford's Law

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/Benford_tests.R

Description

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

Usage

1
edist.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".

Details

A statistical test is performed utilizing the Euclidean distance between signifd(x,digits) and pbenf(digits). Specifically:

d = √{n}\cdot √{\displaystyle∑_{i=10^{k-1}}^{10^k-1}≤ft(f_i^o - f_i^e\right)^2}

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.

Value

A list with class "htest" containing the following components:

statistic

the value of the Euclidean distance 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

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.

Cho, W.K.T. and Gaines, B.J. (2007) Breaking the (Benford) Law: Statistical Fraud Detection in Campaign Finance. The American Statistician. 61, 218–223.

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

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 Euclidean Distance Test on the
#sample's first digits using defaults
edist.benftest(X,pvalmethod ="simulate")
#p-value = 0.6085

Example output

	Euclidean Distance Test for Benford Distribution

data:  X
d_star = 0.78843, p-value = 0.6082

BenfordTests documentation built on May 1, 2019, 8:07 p.m.