我想对数据框中的相邻行(1-2,3-4,5-6)进行t检验。我想测试相邻行是否明显大于0.如何在整个数据框中执行此操作? 像这样的t检验:
t.test(x=rowname,y=NULL,alternative="one.sided", alternative = "greater")
例如:hsa-miR-99a-5p.dataTissue
和hsa-miR-99a-5p.dataSerum
都大于0吗?
HEP015 mm7 s26 TxHEP-014 TxHEP-015 TxHEP-018 vs29
hsa-miR-99a-5p.dataTissue 0.8234702 1.18956279 0.6145471 -1.1804234 -2.9679366 -1.2382820 -1.856565
hsa-miR-99a-5p.dataSerum -4.7975142 -1.79686065 -0.6652281 -3.0752460 -3.3742772 -3.8129578 -1.099334
hsa-miR-93-5p.dataTissue -0.2943401 -0.02306152 0.3097169 -2.0754544 0.3720528 2.1457004 2.003187
hsa-miR-93-5p.dataSerum 1.2905805 -2.07963898 -1.7277941 -1.9811846 -0.7549379 -0.9258338 -2.319956
hsa-miR-92b-3p.dataTissue -0.5874168 -1.55601781 0.8656526 -0.3436976 -2.8644071 1.2470288 4.652237
hsa-miR-92b-3p.dataSerum -1.9323028 -1.53377562 -0.9441492 -2.7669216 -2.5563865 -1.1790849 2.637090
答案 0 :(得分:1)
假设它位于名为data.frame
的{{1}}中,一种方法如下:
df
看来,你的library(dplyr)
library(broom)
row_results <- apply(df, 1, function(x) glance(t.test(x, alternative = "greater")))
row_results <- rbind_all(row_results)
row_results$name <- rownames(df)
# row_results
# Source: local data frame [6 x 7]
#
# estimate statistic p.value parameter conf.low conf.high name
# (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (chr)
# 1 -0.6593753 -1.1179897 0.8468370 6 -1.8054369 Inf hsa-miR-99a-5p.dataTissue
# 2 -2.6602026 -4.6508774 0.9982498 6 -3.7716602 Inf hsa-miR-99a-5p.dataSerum
# 3 0.3482573 0.6410169 0.2726011 6 -0.7074507 Inf hsa-miR-93-5p.dataTissue
# 4 -1.2141093 -2.5674955 0.9787610 6 -2.1329943 Inf hsa-miR-93-5p.dataSerum
# 5 0.2019113 0.2219719 0.4158491 6 -1.5656549 Inf hsa-miR-92b-3p.dataTissue
# 6 -1.1822187 -1.7248956 0.9323470 6 -2.5140465 Inf hsa-miR-92b-3p.dataSerum
实际上是两个变量,因此,我会将它们分解,如下所示:
rowname
这允许我们library(tidyr)
row_results <- separate(row_results, name, c("name", "type"), sep = "\\.")
新的group_by
变量并创建一个新的指标变量name
:
both_significant
您可能希望将逻辑更改为row_results %>%
group_by(name) %>%
mutate(both_significant = all(p.value > 0.8))
,但我想在结果中添加一些p.value < 0.05
示例:
TRUE