DEV Community

Cover image for Benford's Law Calculator
John Rock
John Rock

Posted on

4 1

Benford's Law Calculator

Benford's Law is a little known law that observes first digits in a naturally occurring data set. I just recently found out about it after watching episode four ("Digits") of the Netflix original series Connected. The law states that given a set of data, the first digits do not display a uniform distribution, but instead are arranged in a way that the digit "1" occurs most often, followed by "2", "3", etc.

Per Wikipedia

"It has been shown that this result applies to a wide variety of data sets, including electricity bills, street addresses, stock prices, house prices, population numbers, death rates, lengths of rivers..."

Because of this, Benford's Law has been used to detect anomalies and fraud.

I found this fascinating and wanted to build a calculator to test it on my own.

Using React and a little bit of Recharts I created an app that lets you input data, grab the first digits, calculate the percent of occurrence, and outputs the data to a chart.

Play around with the app here.
Screenshot of Benford's Law Calculator
View source

I highly recommend taking a look into Benford's Law yourself. It's one of those mind-boggling pieces of information that makes you question everything you've learned.
Alt Text

Cover photo by Ian Panelo from Pexels

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (1)

Collapse
 
thomas_james_24f9e9edc897 profile image
Thomas James

This is a fascinating concept! It's incredible how Benford's Law can apply to so many types of data. If you're interested in uncovering more about data trends and information, you might want to explore various records and searches related to public information. For example, you can check Arrests-ca.org or look into criminal history for comprehensive data insights. This can be a valuable resource for anyone working with large datasets or just curious about how such laws can reveal hidden patterns.

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay