1
$\begingroup$

I have the following data hscore:

  Type  0   1   2   3
CHP134  NA  NA  NA  11.3481
CHP212  3.094671    NA  NA  NA
COGN415 NA  NA  NA  27.96847
COGN440 NA  NA  NA  9.889557
COGN453 NA  NA  NA  26.61886
COGN471 6.849386    NA  NA  NA
COGN496 NA  NA  NA  24.62897
COGN534 NA  NA  5.700753    NA
COGN561 NA  NA  NA  15.41605
COGN573 NA  NA  NA  12.24616
FELIX   NA  NA  NA  17.90017
IMR32   NA  NA  NA  8.186577
IMR5    NA  NA  2.733886    NA
KELLY   NA  NA  11.10087    NA
LAN5    NA  NA  NA  20.2676
LAN6    NA  NA  NA  11.42142
NB1 NA  NA  NA  21.23469
NB16    NA  NA  NA  11.84981
NB1643  NA  NA  41.5252 NA
NB1691  NA  NA  NA  19.0909
NB69    NA  NA  NA  19.45173
NBEBC1  NA  NA  NA  5.99003
NBLS    NA  NA  11.94275    NA
NBSD    NA  NA  NA  16.12929
NGP NA  NA  10.81298    NA
NLF NA  NA  7.10228 NA
NMB NA  NA  NA  5.914751
SHSY5Y  NA  NA  NA  4.030656
SKNAS   0.4817894   NA  NA  NA
SKNBE2  NA  NA  16.9283 NA
SKNBE2C NA  NA  NA  27.00673
SKNDZ   NA  NA  NA  10.16279
SKNFI   NA  NA  NA  20.28035
SKNSH   NA  NA  NA  20.80995
SMSKAN  NA  NA  NA  13.97183
SMSSAN  NA  NA  NA  33.04528

The columns 0, 1, 2 and 3 represent an H-score. Each Type has a value associated with only one H-score. So the NAs represent missing values. This is my code to melt the data:

colnames(hscore) <- c('Type','zero','one','two','three')
tmp <- melt(hscore, id.vars = 'Type')
tmp[is.na(tmp)] <- 0 # replace all NAs to 0
tmp$val[tmp$variable=='zero'] <- 0
tmp$val[tmp$variable=='one'] <- 1
tmp$val[tmp$variable=='two'] <- 2
tmp$val[tmp$variable=='three'] <- 3

head(tmp)

    Type variable    value val
  CHP134     zero 0.000000   0
  CHP212     zero 3.094671   0
 COGN415     zero 0.000000   0
 COGN440     zero 0.000000   0
 COGN453     zero 0.000000   0
 COGN471     zero 6.849386   0

I have created a boxplot like this:

ggplot(data = tmp, aes(x=variable,y=value)) + geom_boxplot()

enter image description here

I have replaced all NAs (missing values) to 0. I want to show the differences between the boxes using a P-value and was thinking a pairwise Wilcox test like this:

pairwise.wilcox.test(tmp$value, tmp$val)

    Pairwise comparisons using Wilcoxon rank sum test 

data:  tmp$value and tmp$val 

  0       1       2     
1 0.1528  -       -     
2 0.1528  0.0092  -     
3 1.8e-07 1.5e-08 0.0001

P value adjustment method: holm 

Warning messages:
1: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties
2: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties
3: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties
4: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties
5: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties
6: In wilcox.test.default(xi, xj, paired = paired, ...) :
  cannot compute exact p-value with ties

Is this the correct way to show the differences in terms of a Pvalue?

$\endgroup$
2
  • 2
    $\begingroup$ It is incorrect to treat missing values as zeros--unless that's what you intended "NA" to mean. So what does "NA" actually indicate? $\endgroup$
    – whuber
    Sep 26 '16 at 21:57
  • $\begingroup$ I have edited my question for more clarity - each Type has a value associated with only one H-score (0,1,2 or 3). NAs represent missing values. $\endgroup$ Sep 27 '16 at 13:14
1
$\begingroup$

Since NAs are missing values, substituting them with a number is just inventing data. Then, you should work with the data you have. If the table shows all your data, that means that you have no information about type 1, so you can't expect to draw conclusions about it.

Each observation has an H-score value just in one type. Then, your data is not paired and you should go for an independent samples test - in the question you used a pairwise test, and therefore you had to invent data; with and independent sample test you won't need to artificially make pairs.

Said this, you can apply different tools. A simple way could be:

  1. Performing a Kruskal–Wallis one-way analysis of variance. Since it's a non parametric test you don't need to worry about differences in variances or normality of your data. It will tell you if there are significant differences between types, with a p-value. Alternatively, you could perform a parametric one way ANOVA, but beware of assumptions.
  2. You can assess significance of difference between two groups using Mann–Whitney U test. It's the equivalent for unpaired samples of the Wilcoxon test for paired samples you tried in the question.

If you perform multiple pairwise tests (that is, comparison between two types), beware that you will need to reduce the significance to reject the null hypothesis, as explained in Wikipedia article on post hoc analysis.

$\endgroup$
2
  • $\begingroup$ I would like to do a Mann-Whitney U test based on your answer but how can I do it in R? should I test each group separately? For e.g if I wanted to test the significance between 0-3 how would I do that? $\endgroup$ Sep 27 '16 at 14:32
  • $\begingroup$ The order is wilcox.test. You can check stat.ethz.ch/R-manual/R-devel/library/stats/html/… . If I understand your dataset, it should be something like $wilcox.test(x=tmp\$zero,y=tmp\$three,alternative="two.sided")$ $\endgroup$
    – Pere
    Sep 27 '16 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.