如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
统计建模与R软件第七讲-方差分析7.1单因素方差分析7.2双因素方差分析7.3正交试验设计与方差分析方差分析是统计检验的一种。由英国著名统计学家:R.A.FISHER推导出来的,也叫F检验。用于多个样本间均数的比较。方差是描述变异的一种指标,方差分析也就是对变异的分析。方差分析是按照设计类型将变量的总变异分解为若干部分,再通过比较各部分的变异做出统计推断的检验方法。7.1单因素方差分析考虑统计量:7.1.3方差分析表的计算x=scan('dataexample702.txt')a=factor(rep(1:4,c(7,5,8,6)))lamp=data.frame(x,a)lamp.aov=aov(x~a,data=lamp)summary(lamp.aov)anova.tab<-function(fm){tab<-summary(fm)k<-length(tab[[1]])-2temp<-c(sum(tab[[1]][,1]),sum(tab[[1]][,2]),rep(NA,k))tab[[1]]["total",]<-temptab}attributes(tab)$class[1]"summary.aov""listof">is.list(tab)[1]TRUE例7.37.1.4均值的多重比较Usage:pairwise.t.test(x,g,p.adjust.method=p.adjust.methods,pool.sd=!paired,paired=FALSE,alternative=c("two.sided","less","greater"),...)x:responsevector.g:groupingvectororfactor.p.adjust.method:Methodforadjustingpvalues.pool.sd:switchtoallow/disallowtheuseofapooledSDpaired:alogicalindicatingwhetheryouwantpairedt-tests.alternative:acharacterstringspecifyingthealternativehypothesis,mustbeoneof"two.sided"(default),"greater"or"less".DetailsThepool.SDswitchcalculatesacommonSDforallgroupsandusedthatforallcomparisons(thiscanbeusefulifsomegroupsaresmall).Thismethoddoesnotactuallycallt.test,soextraargumentsareignored.Poolingdoesnotgeneralizetopairedtestssopool.SDandpairedcannotbothbeTRUE.mu=c(mean(x[a==1]),mean(x[a==2]),mean(x[a==3]))pairwise.t.test(x,a,p.adjust.method='none')PairwisecomparisonsusingttestswithpooledSDdata:xanda1220.00072-30.002380.54576Pvalueadjustmentmethod:none7.1.5方差的齐次性检验常用的检验方法是Bartlett检验例7.6关于例7.1和7.3小结:7.1.6Kruskal-Wallis秩和检验:R函数kruskal.test()及其例7.7#假设成立的检验:shapiro.test(x[g==1])p-value=0.828shapiro.test(x[g==2])p-value=0.4741shapiro.test(x[g==3])p-value=0.7506shapiro.test(x[g==4])p-value=0.08516bartlett.test(x~g,data=food)p-value=0.8175#方差齐次性检验,结果通过#假设成立的情况下,进行方差分析food.sol=aov(x~g,data=food)>summary(food.sol)DfSumSqMeanSqFvaluePr(>F)g33308.11102.691.3780.2769Residuals2116803.9800.197.1.7friedman秩和检验R函数friedman.test()及其例7.8注:kruskal-wallis检验与方差分析结果一致,但是kruskal