0

I am working with very small p-values (several hundred decimals) and I am trying to detect the smallest one in the list. It seems like Python detects many of them as zero so I get a zero division error when I log.

To avoid this, I have written this code:

smallest_val = min(np.array(p_value)[np.array(p_value) > 0])
for i in range(len(p_value)):
  if p_value[i] == 0: 
    p_value[i] = smallest_val

p_value_log = []
for i in p_value:
  b = log(i)
  p_value_log.append(b)

Of course, this does not solve my problem as several small p-values are then equal to smallest_val and I can't identify the smallest. Any idea on the best way to go about this?

CenCG
  • 21
  • 3

1 Answers1

0

Instead of replacing 0's with smallest_val, replace them with smallest_val/2 or something else between smallest_val and 0, so that you can still identify your replacements.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • The problem is that smallest_val is already at the limit of what Python will accept as non-zero so if i divide it by 2, python still thinks the value is zero – CenCG Oct 28 '16 at 13:16
  • How do you know that? Your code is finding the smallest non-0 value in the array, not (necessarily) the smallest non-0 possible. – Scott Hunter Oct 28 '16 at 14:34
  • Because when i use the same code for another data set that varies less widely from the set i'm comparing it to, I manage to plot all the p-values and the smallest one has already several hundred decimals – CenCG Oct 28 '16 at 15:30
  • So why would one more decimal (which dividing by 2 wouldn't necessarily produce) necessarily go past this limit? – Scott Hunter Oct 28 '16 at 15:41