Skip to content

Commit

Permalink
Weight.
Browse files Browse the repository at this point in the history
  • Loading branch information
josep.marin.llao committed Sep 8, 2017
1 parent feccac6 commit a645dac
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,45 +157,46 @@ def get_weights_above_hypothesis_score_for_a_three_by_two_table(
if m_pp + m_mm - (m_pm + m_mp) >= hypothesisScore:
weights[1] = weights[1] + weight_contrib

# The loop below does exactly the same thing as the one above; it covers the cases that are not done in the loop above. A lower bound for possible
# values of n++ is 0 To avoid n_pp become negative or double counting when n_pp = 0, we add the following if statement
if (n_pp > 0):
for (m_pp in range(n_pp - 1, 0)):

# Iterate over all values of m_mp
for (m_mp in 0: min(r_m, n_p)) {

# n+-
m_pm = r_p - m_pp
# n--
m_mm = r_m - m_mp
# n0+
m_zp = n_p - (m_pp + m_mp)
# n0-
m_zm = n_m - (m_pm + m_mm)
contingencyTableValues = c(m_pp, m_pm, m_mp, m_mm, m_zp, m_zm)

m_pz = prediction_list_stats[1] - r_p
m_mz = prediction_list_stats[2] - r_m
m_zz = prediction_list_stats[3] - r_z

# None of these values can be less than zero
if min(contingencyTableValues) >= 0:


threeByThreeContingencyTable = [m_pp, m_pm, m_pz, m_mp, m_mm, m_mz, m_zp, m_zm, m_zz]
logDValue = math.log(math.factorial(log_of_factorial_of_prediction_list_stats)) - math.log(math.factorial(threeByThreeContingencyTable))

# Only need to compute the score if the D-value is non-neglible
if logDValue > logepsDMax:

# Rather than just calculate the DValue by taking the exponential of logDvalue, we first subtract a constant. This means when we take the
# exponential we get the DValue divided by a different constant, but this cancels out when we take ratios later when computing the p-value
weight_contrib = math.exp(logDValue - logDMax)
weights[2] = weights[2] + weight_contrib

if (m_pp + m_mm - (m_pm + m_mp) >= hypothesisScore):

weights[1] =hts weights[1] + weight_contrib

return weights
# The loop below does exactly the same thing as the one above; it covers the cases that are not done in the loop above. A lower bound for possible
# values of n++ is 0 To avoid n_pp become negative or double counting when n_pp = 0, we add the following if statement
if (n_pp > 0):
for m_pp in range(n_pp - 1, 0):

# Iterate over all values of m_mp
for m_mp in range(0, min(r_m, n_p)):

# n+-
m_pm = r_p - m_pp
# n--
m_mm = r_m - m_mp
# n0+
m_zp = n_p - (m_pp + m_mp)
# n0-
m_zm = n_m - (m_pm + m_mm)
contingencyTableValues = [m_pp, m_pm, m_mp, m_mm, m_zp, m_zm]

m_pz = prediction_list_stats[1] - r_p
m_mz = prediction_list_stats[2] - r_m
m_zz = prediction_list_stats[3] - r_z

# None of these values can be less than zero
if min(contingencyTableValues) < 0:
continue

threeByThreeContingencyTable = [m_pp, m_pm, m_pz, m_mp, m_mm, m_mz, m_zp, m_zm, m_zz]
logDValue = math.log(math.factorial(log_of_factorial_of_prediction_list_stats)) - math.log(
math.factorial(threeByThreeContingencyTable))

# Only need to compute the score if the D-value is non-neglible
if logDValue <= logepsDMax:
continue

# Rather than just calculate the DValue by taking the exponential of logDvalue, we first subtract a constant. This means when we take the
# exponential we get the DValue divided by a different constant, but this cancels out when we take ratios later when computing the p-value
weight_contrib = math.exp(logDValue - logDMax)
weights[2] = weights[2] + weight_contrib

if (m_pp + m_mm - (m_pm + m_mp) >= hypothesisScore):
weights[1] = weights[1] + weight_contrib

return weights

0 comments on commit a645dac

Please sign in to comment.