Paul
Paul

Reputation: 1117

Mann-Whitney U test with p-value

I would like to do a Mann-Whitney U test comparing columns 2,3,4 against columns 5, 6 and 7 and get a p-value for each row to assess the significance.

  type  Sp1 Sp2 Sp3 Sp4 Sp5 Sp6    
  GH1   4   4   4   2   2   0
  GH2   7   7   7   4   8   4
  GH3   13  17  16  10  16  10
  GH5   9   10  10  11  10  6
  GH6   0   0   0   0   0   0
  GH7   1   1   1   1   1   0
  GH9   0   0   1   0   1   0
  GH10  3   1   1   0   2   0
  GH11  1   1   0   2   1   1
  GH12  3   1   2   3   1   2
  GH13  11  13  12  12  13  12
  GH15  2   1   2   2   1   3
  GH16  17  16  16  14  11  13
  GH17  7   7   7   8   6   7
  GH18  7   9   9   9   9   5
  GH20  2   2   2   2   1   2
  GH22  0   0   0   0   0   0
  GH23  2   1   2   1   0   3
  GH24  0   0   0   1   0   0
  GH25  1   1   1   1   0   0
  GH26  0   0   0   0   0   0

I did see some tutorials for comparing two sets of values

 wilcox.test(a,b, correct=FALSE)

but I was not sure how to do it for two groups and get a p value for each row so that I will know if any of the types is significant across the two groups. In the end it will be something like

  type  Sp1 Sp2 Sp3 Sp4 Sp5 Sp6 p-value
  GH1   4   4   4   2   2   0   0.4
  GH2   7   7   7   4   8   4   0.2
  GH3   13  17  16  10  16  10  0.01 
  GH5   9   10  10  11  10  6   0.6

Upvotes: 0

Views: 1006

Answers (1)

thc
thc

Reputation: 9705

df$p_values <- apply(df, 1, function(x) {
    wilcox.test(as.numeric(x[2:4]), as.numeric(x[5:7]))$p.value
})

   type Sp1 Sp2 Sp3 Sp4 Sp5 Sp6   p_values
1   GH1   4   4   4   2   2   0 0.05934644
2   GH2   7   7   7   4   8   4 0.63735189
3   GH3  13  17  16  10  16  10 0.26115456
4   GH5   9  10  10  11  10   6 1.00000000
5   GH6   0   0   0   0   0   0        NaN
6   GH7   1   1   1   1   1   0 0.50498508
7   GH9   0   0   1   0   1   0 1.00000000
8  GH10   3   1   1   0   2   0 0.36868827
9  GH11   1   1   0   2   1   1 0.30169958
10 GH12   3   1   2   3   1   2 1.00000000
11 GH13  11  13  12  12  13  12 0.81366372
12 GH15   2   1   2   2   1   3 0.81366372
13 GH16  17  16  16  14  11  13 0.07652250
14 GH17   7   7   7   8   6   7 1.00000000
15 GH18   7   9   9   9   9   5 1.00000000
16 GH20   2   2   2   2   1   2 0.50498508
17 GH22   0   0   0   0   0   0        NaN
18 GH23   2   1   2   1   0   3 0.82218677
19 GH24   0   0   0   1   0   0 0.50498508
20 GH25   1   1   1   1   0   0 0.18763233
21 GH26   0   0   0   0   0   0        NaN

Upvotes: 2

Related Questions