如何对R中的多个参数进行ANOVA测试

问题描述 投票:1回答:1

我的数据结构如下图所示(两个总体和一些参数)。我对编码感到困惑。请问采用哪种方差分析方法降低每个参数的适用性(F,p值)?

enter image description here

r anova
1个回答
1
投票

您可以尝试这样的操作,但可能需要考虑多个比较:

library(data.table)

DT <- data.table("GROUP" = c("GR1", "GR1", "GR1", "GR2", "GR2")
               , "Weight" = c(78, 85, 84.3, 70, 67)
               , "BloodPres" = c(11, 14, 13, 12, 12)
               , "Heart" = c(140, 130, 142, 135, 120)
               , "Glucose" = c(80, 110, 95, 97, 105))

Outcomes <- c("Weight", "BloodPres", "Heart", "Glucose")

sapply(Outcomes, function(my) {
       f <- as.formula(paste(my, "~GROUP", sep=""))
       summary(aov(f, data=DT))
})

这适用于单向,但是您需要将其调整为两向(请参阅Correct use of sapply with Anova on multiple subsets in R)。

© www.soinside.com 2019 - 2024. All rights reserved.