R语言 如何计算一系列事件p值

hyrbngr7  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(207)

我的数据看起来像这样

df<- structure(list(Accession = c("AAAAA", "AAAAA", "MYDDD", "MYDDD", 
"STDTTT", "STDTTT"), grp = c("Rep1", "Rep2", "Rep1", "Rep2", 
"Rep1", "Rep2"), First = c(24.8432602, 25.16806123, 33.36984063, 
33.59779257, 30.93297676, 31.71292828), Condition1 = c(28.74214021, 
28.68311263, 36.89735285, 37.12617154, 35.67871257, 35.89283737
), Condition2 = c(28.60045356, 27.5609252, 36.85154916, 36.25666317, 
35.3600596, 34.87004551)), class = "data.frame", row.names = c(NA, 
-6L))

每个事件有两个重复样本,称为Rep1和Rep2,我知道如何计算中位数和SD,但不知道如何将p值添加到其中
有何评论?
我就是干这个的

mydf<- df %>% dplyr::mutate(across(where(is.numeric), 
                     list(median= ~ median(.x), SD = ~ sd(.x)))) %>% 
  pivot_wider(names_from = grp, values_from = First:Condition2)
np8igboo

np8igboo1#

这就是你要找的吗?

library(dplyr) # must be version >= 1.1
 
df |> 
  summarise(across(where(is.numeric), 
                   list(median = median, SD = sd)),
            pvalue_First_Condition1 = t.test(First, Condition1)$p.value,
            pvalue_First_Condition2 = t.test(First, Condition2)$p.value,
            pvalue_Condition1_Condition2 = t.test(Condition1, Condition2)$p.value,
            .by = grp)
#>    grp First_median First_SD Condition1_median Condition1_SD Condition2_median
#> 1 Rep1     30.93298 4.391764          35.67871      4.399027          35.36006
#> 2 Rep2     31.71293 4.424334          35.89284      4.560455          34.87005
#>   Condition2_SD pvalue_First_Condition1 pvalue_First_Condition2
#> 1      4.396919               0.3214366               0.3394101
#> 2      4.671934               0.3655297               0.5023632
#>   pvalue_Condition1_Condition2
#> 1                    0.9647786
#> 2                    0.8029806

如果你给予我更多的指示,我会尽力进一步帮助你。

相关问题