The Benford class is a high-level wrapper that ingests data and automatically runs a suite of tests (First Digit, Second Digit, First Two, First Three, and Last Two Digits) along with their statistics.
Initialization:
You can initialize it with a pandas Series/numpy array, or a tuple containing a DataFrame and the column name: bf.Benford((df, 'column_name'), decimals=...).
Key Attributes:
.tests: A list of all tests performed..data: The raw input data..base: The pre-processed data containing sequences (Seq), transformed values (ZN), and digit-specific records (F1D, F2D, F3D, SD, L2D)..all_confidences: Returns the current confidence levels for all tests.
Key Methods:
.report(): Called on a specific test attribute (e.g., benf.F1D.report()) to get detailed results..update_confidence(level, tests=None): Updates the confidence level for all tests (or a specific subset) without re-processing the data. This is useful for addressing the 'Power Problem' in large samples..summation(): Runs Summation Tests..sec_order(): Runs Second Order Tests.
# Initialize with a DataFrame and column name
benf = bf.Benford((sp, 'l_r'), decimals=8, limit_N=1800)
# Get a report for the First Two Digits test
print(benf.F2D.report())
# Update confidence for specific tests
benf.update_confidence(99.999, tests=['F2D', 'L2D'])