Paired samples Wilcoxon test over each column.

huangapple go评论71阅读模式
英文:

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(&quot;Group1&quot;, 
&quot;Group1&quot;, &quot;Group1&quot;, &quot;Group1&quot;, &quot;Group1&quot;, &quot;Group2&quot;, &quot;Group2&quot;, &quot;Group2&quot;, 
&quot;Group2&quot;, &quot;Group2&quot;, &quot;Group1&quot;, &quot;Group1&quot;, &quot;Group1&quot;, &quot;Group1&quot;, &quot;Group1&quot;, 
&quot;Group2&quot;, &quot;Group2&quot;, &quot;Group2&quot;, &quot;Group2&quot;, &quot;Group2&quot;), Time = c(&quot;T0&quot;, 
&quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T0&quot;, &quot;T2&quot;, &quot;T2&quot;, 
&quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;, &quot;T2&quot;), 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 = &quot;data.frame&quot;, 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 &lt;- c(&quot;Alistipes_putredinis&quot;, &quot;Bidobacterium_l&quot;, &quot;Dialister_invisus&quot;, &quot;Clostridia_bacterium&quot;, &quot;Ruminococcus_sp_NSJ_71&quot;)
mydat |&gt; 
group_by(Group) |&gt; 
nest() |&gt; 
mutate(test = map(data, function(dat) map(myvars, function(x) pairwise.wilcox.test(dat[[x]], dat[[&quot;Time&quot;]], paired = TRUE) |&gt; 
tidy() |&gt; 
mutate(var = x)) |&gt; 
list_rbind())) |&gt; 
unnest(test) |&gt;
ungroup()
# A tibble: 10 &#215; 6
Group  data              group1 group2 p.value var                   
&lt;chr&gt;  &lt;list&gt;            &lt;chr&gt;  &lt;chr&gt;    &lt;dbl&gt; &lt;chr&gt;                 
1 Group1 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.371 Alistipes_putredinis  
2 Group1 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.438 Bidobacterium_l       
3 Group1 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.625 Dialister_invisus     
4 Group1 &lt;tibble [10 &#215; 7]&gt; T2     T0       1     Clostridia_bacterium  
5 Group1 &lt;tibble [10 &#215; 7]&gt; T2     T0       1     Ruminococcus_sp_NSJ_71
6 Group2 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.584 Alistipes_putredinis  
7 Group2 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.125 Bidobacterium_l       
8 Group2 &lt;tibble [10 &#215; 7]&gt; T2     T0       1     Dialister_invisus     
9 Group2 &lt;tibble [10 &#215; 7]&gt; T2     T0       1     Clostridia_bacterium  
10 Group2 &lt;tibble [10 &#215; 7]&gt; T2     T0       0.438 Ruminococcus_sp_NSJ_71

huangapple
  • 本文由 发表于 2023年6月26日 17:43:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555469.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定