p -value adjustment Mann-Whitney U test in python

末鹿安然 提交于 2019-12-31 05:44:07

问题


I have a two-dimensional list file(name - 'hcl_file'). A shortened version of the file for clarity. Vertical-observations, horizontal-experiment number:

ID type First Second Third

gerg    I   0.02695 0    0.00135      0.31312

11P     I   0.02695 0    0.00135      0.31312

112HP   II  0.02695 0    0.00135      0.31312

1454HP  II  0.02695 0    0.00135      0.31312

11544H  III 0.02695 0    0.00135      0.31312

657BF   III 0.02695 0    0.00135      0.31312

785DS   III 0.02695 0    0.00135      0.31312

I'm new to programming. Could you please tell me how I can calculate the significance of the differences between the type I,II,III, and then make an BH(Bennamini and Hochbberg) adjustment ? To avoid misunderstandings, let me clarify that we are conducting an experiment for different groups(I,II,III) and find the p-value for them, but then we repeat this for other data that requires adjustment of p-value for multiple comparisons. I have difficulty doing this in a cycle, please advise the direction of further movement. My script:

for line in hcl_file:

     substrings = (len(line))

while j < substrings:

k1 = []         # list of values in I-st group 

k2 = []         II

k3 = []         III

for line in hcl_file:

        if line[1] == 'I':

                v1 = float(line[j])

                k1.append(v1)

        elif line[1] == 'II':

                v2 = float(line[j])

                k2.append(v2)

        elif line[1] == 'III':

                v3 = float(line[j])

                k3.append(v3)



import pandas

from scipy.stats import mannwhitneyu

print(mannwhitneyu(k1, k2))

j += 1

回答1:


If you're gonna use pandas, use pandas to load the data too.

import pandas
from scipy.stats import mannwhitneyu
hcl_data = pandas.read_table(hcl_file, sep="\t")

print(mannwhitneyu(hcl_data.loc[hcl_data['type'] == "II"], hcl_data.loc[hcl_data['type'] == "III"]))

I'm not entirely sure which columns you're trying to test so I can't be more specific. You might need to flatten the data before you pass it to scipy.



来源:https://stackoverflow.com/questions/52433424/p-value-adjustment-mann-whitney-u-test-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!