双向方差分析的同方差检验

发布于 2024-09-03 18:25:42 字数 438 浏览 5 评论 0原文

我一直在使用 var.testbartlett.test 来检查基本的方差分析假设,其中包括同质性(同质性、方差相等)。对于单向方差分析,程序非常简单:

bartlett.test(x ~ g)  # where x is numeric, and g is a factor
var.test(x ~ g)

但是,对于 2x2 表,即双向方差分析,我想做这样的事情:

bartlett.test(x ~ c(g1, g2))  # or with list; see latter:
var.test(x ~ list(g1, g2))

当然,可以使用图形程序检查方差分析假设,但是“算术选项”?这是可以管理的吗?如何在双向方差分析中检验同方差性?

I've been using var.test and bartlett.test to check basic ANOVA assumptions, among others, homoscedascity (homogeniety, equality of variances). Procedure is quite simple for One-Way ANOVA:

bartlett.test(x ~ g)  # where x is numeric, and g is a factor
var.test(x ~ g)

But, for 2x2 tables, i.e. Two-Way ANOVA's, I want to do something like this:

bartlett.test(x ~ c(g1, g2))  # or with list; see latter:
var.test(x ~ list(g1, g2))

Of course, ANOVA assumptions can be checked with graphical procedures, but what about "an arithmetic option"? Is that, at all, manageable? How do you test homoscedascity in Two-Way ANOVA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伪心 2024-09-10 18:25:42

假设检验是评估模型假设有效性的错误工具。如果样本量很小,即使方差差异很大,您也没有能力检测任何方差差异。如果你有很大的样本量,你就有能力检测到最微小的等方差偏差,所以你几乎总是会拒绝零值。模拟研究表明,模型假设的初步测试会导致不可靠的 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')

使用稳健方法(异方差一致协方差矩阵)不会失去太多功效,因此如果有疑问,请采用稳健方法。

Hypothesis testing is the wrong tool to use to asses the validity of model assumptions. If the sample size is small, you have no power to detect any variance differences, even if the variance differences are large. If you have a large sample size you have power to detect even the most trivial deviations from equal variance, so you will almost always reject the null. Simulation studies have shown that preliminary testing of model assumption leads to unreliable type I errors.

Looking at the residuals across all cells is a good indicator, or if your data are normal, you can use the AIC or BIC with/without equal variances as a selection procedure.

If you think there are unequal variances, drop the assumption with something like:

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')

You don't loose much power with the robust method (hetroscedastic consistent covariance matrices), so if in doubt go robust.

淡看悲欢离合 2024-09-10 18:25:42

您可以使用 Fligner–Killeen 测试< /a> 方差的同质性。假设您的模型类似于

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

您可以使用 bartlett。测试(但这更多的是对非正态性的测试,而不是方差相等的测试)

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

此外,您可以对单向和双向的相等组方差执行Levene测试方差分析。 Levene 测试的实现可以在包 car 中找到(链接已修复),s20x 和 < a href="http://finzi.psych.upenn.edu/R/library/lawstat/html/levene.test.html" rel="nofollow noreferrer">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 

You can test for heteroscedasticity using the Fligner–Killeen test of homogeneity of variances. Supposing your model is something like

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

You could have used bartlett.test (but this is more a test of non-normality than of equality of variances)

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

Moreover, you could perform the Levene test for equal group variances in both one-way and two-way ANOVA. Implementations of Levene's test can be found in packages car (link fixed), s20x and 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 
蓝梦月影 2024-09-10 18:25:42

对于 bartlett.test

bartlett.test(split(x,list(g1,g2)))

var.test 不适用,因为它仅在有两个组时才有效。

For bartlett.test

bartlett.test(split(x,list(g1,g2)))

var.test is not applicable as it works only when there are two groups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文