R统计分析_变量同质性检验

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

英文:http://www.cookbook-r.com/Statistical_analysis/Homogeneity_of_variance/
中文:https://openbiox.github.io/Cookbook-for-R-Chinese/section-7.html#section-7.6
像t检验、ANOVA等统计分析都有适用条件,在进行数据分析时,首先需要对数据进行符合他条件的相应检验,才能进行下一步的统计分析。
There are many ways of testing data for homogeneity of variance. Three methods are shown here.

head(InsectSprays)
tg <- ToothGrowth
tg$dose <- factor(tg$dose)
head(tg)
plot(count~spray, data = InsectSprays)
plot(len~interaction(dose, supp), data = ToothGrowth)

#有多个独立变量,必须使用 interaction() 函数将这些独立变量包裹为含所有因子组合的单个变量。
#如果不适应,那么会得到错误的自由度,因而 p 值也将是错误的。
#Bartlett’s test
bartlett.test(count~spray, data = InsectSprays)
bartlett.test(len~interaction(dose, supp), data = ToothGrowth)
bartlett.test(len~dose, data = ToothGrowth)

#Levene’s test
library(car)
leveneTest(count~spray, data = InsectSprays)
leveneTest(len~dose*supp, data = tg)

#Fligner-Killeen test
fligner.test(count~spray, data = InsectSprays)
fligner.test(len~interaction(dose, supp), data = ToothGrowth)
fligner.test(len~dose, data = ToothGrowth)

Rplot01.png Rplot02.png
上一篇下一篇

猜你喜欢

热点阅读