在组上映射 wilcoxon-rank-sum-test
mapping wilcoxon-rank-sum- test on groups
所以我正在尝试对分组数据框执行 wilcoxon-rank-sum-test。变量“Feuchte”(=numeric)和“Transtyp”(=factor)应针对每个组(soll)进行测试我想要一个数据框,其中包含每个组的 p 值作为输出。
我的 df 看起来像这样:
BF_all_soll <- structure(list(Datum = structure(c(18758, 18758, 18758, 18758,
18758, 18758, 18758, 18758, 18758, 18758, 18758, 18758, 18758,
18758, 18758, 18758), class = "Date"), Soll = c("1189", "1189",
"119", "119", "1192", "1192", "1202", "1202", "149", "149", "172",
"172", "2484", "2484", "552", "552"), Transtyp = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("2",
"5"), class = "factor"), Feuchte = c(11.9171875, 14.078125, 10.7153846153846,
10.6387096774194, 13.675, 13.7896551724138, 18.5, 17.071875,
12.390625, 9.690625, 12.3935483870968, 11.6, 10.578125, 10.21875,
13.021875, 13.225), kumsum = c(25.04, 25.04, 20.77, 20.77, 25.04,
25.04, 25.04, 25.04, 20.77, 20.77, 20.77, 20.77, 25.04, 25.04,
25.04, 25.04)), row.names = c(NA, -16L), groups = structure(list(
Soll = c("1189", "1189", "119", "119", "1192", "1192", "1202",
"1202", "149", "149", "172", "172", "2484", "2484", "552",
"552"), Transtyp = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("2", "5"), class = "factor"),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
到目前为止我写的代码是这样的
BF_all_soll %>% split( BF_all_soll$Soll) %>%
map( ~wilcox.test(Feuchte ~ Transtyp, data = BF_all_soll))%>%
map_dfr(~ broom::tidy(.)) ->bla
但是,输出不正确。 p 值都相同。我错过了什么?非常感谢任何帮助!
干杯
那是因为您在 wilcox.test
中使用了相同的数据 (BF_all_soll
)。要使用特定于每个组的数据,请在 map
.
中使用 .x
library(dplyr)
library(purrr)
BF_all_soll %>%
ungroup() %>%
split(.$Soll) %>%
map_df( ~broom::tidy(wilcox.test(Feuchte ~ Transtyp, data = .x))) -> bla
这再次为共享数据提供相同的 p 值,但应该为更大的数据提供正确的 p 值。
所以我正在尝试对分组数据框执行 wilcoxon-rank-sum-test。变量“Feuchte”(=numeric)和“Transtyp”(=factor)应针对每个组(soll)进行测试我想要一个数据框,其中包含每个组的 p 值作为输出。 我的 df 看起来像这样:
BF_all_soll <- structure(list(Datum = structure(c(18758, 18758, 18758, 18758,
18758, 18758, 18758, 18758, 18758, 18758, 18758, 18758, 18758,
18758, 18758, 18758), class = "Date"), Soll = c("1189", "1189",
"119", "119", "1192", "1192", "1202", "1202", "149", "149", "172",
"172", "2484", "2484", "552", "552"), Transtyp = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("2",
"5"), class = "factor"), Feuchte = c(11.9171875, 14.078125, 10.7153846153846,
10.6387096774194, 13.675, 13.7896551724138, 18.5, 17.071875,
12.390625, 9.690625, 12.3935483870968, 11.6, 10.578125, 10.21875,
13.021875, 13.225), kumsum = c(25.04, 25.04, 20.77, 20.77, 25.04,
25.04, 25.04, 25.04, 20.77, 20.77, 20.77, 20.77, 25.04, 25.04,
25.04, 25.04)), row.names = c(NA, -16L), groups = structure(list(
Soll = c("1189", "1189", "119", "119", "1192", "1192", "1202",
"1202", "149", "149", "172", "172", "2484", "2484", "552",
"552"), Transtyp = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("2", "5"), class = "factor"),
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
到目前为止我写的代码是这样的
BF_all_soll %>% split( BF_all_soll$Soll) %>%
map( ~wilcox.test(Feuchte ~ Transtyp, data = BF_all_soll))%>%
map_dfr(~ broom::tidy(.)) ->bla
但是,输出不正确。 p 值都相同。我错过了什么?非常感谢任何帮助!
干杯
那是因为您在 wilcox.test
中使用了相同的数据 (BF_all_soll
)。要使用特定于每个组的数据,请在 map
.
.x
library(dplyr)
library(purrr)
BF_all_soll %>%
ungroup() %>%
split(.$Soll) %>%
map_df( ~broom::tidy(wilcox.test(Feuchte ~ Transtyp, data = .x))) -> bla
这再次为共享数据提供相同的 p 值,但应该为更大的数据提供正确的 p 值。