milcent / benford_py

Python implementation of Benford's Law tests.
BSD 3-Clause "New" or "Revised" License
151 stars 52 forks source link

Selection of tests to be subjected to Zscore (and other stats that use sample size) in Benford object #41

Closed milcent closed 3 years ago

milcent commented 4 years ago

Currently, the Benford object, after internalizing the data, perfoms all first order tests (F1D, F2D, F3D, SD and L2D) by default. Then one can use other methos so it also includes the Summation (F1D_Sum, F2D_Sum and F3D_Sum), the Mantissas and the Second Order (F1D_Sec, F2D_Sec...) tests. However, when the data do not span across multiple orders of magnitude, some digits combinations may have no hits, especially the First-Two-Digits (45, 77...) and First-Three-Digits (122, 670,...), which will cause a DivisionbyZero error when computing the Z scores, since it uses the number of hits as denominator, as well noticed by @ditlevjoergensen in #40. Ideally, then, when initializing, there should be some safeguard preventing the Z scores of even being called on that Test object if there are no hits, and the user is informed of that if the verbose flag is on.

milcent commented 3 years ago

Inserted a fix in _setN function, so it won't return 0

ditlevjoergensen commented 3 years ago

Fantastic job!