在 R 中循环许多单边方差分析 [英] Looping many one-sided ANOVA in R
本文介绍了在 R 中循环许多单边方差分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对不同的数值向量运行 100 个方差分析.
I would like to run 100 ANOVA for different numeric vectors.
我的数值向量是 (ruy, fjr, akf ....) 来自我的 data.frame
My numeric vectors are (ruy, fjr, akf....) from my data.frame
aa=aov(data.frame$ruy~data.frame$Group)
anova(aa)
ab=aov(data.frame$fjr~data.frame$Group)
anova(ab)
ac=aov(data.frame$akf~data.frame$Group)
anova(ac)
.....
.....
我的循环技巧很差,所以请善待.
My looping skills are poor so please be nice.
推荐答案
由于 aov
基于 lm
你可以 cbind
依赖变量LHS,这会导致运行单独的模型:
Since aov
is based on lm
you can cbind
dependent variables on the LHS, which results in seperate models being run:
formula <- as.formula(paste0("cbind(", paste(names(iris)[-5], collapse = ","), ") ~ Species"))
fit <- aov(formula, data=iris)
summary(fit)
# Response Sepal.Length :
# Df Sum Sq Mean Sq F value Pr(>F)
#Species 2 63.212 31.606 119.26 < 2.2e-16 ***
#Residuals 147 38.956 0.265
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Response Sepal.Width :
# Df Sum Sq Mean Sq F value Pr(>F)
#Species 2 11.345 5.6725 49.16 < 2.2e-16 ***
#Residuals 147 16.962 0.1154
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#</snip>
这篇关于在 R 中循环许多单边方差分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文