英文:
Paired samples wilcoxon test over each column
问题
Sure, here's the translated code snippet for performing a pairwise sample Wilcoxon test in R:
# 在 R 中执行按 "Time" 变量分割的数据框的每列的成对样本 Wilcoxon 检验(按 "Group" 分割,即 Group1 和 Group2)。
# 定义数据框
data <- structure(list(ID = c(1L, 2L, 3L, 4L, 5L, 10L, 11L, 12L, 13L,
14L, 1L, 2L, 3L, 4L, 5L, 10L, 11L, 12L, 13L, 14L), Group = c("Group1",
"Group1", "Group1", "Group1", "Group1", "Group2", "Group2", "Group2",
"Group2", "Group2", "Group1", "Group1", "Group1", "Group1", "Group1",
"Group2", "Group2", "Group2", "Group2", "Group2"), Time = c("T0",
"T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T2", "T2",
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2"), Alistipes_putredinis = c(20.54997,
0, 0, 0, 0.00226, 0, 12.83106, 0.38555, 16.45834, 0, 0.6405,
0, 0, 0, 0, 16.32105, 0, 0, 0, 0), Bidobacterium_l = c(14.43141,
0.25318, 0.83121, 0.54282, 8.50687, 0.10432, 0.0051, 0.00139,
0.11766, 0.57905, 0.74302, 0.79018, 0.20329, 5.34884, 1.75612,
0.25502, 0, 0.60675, 0.59414, 0.85824), Dialister_invisus = c(12.45032,
7.88459, 0.99032, 1.84241, 0.93828, 1.96771, 5.16734, 3.82884,
1.55069, 0.97391, 1.43845, 9.77174, 2.59287, 4.70876, 2.30655,
3.08246, 10.56866, 0.49946, 0.95196, 0.14022), Clostridia_bacterium = c(7.5127,
0, 0, 0, 0, 6.65269, 0, 0, 4.11219, 0, 5.34908, 0.00794, 0, 0,
0, 0, 0, 4.33676, 6.2422, 0), Ruminococcus_sp_NSJ_71 = c(6.57903,
1.45815, 0.28668, 1.66816, 1.66008, 1.85348, 1.80051, 0.91537,
3.12064, 3.00647, 2.91748, 1.97839, 0.0726, 3.7829, 1.59076,
1.05453, 0.03881, 3.84824, 0.01241, 2.88977)), class = "data.frame", row.names = c(NA,
-20L))
# 执行 Wilcoxon 检验(根据需要替换变量名)
result <- pairwise.wilcox.test(data$Alistipes_putredinis, data$Group, p.adjust.method = "bonferroni")
Please replace the variable names as needed for your specific analysis. If you have any further questions or need assistance, feel free to ask.
英文:
i would like to perform in R a pairwise sample wilcoxon test (by variable "Time") over each column of a dataframe splitted by "Group" (i.e. Group1 and Group2).
structure(list(ID = c(1L, 2L, 3L, 4L, 5L, 10L, 11L, 12L, 13L,
14L, 1L, 2L, 3L, 4L, 5L, 10L, 11L, 12L, 13L, 14L), Group = c("Group1",
"Group1", "Group1", "Group1", "Group1", "Group2", "Group2", "Group2",
"Group2", "Group2", "Group1", "Group1", "Group1", "Group1", "Group1",
"Group2", "Group2", "Group2", "Group2", "Group2"), Time = c("T0",
"T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T0", "T2", "T2",
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2"), Alistipes_putredinis = c(20.54997,
0, 0, 0, 0.00226, 0, 12.83106, 0.38555, 16.45834, 0, 0.6405,
0, 0, 0, 0, 16.32105, 0, 0, 0, 0), Bidobacterium_l = c(14.43141,
0.25318, 0.83121, 0.54282, 8.50687, 0.10432, 0.0051, 0.00139,
0.11766, 0.57905, 0.74302, 0.79018, 0.20329, 5.34884, 1.75612,
0.25502, 0, 0.60675, 0.59414, 0.85824), Dialister_invisus = c(12.45032,
7.88459, 0.99032, 1.84241, 0.93828, 1.96771, 5.16734, 3.82884,
1.55069, 0.97391, 1.43845, 9.77174, 2.59287, 4.70876, 2.30655,
3.08246, 10.56866, 0.49946, 0.95196, 0.14022), Clostridia_bacterium = c(7.5127,
0, 0, 0, 0, 6.65269, 0, 0, 4.11219, 0, 5.34908, 0.00794, 0, 0,
0, 0, 0, 4.33676, 6.2422, 0), Ruminococcus_sp_NSJ_71 = c(6.57903,
1.45815, 0.28668, 1.66816, 1.66008, 1.85348, 1.80051, 0.91537,
3.12064, 3.00647, 2.91748, 1.97839, 0.0726, 3.7829, 1.59076,
1.05453, 0.03881, 3.84824, 0.01241, 2.88977)), class = "data.frame", row.names = c(NA,
-20L))
Does anyone can help me,please?
Thanks
答案1
得分: 1
这部分代码的翻译如下:
我不完全确定我是否理解你在测试应用方面正在寻找的内容,但也许类似这样?
library(dplyr)
library(tidyr)
library(purrr)
library(broom)
myvars <- c("Alistipes_putredinis", "Bidobacterium_l", "Dialister_invisus", "Clostridia_bacterium", "Ruminococcus_sp_NSJ_71")
mydat %>%
group_by(Group) %>%
nest() %>%
mutate(test = map(data, function(dat) map(myvars, function(x) pairwise.wilcox.test(dat[[x]], dat[["Time"]], paired = TRUE) %>%
tidy() %>%
mutate(var = x)) %>%
list_rbind())) %>%
unnest(test) %>%
ungroup()
# 一个 tibble: 10 × 6
Group data group1 group2 p.value var
<chr> <list> <chr> <chr> <dbl> <chr>
1 Group1 <tibble [10 × 7]> T2 T0 0.371 Alistipes_putredinis
2 Group1 <tibble [10 × 7]> T2 T0 0.438 Bidobacterium_l
3 Group1 <tibble [10 × 7]> T2 T0 0.625 Dialister_invisus
4 Group1 <tibble [10 × 7]> T2 T0 1 Clostridia_bacterium
5 Group1 <tibble [10 × 7]> T2 T0 1 Ruminococcus_sp_NSJ_71
6 Group2 <tibble [10 × 7]> T2 T0 0.584 Alistipes_putredinis
7 Group2 <tibble [10 × 7]> T2 T0 0.125 Bidobacterium_l
8 Group2 <tibble [10 × 7]> T2 T0 1 Dialister_invisus
9 Group2 <tibble [10 × 7]> T2 T0 1 Clostridia_bacterium
10 Group2 <tibble [10 × 7]> T2 T0 0.438 Ruminococcus_sp_NSJ_71
注意:代码部分没有进行翻译,只翻译了注释和字符串部分。
英文:
I'm not entirely certain I understood what you are looking for in terms of the application of the test, but maybe something like this?
library(dplyr)
library(tidyr)
library(purrr)
library(broom)
myvars <- c("Alistipes_putredinis", "Bidobacterium_l", "Dialister_invisus", "Clostridia_bacterium", "Ruminococcus_sp_NSJ_71")
mydat |>
group_by(Group) |>
nest() |>
mutate(test = map(data, function(dat) map(myvars, function(x) pairwise.wilcox.test(dat[[x]], dat[["Time"]], paired = TRUE) |>
tidy() |>
mutate(var = x)) |>
list_rbind())) |>
unnest(test) |>
ungroup()
# A tibble: 10 × 6
Group data group1 group2 p.value var
<chr> <list> <chr> <chr> <dbl> <chr>
1 Group1 <tibble [10 × 7]> T2 T0 0.371 Alistipes_putredinis
2 Group1 <tibble [10 × 7]> T2 T0 0.438 Bidobacterium_l
3 Group1 <tibble [10 × 7]> T2 T0 0.625 Dialister_invisus
4 Group1 <tibble [10 × 7]> T2 T0 1 Clostridia_bacterium
5 Group1 <tibble [10 × 7]> T2 T0 1 Ruminococcus_sp_NSJ_71
6 Group2 <tibble [10 × 7]> T2 T0 0.584 Alistipes_putredinis
7 Group2 <tibble [10 × 7]> T2 T0 0.125 Bidobacterium_l
8 Group2 <tibble [10 × 7]> T2 T0 1 Dialister_invisus
9 Group2 <tibble [10 × 7]> T2 T0 1 Clostridia_bacterium
10 Group2 <tibble [10 × 7]> T2 T0 0.438 Ruminococcus_sp_NSJ_71
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论