signifd: First Digits Function

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

View source: R/Benford_tests.R

Description

Applies the first digits function to each element of a given vector.

Usage

1
signifd(x = NULL, digits = 1)

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.

Details

The first digits function can be written as:

D_k(x) = \lfloor |x| \cdot 10^{≤ft( -1 \cdot \lfloor log_{10}|x| \rfloor + k -1 \right)}\rfloor

with k being the number of first digits that should be extracted. x is a numeric vector of arbitrary length. Unlike other solutions, this function will work reliably with all real numbers.

Value

Returns a vector of integers the same length as the input vector x.

Author(s)

Dieter William Joenssen Dieter.Joenssen@googlemail.com

References

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]

See Also

chisq.benftest; ks.benftest; usq.benftest; mdist.benftest; edist.benftest; meandigit.benftest; jpsq.benftest

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)
#Look at the first digits of the sample
signifd(X)
#should be:
#[1] 6 1 5 2 7 5 7 4 3 1 2 2 1 5 6 2 2 3 1 3

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