在R中循环许多单侧方差分析 [英] Looping many one-sided ANOVA in R

查看:133
本文介绍了在R中循环许多单侧方差分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对不同的数值向量运行100方差分析.

I would like to run 100 ANOVA for different numeric vectors.

我的数字矢量来自我的data.frame(ruy,fjr,akf ....)

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,因此您可以在LHS上cbind因变量,从而导致运行单独的模型:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆