如何在 R 中对多个参数进行方差分析检验
How to do an ANOVA test of multiple parameters in R
我有一个如下图所示的数据结构(两个群体和一些参数)。我对编码感到困惑。请问如何进行方差分析来降低每个参数的适用性(F,p值)?
您可以尝试这样的操作,但可能需要考虑多重比较:
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)。
我有一个如下图所示的数据结构(两个群体和一些参数)。我对编码感到困惑。请问如何进行方差分析来降低每个参数的适用性(F,p值)?
您可以尝试这样的操作,但可能需要考虑多重比较:
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)。