有没有办法通过包中的map()
功能进行 Levene 测试purrr
?还是有另一种简单的方法来计算各种变量的 Levene 测试?
我的数据框包含各种因子和数字列,所以我尝试使用map_if()
,它工作正常,例如用于夏皮罗测试。但是,我不知道如何指定公式。我想根据“治疗”因素测试我所有的数字变量。
library("tidyverse")
library("rstatix")
data <- data.frame(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L),
.Label = c("S1 ", "S2 ", "S3 "), class = "factor"),
plot = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L),
.Label = c(" Tree 1 ", " Tree 2 ", " Tree 3 "), class = "factor"),
Treatment = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L), .Label = c("T1", "T2"), class = "factor"),
flux1 = c(11.52188065, 8.43156699, 4.495312274, -1.866676811, 3.861102035, -0.814742373, 6.51039536, 4.767950345, 10.36544542, 1.065963875),
flux2 = c(0.142259208, 0.04060245, 0.807631744, 0.060127596, -0.157762562, 0.062464942, 0.043147603, 0.495001652, 0.34363348, 0.134183704),
flux3 = c(0.147506197, 1.131009714, 0.038860728, 0.0176834, 0.053191593, 0.047591306, 0.00573377, -0.034926075, 0.123379247, 0.018882469))
map_if(data, is.numeric, levene_test(. ~ Treatment))
有什么建议么?谢谢你的帮助!
现在还有一个可重现的例子;)