chisq.benftest: Pearson's Chi-squared Goodness-of-Fit Test for Benford's Law

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

View source: R/Benford_tests.R

Description

chisq.benftest takes any numerical vector reduces the sample to the specified number of significant digits and performs Pearson's chi-square goodness-of-fit test to assert if the data conforms to Benford's law.

Usage

1
chisq.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 "asymptotic" or "simulate".

pvalsims

An integer specifying the number of replicates to use if pvalmethod = "simulate".

Details

A χ^2 goodness-of-fit test is performed on signifd(x,digits) versus pbenf(digits). Specifically:

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

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 χ^2 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.

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]

Pearson, K. (1900) On the Criterion that a Given System of Deviations from the Probable in the Case of a Correlated System of Variables is Such that it can be Reasonably Supposed to have Arisen from Random Sampling. Philosophical Magazine Series 5. 50, 157–175.

See Also

pbenf, simulateH0

Examples

1
2
3
4
5
6
7
8
9
#Set the random seed to an arbitrary number
set.seed(421)
#Create a sample satisfying Benford's law
X<-rbenf(n=20)
#Perform a Chi-squared Test on the sample's 
#first digits using defaults but determine
#the p-value by simulation
chisq.benftest(X,pvalmethod ="simulate")
#p-value = 0.6401

Example output

	Chi-Square Test for Benford Distribution

data:  X
chisq = 5.9932, p-value = 0.6401

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