Skip to main content

Benford's law analysis

Benford's law is a digit-law, which states that the distribution of seperate digits in numbers follow a specific frequency. This specific frequency is seen in many numerical datasets, as discovered by Simon Newcomb and Frank Benford. You can find on wikipedia more information about this mysterious law.

Benford's law might be helpful to detect fraud, do science, or just investigate the quality of data.

Installation

By pip install benfordslaw-analysis you will install the package.

Usage

Now you can do from benfordslaw_analysis.analysis import Analysis. You have now imported the class Analysis. Now you can play around with your data and test if Benford's law is hidden in your data, by inserting a list or a pandas series into the class object.

For example, make a plot with Benford's law versus random data with:

from benfordslaw_analysis.analysis import Analysis
from random import uniform
random_data = [uniform(-10, 10) for i in range(0,1000)]
bl = Analysis(random_data)
bl.plot_first_digit('Random stuff')

Test Image 1

Note that we use the Euclidean distance between the digit frequency from Benford's law and your own data as a measure and that we use Poisson error bars (based on the number of data points).

Euclidean distance

The normalized Euclidean distance is a nice way to test how Benford your data is. This value is situated between 0 and 1, the closer to 0 the better. However, it is not a formal statistic because it is sample size independent. In the literature there are several other measures (Chi-square, Kolmogorov-Smirnov, ..) that are used but I noticed in my own research that size dependency is a limitation in bigger datasets and classifies all bigger datasets as non-Benford, even though they are Benford by eye. More about the justification of using the Euclidean distance is explained in my own paper in Appendix D.

Citing

If you find benfordslaw_analysis a useful tool for your own research, please cite in the following way:

@misc{benford_py,
      author = {Jurjen, de Jong},
      title = {{benfordslaw_analysis: a Python Implementation of Benford's Law analysis}},
      year = {2021},
      howpublished = {\url{https://github.com/jurjen93/Benfords_law}},
}

Metadata

Release files for benfordslaw-analysis 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benfordslaw-analysis 1.0.3
File Size Uploaded
benfordslaw_analysis-1.0.3.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for benfordslaw-analysis 1.0.3
File Interpreter ABI Platform
benfordslaw_analysis-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / benfordslaw_analysis-1.0.3.tar.gz

Download URL benfordslaw_analysis-1.0.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f1a878ac67110edec59abb53015c376218398bfd92d666930eb62dfba843929f
BLAKE2b-256 checksum
How to use checksums
167a651a1a19da55e00823cdca5e1e09fb281bfa3fff06b23b25a64f3ead8f8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release files / benfordslaw_analysis-1.0.3-py3-none-any.whl

Download URL benfordslaw_analysis-1.0.3-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6d6267a9f7b84a13ea0a8bed6083a1891d4d27ddb18149b3c8cfc1753140684
BLAKE2b-256 checksum
How to use checksums
6ec4eb8b57d499d4c28aaa56932aff6970145513e9a5ca4355abe594c7ef6e1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page