在 R 中计算箱线图显着性水平的错误结果
Wrong results in calculating boxplot significance levels in R
我正在创建一个带有显着性水平条的基本箱线图(如此处所示:)
我使用的数据如下:
title1
title2
value
1
A
8.88
2
A
5.84
3
A
13.28
4
A
16.89
1
B
21.39
2
B
20.77
3
B
28.03
4
B
19.78
1
C
28.89
2
C
35.41
3
C
37.47
4
C
50.11
1
D
50.84
2
D
53.21
3
D
46.47
4
D
45.03
使用以下代码,创建箱线图效果很好。对于显着性条,我想使用配对 t 检验,例如 title2=A 与 title2=B,其中 title1=1 的两行是一对,依此类推。
在 R 中,我输入了以下命令,但它对 p 产生了不同的结果。例如,A 与 D 的 p 值应为 0.003,但 R 的结果为 2.8e-05。配对 t 检验的正确语法是什么?
library(ggplot2)
library(ggsignif)
ggplot(bxp, aes(y=value,x=title2)) +
xlab("Behandlung") +
scale_x_discrete(labels=c("Kontrolle","Stretch","Hyperoxie","Stretch & Hyperoxie")) +
ylab("Zelluläre Seneszenz (%)") + theme_classic() +
geom_boxplot(coef = Inf) +
geom_signif(comparisons=list(c("A","B"),c("A","C"),c("A","D")), test=t.test, map_signif_level=FALSE, step_increase=0.08)
谢谢!
ggsignif
正在计算未配对的 t-test,我认为您需要配对测试。幸运的是 geom_signif
有一个 test.args
参数,它允许您将 paired = TRUE
传递给 geom:
ggplot(bxp, aes(y=value,x=title2)) +
xlab("Behandlung") +
scale_x_discrete(labels=c("Kontrolle","Stretch","Hyperoxie","Stretch & Hyperoxie")) +
ylab("Zelluläre Seneszenz (%)") + theme_classic() +
geom_boxplot(coef = Inf) +
geom_signif(comparisons=list(c("A","B"),c("A","C"),c("A","D")), test=t.test, test.args = list(paired = T), map_signif_level=FALSE, step_increase=0.08)
数据:
bxp <- structure(list(title1 = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4), title2 = c("A", "A", "A", "A", "B", "B", "B", "B",
"C", "C", "C", "C", "D", "D", "D", "D"), value = c(8.88, 5.84,
13.28, 16.89, 21.39, 20.77, 28.03, 19.78, 28.89, 35.41, 37.47,
50.11, 50.84, 53.21, 46.47, 45.03)), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"))
我正在创建一个带有显着性水平条的基本箱线图(如此处所示:
我使用的数据如下:
title1 | title2 | value |
---|---|---|
1 | A | 8.88 |
2 | A | 5.84 |
3 | A | 13.28 |
4 | A | 16.89 |
1 | B | 21.39 |
2 | B | 20.77 |
3 | B | 28.03 |
4 | B | 19.78 |
1 | C | 28.89 |
2 | C | 35.41 |
3 | C | 37.47 |
4 | C | 50.11 |
1 | D | 50.84 |
2 | D | 53.21 |
3 | D | 46.47 |
4 | D | 45.03 |
使用以下代码,创建箱线图效果很好。对于显着性条,我想使用配对 t 检验,例如 title2=A 与 title2=B,其中 title1=1 的两行是一对,依此类推。
在 R 中,我输入了以下命令,但它对 p 产生了不同的结果。例如,A 与 D 的 p 值应为 0.003,但 R 的结果为 2.8e-05。配对 t 检验的正确语法是什么?
library(ggplot2)
library(ggsignif)
ggplot(bxp, aes(y=value,x=title2)) +
xlab("Behandlung") +
scale_x_discrete(labels=c("Kontrolle","Stretch","Hyperoxie","Stretch & Hyperoxie")) +
ylab("Zelluläre Seneszenz (%)") + theme_classic() +
geom_boxplot(coef = Inf) +
geom_signif(comparisons=list(c("A","B"),c("A","C"),c("A","D")), test=t.test, map_signif_level=FALSE, step_increase=0.08)
谢谢!
ggsignif
正在计算未配对的 t-test,我认为您需要配对测试。幸运的是 geom_signif
有一个 test.args
参数,它允许您将 paired = TRUE
传递给 geom:
ggplot(bxp, aes(y=value,x=title2)) +
xlab("Behandlung") +
scale_x_discrete(labels=c("Kontrolle","Stretch","Hyperoxie","Stretch & Hyperoxie")) +
ylab("Zelluläre Seneszenz (%)") + theme_classic() +
geom_boxplot(coef = Inf) +
geom_signif(comparisons=list(c("A","B"),c("A","C"),c("A","D")), test=t.test, test.args = list(paired = T), map_signif_level=FALSE, step_increase=0.08)
数据:
bxp <- structure(list(title1 = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4), title2 = c("A", "A", "A", "A", "B", "B", "B", "B",
"C", "C", "C", "C", "D", "D", "D", "D"), value = c(8.88, 5.84,
13.28, 16.89, 21.39, 20.77, 28.03, 19.78, 28.89, 35.41, 37.47,
50.11, 50.84, 53.21, 46.47, 45.03)), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"))