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)
| 786 | #--- PEARSON'S LOG LIKELIHOOD RATIO APPROXIMATION -------------------------------------------------- |
| 787 | |
| 788 | def 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 | |
| 807 | llr = likelihood = pearson_log_likelihood_ratio |
| 808 |
no test coverage detected
searching dependent graphs…