3

I want to calculate p-value for each key of a dictionary and create a table for the (keys | p-value).

Example dictionary:

mydict = {
'a': [100, 5, 4, 3],
'b': [66, 0, 75, 12],
'c': [56, 11, 80, 0]}

How can I insert the 4 value of each key in order into the Scipy function for that?

p-value calculation example for a by using Scipy function:

import scipy.stats as stats
oddsratio, pvalue = stats.fisher_exact([[100, 5], [4, 3]])
pvalue

All help will be appreciated

Thank you

martineau
  • 119,623
  • 25
  • 170
  • 301
Alakeedi
  • 31
  • 2

1 Answers1

3

You can do something like that:

mydict = {
    'a': [100, 5, 4, 3],
    'b': [66, 0, 75, 12],
    'c': [56, 11, 80, 0],
}

results = {k: stats.fisher_exact([v[:2], v[2:]]) for k, v in mydict.items()}
pvalues = {k: pvalue for k, (oddsratio, pvalue) in results.items()}
enzo
  • 9,861
  • 3
  • 15
  • 38