Winnie09 / Lamian

48 stars 11 forks source link

Each p-value from branchPropTest() is 1 #4

Closed jmitchell81 closed 3 years ago

jmitchell81 commented 3 years ago

Hello,

I was trying to the branchPropTest() function with the sample.cellcomp.mean from the result of evaluate_uncertainty(). When running the proportion test, I noticed all p-values come back as 1

> branchPropTest(data = data, design = design)
 TEM1->TEM2  TEM1->TEM3   TEM0->TCM naive->TEM0  TEM0->TEM1 
          1           1           1           1           1 

Looking at the source code for this function, I think the issue is in line 18 of Lamian/R/branchPropTest.R

apply(data, 1, function(i)
    t.test(i[id1], i[-c(id2)])$p.value)

The variable selection for y in the t-test ( i[-c(id2)] ) subsets the row to the inverse of samples with id2, thereby leading to a t-test of id1 against itself. By removing -c( ), I was able to get the correct p-values.

> branchPropTest <- function(data, design) {
+   id1 = which(design[, 2] == 0)
+   id2 = which(design[, 2] == 1)
+   apply(data, 1, function(i)
+     t.test(i[id1], i[id2])$p.value)
+ }
> branchPropTest(data = data, design = design)
  TEM1->TEM2   TEM1->TEM3    TEM0->TCM  naive->TEM0   TEM0->TEM1 
0.3173038005 0.0299670388 0.4542933683 0.0001164067 0.9788035124
Winnie09 commented 3 years ago

Hello Jacob,

Very good catch! Thank you! I updated the codes of branchPropTest() accordingly.

Best, Wenpin