我如何 运行 Kruskal 和 post HOC 在 R 中的多个变量上?
How do I run Kruskal and post HOC on multiple variables in R?
如果我没有正确格式化我的代码,请原谅,因为我是这个网站的新手。我也不知道如何正确提供示例数据。
我有一个42个obs的数据集。以及37个非正态分布数据的变量(第一列为组,3组);我想比较 3 组之间的所有 36 个参数,然后进行后续 post hoc (pairwise.wilcox?)。
数据是三个不同患者组的流动细胞计数。我已经能够执行创建公式和 运行 aov 的初始比较(虽然我想做 Kruskal)但是还没有找到一种方法来执行 post hoc 到相同的所有变量方式。
#Data
Type Neutrophils Monocytes NKC .....
------------------------------------------
IN 546 2663 545
IN 0797 7979 008
OUT 0899 3899 345
OUT 6868 44533 689
HC 9898 43443 563
#Cbind all variable together to run model on all
formula <- as.formula(paste0("cbind(", paste(names(LessCount)[-1],
collapse = ","), ") ~ Type"))
print(formula)
#Run test on model
fit <- aov(formula, data=LessCount)
#Print results
summary(fit)
Response Neutrophils :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 18173966 9086983 1.8099 0.1771
Residuals 39 195806220 5020672
Response Monocytes :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 694945 347472 0.7131 0.4964
Residuals 39 19004809 487303
Response Mono.Classic :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 1561778 780889 2.5842 0.08833 .
Residuals 39 11785116 302182
###export anova####
capture.output(summary(fit),file="test1.csv")
#If Significant,Check which# (currently doing by hand individually)
pairwise.wilcox.test(LessCount$pDCs, LessCount$Type,
p.adjust.method = "BH")
我得到了 table 我控制台中每个变量的 aov 结果,但我想对 post hoc 做同样的事情,因为我需要每个 p 值。
提前致谢。
也许你可以直接使用函数 kruskal.test()
得到 p.values.
这是鸢尾花数据集的示例。我使用函数 apply()
以便将 kruskal.test 函数应用于每个变量(除了 Species,它是具有组信息的变量)。
data(iris)
apply(iris[-5], 2, function(x) kruskal.test(x = x, g = iris$Species)$p.value)
# Sepal.Length Sepal.Width Petal.Length Petal.Width
# 8.918734e-22 1.569282e-14 4.803974e-29 3.261796e-29
如果我没有正确格式化我的代码,请原谅,因为我是这个网站的新手。我也不知道如何正确提供示例数据。
我有一个42个obs的数据集。以及37个非正态分布数据的变量(第一列为组,3组);我想比较 3 组之间的所有 36 个参数,然后进行后续 post hoc (pairwise.wilcox?)。
数据是三个不同患者组的流动细胞计数。我已经能够执行创建公式和 运行 aov 的初始比较(虽然我想做 Kruskal)但是还没有找到一种方法来执行 post hoc 到相同的所有变量方式。
#Data
Type Neutrophils Monocytes NKC .....
------------------------------------------
IN 546 2663 545
IN 0797 7979 008
OUT 0899 3899 345
OUT 6868 44533 689
HC 9898 43443 563
#Cbind all variable together to run model on all
formula <- as.formula(paste0("cbind(", paste(names(LessCount)[-1],
collapse = ","), ") ~ Type"))
print(formula)
#Run test on model
fit <- aov(formula, data=LessCount)
#Print results
summary(fit)
Response Neutrophils :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 18173966 9086983 1.8099 0.1771
Residuals 39 195806220 5020672
Response Monocytes :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 694945 347472 0.7131 0.4964
Residuals 39 19004809 487303
Response Mono.Classic :
Df Sum Sq Mean Sq F value Pr(>F)
Type 2 1561778 780889 2.5842 0.08833 .
Residuals 39 11785116 302182
###export anova####
capture.output(summary(fit),file="test1.csv")
#If Significant,Check which# (currently doing by hand individually)
pairwise.wilcox.test(LessCount$pDCs, LessCount$Type,
p.adjust.method = "BH")
我得到了 table 我控制台中每个变量的 aov 结果,但我想对 post hoc 做同样的事情,因为我需要每个 p 值。
提前致谢。
也许你可以直接使用函数 kruskal.test()
得到 p.values.
这是鸢尾花数据集的示例。我使用函数 apply()
以便将 kruskal.test 函数应用于每个变量(除了 Species,它是具有组信息的变量)。
data(iris)
apply(iris[-5], 2, function(x) kruskal.test(x = x, g = iris$Species)$p.value)
# Sepal.Length Sepal.Width Petal.Length Petal.Width
# 8.918734e-22 1.569282e-14 4.803974e-29 3.261796e-29