简体   繁体   English

使用 `dplyr` 运行所有成对比较并添加 Cohen 的 *d*

[英]Use `dplyr` to run all pairwise comparisons and add Cohen's *d*

I am using rstatix to perform multiple t-tests on a dataset which works very well, but I also need Cohen's d .我正在使用rstatix在运行良好的数据集上执行多个 t 检验,但我还需要 Cohen 的d rstatix also includes a function to calculate Cohen's d , but it requires the original dataset, not the table generated by the t_test function. rstatix还包括一个 function 来计算 Cohen 的d ,但它需要原始数据集,而不是t_test function 生成的表。

library(tidyverse)
library(rstatix)

iris %>%
    t_test(Petal.Width ~ Species, paired = FALSE, var.equal = FALSE)

Which gives me:这给了我:

# A tibble: 3 × 10
  .y.         group1     group2        n1    n2 statistic    df        p    p.adj p.adj.signif
* <chr>       <chr>      <chr>      <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
1 Petal.Width setosa     versicolor    50    50     -34.1  74.8 2.72e-47 5.44e-47 ****        
2 Petal.Width setosa     virginica     50    50     -42.8  63.1 2.44e-48 7.32e-48 ****        
3 Petal.Width versicolor virginica     50    50     -14.6  89.0 2.11e-25 2.11e-25 ****     

This output would be perfect if it had an additional column with Cohen's d for each t-test.如果这个 output 对于每个 t 检验都有一个带有 Cohen's d的附加列,那将是完美的。 How do I get Cohen's d ?我如何获得科恩的d

We may do a join我们可以加入

library(dplyr)
library(rstatix)
iris %>% 
  cohens_d(Petal.Width ~ Species, paired = TRUE) %>% 
  inner_join(iris %>%
    t_test(Petal.Width ~ Species, paired = FALSE, var.equal = FALSE)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM