Skip to content

Commit

Permalink
Merge branch 'hotfix/Chi2_KS_naming' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
milcent committed Apr 14, 2020
2 parents 37d7a4c + 7a02e7e commit 5ab5cf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions benford/benford.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
plot_mantissa_arc_test, plot_roll_mse, plot_roll_mad
from .reports import _inform_, _report_mad_, _report_test_, _deprecate_inform_,\
_report_mantissa_
from .stats import Z_score, chi_square, chi_square_2, KS, KS_2
from .stats import Z_score, chi_sq, chi_sq_2, kolmogorov_smirnov,\
kolmogorov_smirnov_2

class Base(DataFrame):
"""Internalizes and prepares the data for Analysis.
Expand Down Expand Up @@ -122,8 +123,8 @@ def __init__(self, base, digs, confidence, limit_N=None, sec_order=False):
self.N = _set_N_(len(base), limit_N)
self['Z_score'] = Z_score(self, self.N)
self.ddf = len(self) - 1
self.chi_square = chi_square_2(self)
self.KS = KS_2(self)
self.chi_square = chi_sq_2(self)
self.KS = kolmogorov_smirnov_2(self)
self.MAD = self.AbsDif.mean()
self.MSE = (self.AbsDif ** 2).mean()
self.confidence = confidence
Expand Down Expand Up @@ -646,12 +647,12 @@ def first_digits(self, digs, confidence=None, high_Z='pos',

# Chi-square statistic
if chi_square:
self.chi_square = chi_square(df, ddf=len(df) - 1,
self.chi_square = chi_sq(df, ddf=len(df) - 1,
confidence=confidence,
verbose=self.verbose)
# KS test
if KS:
self.KS = KS(df, confidence=confidence, N=len(temp),
self.KS = kolmogorov_smirnov(df, confidence=confidence, N=len(temp),
verbose=self.verbose)

# Plotting the expected frequncies (line) against the found ones(bars)
Expand Down Expand Up @@ -722,18 +723,18 @@ def second_digit(self, confidence=None, high_Z='pos',
if MAD:
self.MAD = df.AbsDif.mean()
if self.verbose:
_report_mad_(digs, self.MAD)
_report_mad_(22, self.MAD)
# Mean Square Error
if MSE:
self.MSE = (df.AbsDif ** 2).mean()

# Chi-square statistic
if chi_square:
self.chi_square = chi_square(df, ddf=9, confidence=confidence,
self.chi_square = chi_sq(df, ddf=9, confidence=confidence,
verbose=self.verbose)
# KS test
if KS:
self.KS = KS(df, confidence=confidence, N=len(temp),
self.KS = kolmogorov_smirnov(df, confidence=confidence, N=len(temp),
verbose=self.verbose)

# Plotting the expected frequncies (line) against the found ones(bars)
Expand Down Expand Up @@ -806,11 +807,11 @@ def last_two_digits(self, confidence=None, high_Z='pos',

# Chi-square statistic
if chi_square:
self.chi_square = chi_square(df, ddf=99, confidence=confidence,
self.chi_square = chi_sq(df, ddf=99, confidence=confidence,
verbose=self.verbose)
# KS test
if KS:
self.KS = KS(df, confidence=confidence, N=len(temp),
self.KS = kolmogorov_smirnov(df, confidence=confidence, N=len(temp),
verbose=self.verbose)

# Plotting expected frequencies (line) versus found ones (bars)
Expand Down
10 changes: 5 additions & 5 deletions benford/stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import sqrt
# from .constants import digs_dict, confs, crit_chi2, KS_crit, mad_dict
from .constants import crit_chi2, KS_crit


def Z_score(frame, N):
Expand All @@ -17,7 +17,7 @@ def Z_score(frame, N):
(frame.Expected * (1. - frame.Expected)) / N)


def chi_square(frame, ddf, confidence, verbose=True):
def chi_sq(frame, ddf, confidence, verbose=True):
"""Comnputes the chi-square statistic of the found distributions and compares
it with the critical chi-square of such a sample, according to the
confidence level chosen and the degrees of freedom - len(sample) -1.
Expand Down Expand Up @@ -48,7 +48,7 @@ def chi_square(frame, ddf, confidence, verbose=True):
return (found_chi, crit_chi)


def chi_square_2(frame):
def chi_sq_2(frame):
"""Computes the chi-square statistic of the found distributions
Args:
Expand All @@ -62,7 +62,7 @@ def chi_square_2(frame):
return (dif_counts ** 2 / exp_counts).sum()


def KS(frame, confidence, N, verbose=True):
def kolmogorov_smirnov(frame, confidence, N, verbose=True):
"""Computes the Kolmogorov-Smirnov test of the found distributions
and compares it with the critical chi-square of such a sample,
according to the confidence level chosen.
Expand Down Expand Up @@ -96,7 +96,7 @@ def KS(frame, confidence, N, verbose=True):
return (suprem, crit_KS)


def KS_2(frame):
def kolmogorov_smirnov_2(frame):
"""Computes the Kolmogorov-Smirnov test of the found distributions
Args:
Expand Down

0 comments on commit 5ab5cf5

Please sign in to comment.