aL3*_*3xa 15 testing r variance anova
我一直在使用var.test
和bartlett.test
检查基本的方差分析假设,其中包括同质性(同质性,方差等式).单因素方差分析的程序非常简单:
bartlett.test(x ~ g) # where x is numeric, and g is a factor
var.test(x ~ g)
Run Code Online (Sandbox Code Playgroud)
但是,对于2x2表,即双向ANOVA,我想做这样的事情:
bartlett.test(x ~ c(g1, g2)) # or with list; see latter:
var.test(x ~ list(g1, g2))
Run Code Online (Sandbox Code Playgroud)
当然,可以使用图形化程序检查ANOVA假设,但是"算术选项"呢?这根本就是可管理的吗?你如何在双因素方差分析中测试同性恋?
Ian*_*ows 18
假设检验是用来评估模型假设有效性的错误工具.如果样本量很小,即使方差差异很大,也无法检测到任何方差.如果你有一个很大的样本量,你有能力检测到相等方差的最微不足的偏差,所以你几乎总是拒绝空值.模拟研究表明,模型假设的初步测试会导致不可靠的I类错误.
纵观所有细胞中的残留物是一个很好的指标,或者如果你的数据是正常的,你可以使用AIC或BIC带/不相等的方差作为选择的过程.
如果您认为存在不等的差异,请使用以下内容删除假设:
library(car)
model.lm <- lm(formula=x ~ g1 + g2 + g1*g2,data=dat,na.action=na.omit)
Anova(model.lm,type='II',white.adjust='hc3')
Run Code Online (Sandbox Code Playgroud)
使用稳健的方法(历史一致的协方差矩阵)不会消耗太多的力量,所以如果有疑问则会变得强大.
您可以使用Fligner-Killeen检验方差同质性来检验异方差性.假设你的模型是这样的
model<-aov(gain~diet*supplement)
fligner.test(gain~diet*supplement)
Fligner-Killeen test of homogeneity of variances
data: gain by diet by supplement
Fligner-Killeen:med chi-squared = 2.0236, df = 2, p-value = 0.3636
Run Code Online (Sandbox Code Playgroud)
您可以使用bartlett.test(但这更像是对非正态性的测试,而不是对方差的相等性)
bartlett.test(gain~diet*supplement)
Bartlett test of homogeneity of variances
data: gain by diet by supplement
Bartlett's K-squared = 2.2513, df = 2, p-value = 0.3244
Run Code Online (Sandbox Code Playgroud)
此外,您可以Levene test
在单向和双向ANOVA中执行相等的组差异.Levene测试的实现可以在包车(链接固定),s20x和lawstat中找到
levene.test(gain~diet*supplement) # car package version
Levene's Test for Homogeneity of Variance
Df F value Pr(>F)
group 11 1.1034 0.3866
36
Run Code Online (Sandbox Code Playgroud)
对于 bartlett.test
bartlett.test(split(x,list(g1,g2)))
Run Code Online (Sandbox Code Playgroud)
var.test
不适用,因为只有在有两个组时才有效.