signifd {BenfordTests} | R Documentation |
First Digits Function
Description
Applies the first digits function to each element of a given vector.
Usage
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^{\left( -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
#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