简体   繁体   English

Levene测试的多重比较Post-Hoc测试

[英]Multiple Comparison Post-Hoc test for Levene's test

I'd like to do a pairwise comparison post-hoc test on Levene's test in R. I know how to do it in SAS using PROC GLM but I can't seem to figure out how to do it in R. Does anyone have any idea? 我想对Levene在R中的测试进行成对比较事后测试。我知道如何使用PROC GLM在SAS中做到这一点但我似乎无法弄清楚如何在R中做到这一点。有没有人有任何理念? In the example below I'd like to be able to test the homogeneity of the variance between all levels of "cat" ie AB, AC, AD, BC, BD, CD. 在下面的例子中,我希望能够测试所有级别的“猫”即AB,AC,AD,BC,BD,CD之间的方差的同质性。 The best way I've found is to subset my data to each of those pairs, then run a Levene's test for each subset, then do a Bonferroni correction at the end. 我发现的最好的方法是将我的数据子集化到每个对中,然后对每个子集运行Levene测试,然后在最后进行Bonferroni校正。 However, this isn't a practical solution when my number of factors becomes large. 然而,当我的因素变得很大时,这不是一个实际的解决方案。

library(car)
dat <- rnorm(100, mean=50, sd=10)
cat <- rep(c("A", "B", "C","D"), each=25)
df <- data.frame(cat,dat)
df$cat <- as.factor(df$cat)

LT <- leveneTest(dat ~ cat, data = df)

Because a Levene test is simply an ANOVA conducted on sample variance (residuals) instead of sample means, you can calculate the residuals manually, then run the ANOVA with a TukeyHSD test as a post-hoc. 因为Levene检验只是对样本方差(残差)而不是样本均值进行的ANOVA,您可以手动计算残差,然后使用TukeyHSD检验作为事后运行ANOVA。

First, multiple comparisons as the title suggests: Using your example, with an extra factor (cat2) so we can do an interaction as well: 首先,作为标题的多重比较表明:使用您的示例,使用额外因子(cat2),以便我们也可以进行交互:

df <- df %>% group_by(cat, cat2) %>% 
  mutate(dat.med = ifelse(dat,median(Ctmax, na.rm=TRUE), ifelse(dat==NA, NA)))

The code above skips NA values and calculates sample medians for each factor combination, putting them in a new column (dat.med) in the dataset. 上面的代码跳过NA值并计算每个因子组合的样本中位数,将它们放在数据集中的新列(dat.med)中。

Then we calculate the residuals, changing them to absolute values and putting them in another column: 然后我们计算残差,将它们更改为绝对值并将它们放在另一列中:

df$dat.med.res<-abs(df$dat-df$dat.med)

# Then we run an ANOVA, and post-hoc if necessary:
levene.dat.aov<-aov(dat.med.res~cat*cat2,df)
summary(levene.dat.aov)
TukeyHSD(levene.dat.aov)

To add in repeated measures, change the anova to: 要添加重复测量,请将anova更改为:

 aov(dat.med.res~cat+Error(Subject/(cat)),df)

For a pairwise comparison with a two-level factor (using package PairedData): 对于与两级因子的成对比较(使用包PairedData):

levene.var.test(df$dat[df$cat=="A"], df$dat[df$cat=="B"],location=c("median")) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM