统计与科研

方差齐次性检验Comparing Variances in R

2020-04-02  本文已影响0人  谢俊飞

在STHDA网站Comparing Variances in R 一文中,专门对正态性检验做了详致的说明,翻译并整理入下:

图片.png

(一) F检验F-Test

F检验用于评估两个总体(A和B)的方差是否相等。
F-Test: Compare Two Variances in R.

> var.test(len ~ supp, data = my_data)

    F test to compare two variances

data:  len by supp
F = 0.6386, num df = 29, denom df = 29, p-value = 0.2331
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.3039488 1.3416857
sample estimates:
ratio of variances 
         0.6385951 

(二) 比较方差的统计检验 Homogeneity of variances

有许多检验可以检测不同组之间方差的均等性(均一性),包括:

Bartlett’s test用于测试k个样本中方差的均匀性,其中k可以大于2。 适用于正态分布的数据。 当数据分布为非正态分布时,下一部分将描述的Levene检验是Bartlett检验的更稳健的替代方案。

2.1 Compute Bartlett’s test in R
# Bartlett’s test with one independent variable:
> bartlett.test(weight ~ group, data = PlantGrowth)

    Bartlett test of homogeneity of variances

data:  weight by group
Bartlett's K-squared = 2.8786, df = 2, p-value = 0.2371

# Bartlett’s test with multiple independent variables: 
> bartlett.test(len ~ interaction(supp,dose), data=ToothGrowth)

    Bartlett test of homogeneity of variances

data:  len by interaction(supp, dose)
Bartlett's K-squared = 6.9273, df = 5, p-value = 0.2261
2.2 Compute Levene’s test in R
library(car)
> # Levene's test with one independent variable
> leveneTest(weight ~ group, data = PlantGrowth)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  2  1.1192 0.3412
      27               
> # Levene's test with multiple independent variables
> leveneTest(len ~ supp*dose, data = ToothGrowth)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  5  1.7086 0.1484
      54               
2.3 Compute Fligner-Killeen test in R
> fligner.test(weight ~ group, data = PlantGrowth)

    Fligner-Killeen test of homogeneity of variances

data:  weight by group
Fligner-Killeen:med chi-squared = 2.3499, df = 2, p-value = 0.3088

参考资料:

  1. Comparing Variances in R
  2. 假设检验-方差齐性检验
上一篇 下一篇

猜你喜欢

热点阅读