library(genefilter)
set.seed(111)
exampleDF <- data.frame(s1 = rnorm(10), s2 = rnorm(10), s3 = rnorm(10), s4 = rnorm(10), s5 = rnorm(10))
group = factor(rep(c("A","B"),c(3,2)))
res = rowttests(as.matrix(exampleDF),factor(group))
res$adjP = p.adjust(res$p.value,"BH")
head(res)
statistic dm p.value
1 -0.04874235 -0.06430958 0.96418815
2 2.01047763 adjP
1.30645511 0.13791972
3 3.04099375 02.86318365 2855413 0.8687078505582346 0.451523563261168
4 2 02.6199888384786452 0.309025049011630 0.57917127
5 06522336 10.21511532 3261168
3 1.00878255 0.31123065
6 41773686 0.07756532 5554058 0.0882825070423693 0.943057438802962
7 4 -0.9805698909067738 -0.661758141196167 0.39911481
8 93346409 0.90571157 9804451
5 0.98698010 0.43185491
9 91684108 31.16533692 0797461 10.1492354942683640 0.050662287113940
10 6 -0.9137026891749882 -0.8714534 0.8299524842654148 0.428246197113940
The default in rowttest
assumes equal variance for groups. You have to see whether this is true. If you need exact p-valuesthis is not the case, thenyou can go back to using t.test()
Then it will be:
library(broom)
res = apply(exampleDF,1,function(i)tidy(t.test(i ~ group)))
res = do.call(rbind,res)
res$adjP = p.adjust(res$p.value,"BH")
res[,c("statistic","p.value","adjP")]
# A tibble: 10 x 3
statistic p.value adjP
<dbl> <dbl> <dbl>
1 2.33 0.248 0.826
2 3.52 0.0515 0.515
3 0.364 0.762 0.952
4 -0.0897 0.936 0.976
5 0.706 0.602 0.952
6 -1.00 0.393 0.952
7 -2.15 0.135 0.675
8 -0.0341 0.976 0.976
9 -0.983 0.488 0.952
10 -0.471 0.710 0.952