【发布时间】:2019-05-29 13:25:09
【问题描述】:
我的问题与this one 有关,但有一个更复杂的示例,我想在其中统计比较所有组合中的多列,并且每一列都有不同数量的样本。
考虑原始数据:
# A tibble: 51 x 3
trial person score
<chr> <chr> <dbl>
1 foo a 0.266
2 bar b 0.372
3 foo c 0.573
4 bar a 0.908
5 foo b 0.202
6 bar c 0.898
7 foo a 0.945
8 bar b 0.661
9 foo c 0.629
10 foo b 0.206
对于每种试验类型,我想运行一个统计测试来比较每个人的分数。所以,我需要以下测试结果:
- 试用
foo,比较所有scoreA-B、B-C、C-A 人的样本 - 试用
bar,比较所有scoreA-B、B-C、C-A 人的样本
当然,试炼不止两个,也不止三个人。
因此,在另一个问题中给出的使用group_split 的解决方案不起作用,因为它意味着始终测试第一人称(在我的情况下),而不是所有成对组合。
所以,在下面的代码中,我被困在了两点:
library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
library(broom)
set.seed(1)
df = tibble::tibble(
trial = rep(c("foo", "bar"), 30),
person = rep(c("a", "b", "c"), 20),
score = runif(60)
) %>%
filter(score > 0.2)
df %>%
group_by(person, trial) %>%
summarize(scores = list(score)) %>%
spread(person, scores) %>%
group_split(trial) %>%
map_df(function(data) {
data %>%
summarize_at(vars(b:c), function(x) {
wilcox.test(.$a, x, paired = FALSE) %>% broom::tidy
})
})
#> Error in wilcox.test.default(.$a, x, paired = FALSE): 'x' must be numeric
由reprex package (v0.3.0) 于 2019 年 5 月 29 日创建
x 的值显然不仅仅是实际的分数列表,而是单个试验的分数列向量。但是我不知道如何处理每个人的样本数量不同的事实。
另外,我仍然需要手动指定列名,如果有四个以上的人,这将是一场组合噩梦。
我可以通过某种方式得到这样的组合:
df %>%
group_split(trial) %>%
map_df(function(data) {
combinations = expand(tibble(x = unique(data$person), y = unique(data$person)), x, y) %>% filter(x != y)
})
…但这并不能真正帮助创建用于比较的列。
我能做些什么来完成这项工作?
【问题讨论】:
-
在有人提到很多统计成对比较需要 alpha 校正之前。