【发布时间】:2021-04-30 21:30:43
【问题描述】:
我有一个数据集,我正在尝试应用shapiro.test。
test_data <- tibble(
gene = rep(c(LETTERS[1:5]), times = 2, each = 5),
treatment = c(rep('control', times = 25) , rep('treatment', times = 25)),
day = rep(c(1:2), times = 5, each = 5),
data = rnorm(50, mean = 25, sd = 5)
)
# A tibble: 50 x 4
gene treatment day data
<chr> <chr> <int> <dbl>
1 A control 1 28.8
2 A control 1 22.4
3 A control 1 24.8
4 A control 1 20.1
5 A control 1 15.6
6 B control 2 26.5
7 B control 2 26.2
8 B control 2 25.3
9 B control 2 21.4
10 B control 2 35.0
# … with 40 more rows
我创建了一个函数来按基因、治疗和天运行测试:
normality_test <- function(x, y, z){
with(test_data, shapiro.test(data[gene == x & treatment == y & day == z]))
}
因此,如果我运行 normality_test('A', 'control', '1'),它将在 第 1 天在 control 中测试 gene A。
Shapiro-Wilk normality test
data: data[gene == x & treatment == y & day == z]
W = 0.99935, p-value = 0.9998
但是,我希望该函数循环遍历基因/治疗/天的所有组合并单独输出每个正态性测试,但无法弄清楚。
我已经能够创建一个循环,将每一行输出为单独的tibble,但未能成功分离行中的每个元素以添加到normality_test 函数中。
我还尝试了map 和lmap,但无济于事。
谢谢。
【问题讨论】: