Learn R Programming

BenfordTests (version 1.2.0)

jointdigit.benftest: A Hotelling T-square Type Test for Benford's Law

Description

jointdigit.benftest takes any numerical vector reduces the sample to the specified number of significant digits and performs a Hotelling T-square type goodness-of-fit test to assert if the data conforms to Benford's law.

Usage

jointdigit.benftest(x = NULL, digits = 1, eigenvalues="all", tol = 1e-15, 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.
eigenvalues
How are the eigenvalues, which are used in testing, selected.
tol
Tolerance in detecting values that are essentially zero.
pvalmethod
Method used for calculating the p-value. Currently only "asymptotic" is available.
pvalsims
An integer specifying the number of replicates used if pvalmethod = "simulate".

Value

A list with class "htest" containing the following components:
statistic
the value of the $T^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
eigenvalues_tested
a vector containing the index numbers of the eigenvalues used in testing.
eigen_val_vect
the eigen values and vectors of the null distribution. computed using eigen.

Details

A Hotelling $T^2$ type goodness-of-fit test is performed on signifd(x,digits) versus pbenf(digits). x is a numeric vector of arbitrary length. argument: eigenvalues can be defined as:
  • numeric, a vector containing which eigenvalues should be used
  • string length = 1, eigenvalue selection scheme:
    • "all", use all non-zero eigenvalues
    • "kaiser", use all eigenvalues larger than the mean of all non-zero eigenvalues

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.

Hotelling, H. (1931). The generalization of Student's ratio. Annals of Mathematical Statistics. 2, 360--378.

See Also

pbenf

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  Test
#on the sample's first digits using defaults
jointdigit.benftest(X)
#p-value = 0.648
#Perform  Test
#using only the two largest eigenvalues
jointdigit.benftest(x=X,eigenvalues=1:2)
#p-value = 0.5176
#Perform  Test
#using the kaiser selection criterion
jointdigit.benftest(x=X,eigenvalues="kaiser")
#p-value = 0.682

Run the code above in your browser using DataLab