#gl()函数可以很方便的产生因子,其一般方法是:#gl(n,k,length=n*k,labels=1:nordered=FALSE),n为水平数,k为重复次数.gl(3,5,15);gl(3,1,15)一、单因素方差分析程序如下:X1-c(163,176,170,185);X2-c(184,198,179,190);X3-c(206,191,218,224);X-c(X1,X2,X3);A-factor(rep(1:3,c(4,4,4)));plot(X~A)product.aov-aov(X~A);anova.tab(product.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}二、双因素方差分析1.无重复试验(例4.23)X-c(3.72,3.90,4.02,5.22,5.24,5.08,5.28,5.74,5.54)A-gl(3,3,9)B-gl(3,1,9)weight-aov(X~A+B)anova.tab(weight)2.重复试验(例4.22)X-c(2.7,3.3,1.71,2.14,1.9,2,2.72,1.85,1.38,1.35,1.74,1.56,3.14,2.29,3.51,3.15,2.35,1.95,1.67,1.5,1.63,1.05,1.39,1.72,2.26,2.13,3.41,2.56,3.17,3.18,2.22,2.19)A-gl(4,8,32)B-gl(4,2,32)weight-aov(X~A+B+A:B)anova.tab(weight)