Learn R Programming

BenfordTests (version 0.5)

chi_square_benford: Pearsons's Chi-squared Goodness-of-Fit Test for Benford's Law

Description

chi_square_benford 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

chi_square_benford(x = NULL, first_digits = 1, pvalmethod = "asymptotic", pvalsims = 10000)

Arguments

x
A numeric vector.
first_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".

Value

  • A list with class "code{htest}" containing the following components:
  • statisticthe value of the chi-squared test statistic
  • p.valuethe p-value for the test
  • methoda character string indicating the type of test performed

Details

A chi-square goodness-of fit test is performed on leading_digits(x,first_digits) versus pbenf(first_digits). x is a numeric vector of arbitrary length. Values of x should be continuous, as dictated by theory, but may also be integers. first_digits should be chosen so that leading_digits(x,first_digits) is not influenced by previous rounding.

References

Benford F. The law of anomalous numbers. Proceedings of the American Philosophical Society. 1938;78:551-572. Pearson K. 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. 1900;50(302):157-175.

See Also

pbenf