MCPcopy Create free account
hub / github.com/clips/pattern / pearson_log_likelihood_ratio

Function pearson_log_likelihood_ratio

pattern/metrics.py:788–805  ·  view source on GitHub ↗

Returns (G, P) for the n x m observed and expected data (containing absolute frequencies). If expected is None, an equal distribution over all classes is assumed. If df is None, it is the number of classes-1 (i.e., len(observed[0]) - 1). P < 0.05: significant P < 0.0

(observed=[], expected=[], df=None, tail=UPPER)

Source from the content-addressed store, hash-verified

786#--- PEARSON'S LOG LIKELIHOOD RATIO APPROXIMATION --------------------------------------------------
787
788def pearson_log_likelihood_ratio(observed=[], expected=[], df=None, tail=UPPER):
789 """ Returns (G, P) for the n x m observed and expected data (containing absolute frequencies).
790 If expected is None, an equal distribution over all classes is assumed.
791 If df is None, it is the number of classes-1 (i.e., len(observed[0]) - 1).
792 P < 0.05: significant
793 P < 0.01: very significant
794 """
795 O = observed
796 E = expected or _expected(observed)
797 df = df or (len(O) > 0 and len(O[0])-1 or 0)
798 G = 0.0
799 for i in range(len(O)):
800 for j in range(len(O[i])):
801 if O[i][j] != 0 and E[i][j] != 0:
802 G += O[i][j] * log(O[i][j] / E[i][j])
803 G = G * 2
804 P = gammai(df * 0.5, G * 0.5, tail)
805 return (G, P)
806
807llr = likelihood = pearson_log_likelihood_ratio
808

Callers 1

significanceFunction · 0.85

Calls 3

_expectedFunction · 0.85
lenFunction · 0.85
gammaiFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…