R中的N向ANOVA [英] N-way ANOVA in R

查看:180
本文介绍了R中的N向ANOVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来执行R中的N向ANOVA,以捕获不同因素之间的相互依存关系.在我的数据中,大约有100个不同的因素,我正在使用以下代码执行ANOVA.

I need some help in performing N-way ANOVA in R to capture inter dependencies among different factors. In my data, there are around 100 different factors and I am using the following code to perform ANOVA.

model.lm<-lm(y~., data=data)
anova(model.lm)

据我所知(可能是我错了),它仅对每个因子执行1向ANOVA.由于某些原因,我需要在所有100个组之间(即从x1到x100)执行N次方差分析.我是否需要像下面这样指定每个因素,或者为此有一个简写形式?

As far as I know (may be I am wrong) that this performs 1-way ANOVA at each factor alone. For some reasons, I need to perform N-way ANOVA between all the 100 groups i.e from x1 to x100. Do I need to specify each factor like the following or there is a shorthand notation for this?

model.lm<-lm(y~x1*x2*x3....,x100, data=data)
anova(model.lm)

推荐答案

您可以使用update.formula~(.)^n表示法.

例如,对于一个模型,该模型包括来自4个变量abcd的三向交互作用

Eg for a model including 3-way interactions from 4 variables a, b, c and d

update(~a+b+c+d, ~(.)^3)


## ~a + b + c + d + a:b + a:c + a:d + b:c + b:d + c:d + a:b:c + a:b:d + a:c:d + b:c:d

因此,对于您要适合100次互动的示例,我建议考虑使用一种更合适的模型(尤其是在该考虑的时候).

So for your example where you want to fit 100-way interactions, I would suggest thinking of a more appropriate model (especially if it is time you are accounting for here).

如果您决定继续使用基本的ANOVA方法,则可以执行以下操作(并等待R因大数据/不合适的模型而导致内存问题而崩溃.)

If you decide to continue with the basic ANOVA approach you could do something like this (and wait for R to crash due having memory issues due to your large data / inappropriate model.)

xvars <- paste0('x',1:100)
oneway <- reformulate(termlabels=  xvars, response = 'y')


horribleformula <- update(oneway, . ~ (.)^100)

horriblemodel <- lm(horribleformula, data=data)

或者((感谢@Dason帮忙)

Or (thanks to @Dason for picking this up)

 stillhorrible <- lm(y ~ .^100, data = data)

这篇关于R中的N向ANOVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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