I am a beginner in R and do not understand why pairwise_t_test()
from the rstatix
package does not show the t-value and cohen's d.
pairwise_t_test(data = filtered_normdata, BZO_RWgesamt ~ Alter, p.adjust.method = "none")
# A tibble: 36 × 9
.y. group1 group2 n1 n2 p p.signif p.adj p.adj.signif
* <chr> <chr> <chr> <int> <int> <dbl> <chr> <dbl> <chr>
1 BZO_RWge… 11 12 95 90 4.26e- 2 * 4.26e- 2 *
2 BZO_RWge… 11 13 95 90 6.17e- 5 **** 6.17e- 5 ****
3 BZO_RWge… 12 13 90 90 4.85e- 2 * 4.85e- 2 *
4 BZO_RWge… 11 14 95 74 4.85e- 9 **** 4.85e- 9 ****
5 BZO_RWge… 12 14 90 74 8.21e- 5 **** 8.21e- 5 ****
6 BZO_RWge… 13 14 90 74 3.72e- 2 * 3.72e- 2 *
7 BZO_RWge… 11 15 95 68 8.39e-18 **** 8.39e-18 ****
8 BZO_RWge… 12 15 90 68 1.22e-11 **** 1.22e-11 ****
9 BZO_RWge… 13 15 90 68 5 e- 7 **** 5 e- 7 ****
10 BZO_RWge… 14 15 74 68 3.73e- 3 ** 3.73e- 3 **
# ℹ 26 more rows
# ℹ Use `print(n = ...)` to see more rows
I already tried to get the statistic and estimate like this:
BZO_H2_w <- pairwise_t_test(data = filtered_normdata, BZO_RWgesamt ~ Alter, p.adjust.method = "none")
BZO_H2_w$estimate
and BZO_H2_w$statistic
but it didn't work. I would be really thankful if someone can help me :)
If it's the function from rstatix
that you are asking about then it only seems to return the full detail of the tests if you request not to use a pooled standard deviation for the t-tests (pool.sd=FALSE
).
If you look at the code, pairwise_t_test
calls the R function stats::pairwise.t.test
when you use a pooled SD, but uses a repeated application of stats::t.test
when pool.sd=FALSE
. It then uses broom::tidy
to collate the statistics into a table.
So I don't think there's a good statistical reason for the difference in reporting, it just relies on different base functions, and while the R function t.test
does return the t-statistic etc, pairwise.t.test
only returns a matrix of p-values.
You can get the detail of the pairwise t-tests with pooled SD if you use lm
to get a linear model (ANOVA) then emmeans
to get the pairwise contrasts. Note the p-values from emmeans
are the same as from pairwise.t.test
with the pooled SD, but it returns the estimate and statistic as well.
So, with some toy data:
> dat <- data.frame(x=rep(1:10,10), y=rnorm(100))
>
> rstatix::pairwise_t_test(dat, y~x, detailed=TRUE)
# A tibble: 45 × 10
.y. group1 group2 n1 n2 p method p.adj p.signif p.adj.signif
* <chr> <chr> <chr> <int> <int> <dbl> <chr> <dbl> <chr> <chr>
1 y 1 2 10 10 0.536 T-test 1 ns ns
2 y 1 3 10 10 0.453 T-test 1 ns ns
3 y 2 3 10 10 0.896 T-test 1 ns ns
4 y 1 4 10 10 0.427 T-test 1 ns ns
5 y 2 4 10 10 0.86 T-test 1 ns ns
6 y 3 4 10 10 0.964 T-test 1 ns ns
7 y 1 5 10 10 0.781 T-test 1 ns ns
8 y 2 5 10 10 0.733 T-test 1 ns ns
9 y 3 5 10 10 0.636 T-test 1 ns ns
10 y 4 5 10 10 0.605 T-test 1 ns ns
# ℹ 35 more rows
# ℹ Use `print(n = ...)` to see more rows
> rstatix::pairwise_t_test(dat, y~x, pool.sd=FALSE, detailed = TRUE)
# A tibble: 45 × 17
estimate estimate1 estimate2 .y. group1 group2 n1 n2 statistic p df conf.low conf.high method alternative p.adj p.adj.signif
* <dbl> <dbl> <dbl> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <chr>
1 -0.276 -0.318 -0.0417 y 1 2 10 10 -0.725 0.479 15.6 -1.08 0.533 T-test two.sided 1 ns
2 -0.334 -0.318 0.0166 y 1 3 10 10 -0.760 0.457 18.0 -1.26 0.590 T-test two.sided 1 ns
3 -0.354 -0.318 0.0367 y 1 4 10 10 -0.782 0.445 18.0 -1.31 0.598 T-test two.sided 1 ns
4 -0.124 -0.318 -0.194 y 1 5 10 10 -0.306 0.763 17.0 -0.977 0.729 T-test two.sided 1 ns
5 -0.209 -0.318 -0.109 y 1 6 10 10 -0.458 0.653 18.0 -1.17 0.749 T-test two.sided 1 ns
6 -0.0428 -0.318 -0.275 y 1 7 10 10 -0.104 0.918 17.3 -0.909 0.823 T-test two.sided 1 ns
7 0.0437 -0.318 -0.361 y 1 8 10 10 0.0933 0.927 17.9 -0.940 1.03 T-test two.sided 1 ns
8 -0.150 -0.318 -0.167 y 1 9 10 10 -0.320 0.752 17.9 -1.14 0.835 T-test two.sided 1 ns
9 -0.321 -0.318 0.00292 y 1 10 10 10 -0.616 0.546 16.9 -1.42 0.778 T-test two.sided 1 ns
10 -0.0583 -0.0417 0.0166 y 2 3 10 10 -0.158 0.876 16.0 -0.840 0.724 T-test two.sided 1 ns
# ℹ 35 more rows
# ℹ Use `print(n = ...)` to see more rows
> mod1 <- lm(data=dat , y~factor(x))
> emmeans::emmeans(mod1, pairwise ~ x, adjust="none", infer=c(TRUE, TRUE))$contrast
contrast estimate SE df lower.CL upper.CL t.ratio p.value
x1 - x2 -0.2759 0.444 90 -1.158 0.606 -0.622 0.5357
x1 - x3 -0.3343 0.444 90 -1.216 0.547 -0.753 0.4533
x1 - x4 -0.3543 0.444 90 -1.236 0.527 -0.798 0.4268
x1 - x5 -0.1238 0.444 90 -1.006 0.758 -0.279 0.7809
x1 - x6 -0.2086 0.444 90 -1.090 0.673 -0.470 0.6395
x1 - x7 -0.0428 0.444 90 -0.925 0.839 -0.096 0.9234
x1 - x8 0.0437 0.444 90 -0.838 0.925 0.098 0.9218
x1 - x9 -0.1503 0.444 90 -1.032 0.731 -0.339 0.7357
x1 - x10 -0.3206 0.444 90 -1.202 0.561 -0.722 0.4720
x2 - x3 -0.0583 0.444 90 -0.940 0.823 -0.131 0.8957
x2 - x4 -0.0784 0.444 90 -0.960 0.803 -0.177 0.8602
x2 - x5 0.1521 0.444 90 -0.730 1.034 0.343 0.7326
x2 - x6 0.0673 0.444 90 -0.814 0.949 0.152 0.8798
x2 - x7 0.2331 0.444 90 -0.649 1.115 0.525 0.6007
x2 - x8 0.3196 0.444 90 -0.562 1.201 0.720 0.4733
x2 - x9 0.1257 0.444 90 -0.756 1.007 0.283 0.7777
x2 - x10 -0.0446 0.444 90 -0.926 0.837 -0.101 0.9201
x3 - x4 -0.0201 0.444 90 -0.902 0.862 -0.045 0.9640
x3 - x5 0.2105 0.444 90 -0.671 1.092 0.474 0.6365
x3 - x6 0.1257 0.444 90 -0.756 1.007 0.283 0.7777
x3 - x7 0.2915 0.444 90 -0.590 1.173 0.657 0.5130
x3 - x8 0.3779 0.444 90 -0.504 1.260 0.852 0.3967
x3 - x9 0.1840 0.444 90 -0.698 1.066 0.415 0.6794
x3 - x10 0.0137 0.444 90 -0.868 0.895 0.031 0.9754
x4 - x5 0.2305 0.444 90 -0.651 1.112 0.519 0.6047
x4 - x6 0.1457 0.444 90 -0.736 1.027 0.328 0.7434
x4 - x7 0.3116 0.444 90 -0.570 1.193 0.702 0.4845
x4 - x8 0.3980 0.444 90 -0.484 1.280 0.897 0.3722
x4 - x9 0.2041 0.444 90 -0.678 1.086 0.460 0.6468
x4 - x10 0.0338 0.444 90 -0.848 0.915 0.076 0.9395
x5 - x6 -0.0848 0.444 90 -0.967 0.797 -0.191 0.8489
x5 - x7 0.0810 0.444 90 -0.801 0.963 0.183 0.8556
x5 - x8 0.1675 0.444 90 -0.714 1.049 0.377 0.7068
x5 - x9 -0.0265 0.444 90 -0.908 0.855 -0.060 0.9526
x5 - x10 -0.1968 0.444 90 -1.078 0.685 -0.443 0.6586
x6 - x7 0.1658 0.444 90 -0.716 1.048 0.374 0.7096
x6 - x8 0.2523 0.444 90 -0.629 1.134 0.568 0.5712
x6 - x9 0.0583 0.444 90 -0.823 0.940 0.131 0.8957
x6 - x10 -0.1120 0.444 90 -0.994 0.770 -0.252 0.8014
x7 - x8 0.0865 0.444 90 -0.795 0.968 0.195 0.8460
x7 - x9 -0.1075 0.444 90 -0.989 0.774 -0.242 0.8092
x7 - x10 -0.2778 0.444 90 -1.160 0.604 -0.626 0.5330
x8 - x9 -0.1939 0.444 90 -1.076 0.688 -0.437 0.6632
x8 - x10 -0.3642 0.444 90 -1.246 0.517 -0.821 0.4140
x9 - x10 -0.1703 0.444 90 -1.052 0.711 -0.384 0.7021