
一文展示R語言中的方差分析常用模型 #2021.9.11
方差分析是一個全新的思路,它采用的是變異分解的思路,將組內(nèi)組件分開,查看顯著性。
變異分解,和數(shù)量遺傳學(xué)的創(chuàng)立也密不可分,比如
更進(jìn)一步:表型 = 加性效應(yīng) + 非加性效應(yīng) + 環(huán)境更更進(jìn)一步:表型 = 加性效應(yīng) + 顯性效應(yīng) + 上位性效應(yīng) + 環(huán)境雜種優(yōu)勢是顯性和上位性效應(yīng)的部分基因與環(huán)境互作是:環(huán)境*基因的效應(yīng)另外還有重復(fù)力效應(yīng)(個體永久環(huán)境效應(yīng))、母體效應(yīng)、窩別效應(yīng)等等,都是使用表型數(shù)據(jù)剖分的形式進(jìn)行計算和評估。很多人分析數(shù)據(jù),想看一下顯著性與否,顯著的話就說明有差異,具體差異是多少,需要進(jìn)行多重比較。所以,先要有方差分析,才有顯著性,只有顯著了,才可以進(jìn)行多重比較。先后順序不能錯。方差分析,還有一定的前提假定。需要進(jìn)行檢驗。好在,現(xiàn)在的R語言足夠友好,各種功能都已經(jīng)打包好了,直接拿來用就行了。下面看我的總結(jié):
1. 方差分析的假定
上面這個思維導(dǎo)圖,也可以看出,方差分析有三大假定:正態(tài),獨(dú)立和齊次,如果不滿足,可以使用廣義線性模型
或者混合線性模型
,或者廣義線性混合模型
去分析。
「本次我們的主題有:」
2. 數(shù)據(jù)來源
這里,我們使用的數(shù)據(jù)來源于R包agridat
,它是講農(nóng)業(yè)相關(guān)的論文,書籍中相關(guān)的數(shù)據(jù)收集在了一起,更加符合我們的背景。
包的下載地址:https://cran./web/packages/agridat/index.html
「包的介紹」
?「agridat: Agricultural Datasets」Datasets from books, papers, and websites related to agriculture. Example graphics and analyses are included. Data come from small-plot trials, multi-environment trials, uniformity trials, yield monitors, and more.
?
「包的安裝方式:」
install.packages("agridat")
3. 單因素方差分析
?比如一個處理有A,B,C三個水平,觀測值y,想看一下這個處理是否達(dá)到顯著性水平,這就可以用到方差分析了。
?
「數(shù)據(jù)描述:」
?Corn yield and nitrogen fertilizer treatment with field characteristics for the Las Rosas farm, Rio Cuarto, Cordoba, Argentina.
?
data(lasrosas.corn)
dat <- lasrosas.corn
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 3443 obs. of 9 variables:
$ year : int 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 ...
$ lat : num -33.1 -33.1 -33.1 -33.1 -33.1 ...
$ long : num -63.8 -63.8 -63.8 -63.8 -63.8 ...
$ yield: num 72.1 73.8 77.2 76.3 75.5 ...
$ nitro: num 132 132 132 132 132 ...
$ topo : Factor w/ 4 levels "E","HT","LO",..: 4 4 4 4 4 4 4 4 4 4 ...
$ bv : num 163 170 168 177 171 ...
$ rep : Factor w/ 3 levels "R1","R2","R3": 1 1 1 1 1 1 1 1 1 1 ...
$ nf : Factor w/ 6 levels "N0","N1","N2",..: 6 6 6 6 6 6 6 6 6 6 ...
這里數(shù)據(jù)有很多列,但是我們要演示單因素方差分析,這里的因素為nf,自變量(Y變量)是yield,想要看一下nf的不同水平是否達(dá)到顯著性差異。
「建模:」
Y變量:yield
因子:nf
「R中的建模代碼:」
m1 = aov(yield ~ nf, data=dat)
yield
為數(shù)據(jù)中的Y變量,這里是yield
「結(jié)果:」
> m1 = aov(yield ~ nf, data=dat)
> summary(m1)
Df Sum Sq Mean Sq F value Pr(>F)
nf 5 23987 4797 12.4 6.08e-12 ***
Residuals 3437 1330110 387
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,nf之間達(dá)到極顯著水平,可以進(jìn)行多重比較。
「方差分析的顯著性和多重比較有何關(guān)系???」
?方差分析,一般會得到顯著性(即P值小于0.05,說明顯著,小于0.01,說明極顯著,大于0.05,說明不顯著),顯著的意思是因素之間至少有一對水平達(dá)到顯著性差異,具體是那一對呢?有幾對呢?這就需要用到多重比較。所以,多重比較是在方差分析達(dá)到顯著性之后進(jìn)行的,只有顯著了(P值小于0.05)才有能進(jìn)行多重比較。多重比較的方法有很多,比如LSD,Tukey,Bonferroni,Holm等等,我們后面系統(tǒng)的介紹。
?
4. 單因素隨機(jī)區(qū)組
這里區(qū)組的設(shè)置,可以控制一些環(huán)境誤差。
「數(shù)據(jù)描述:」
?Switchback trial in dairy with three treatments
?
data(lucas.switchback)
dat <- lucas.switchback
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 36 obs. of 5 variables:
$ cow : Factor w/ 12 levels "C1","C10","C11",..: 1 5 6 7 8 9 10 11 12 2 ...
$ trt : Factor w/ 3 levels "T1","T2","T3": 1 2 3 1 2 3 1 2 3 1 ...
$ period: Factor w/ 3 levels "P1","P2","P3": 1 1 1 1 1 1 1 1 1 1 ...
$ yield : num 34.6 22.8 32.9 48.9 21.8 25.4 30.4 35.2 30.8 38.7 ...
$ block : Factor w/ 3 levels "B1","B2","B3": 1 1 1 1 1 1 2 2 2 3 ...
「建模:」
Y變量:yield
因子:trt
區(qū)組:block
「R中的建模代碼:」
m2 = aov(yield ~ block +trt, data=dat)
summary(m2)
「結(jié)果:」
> summary(m2)
Df Sum Sq Mean Sq F value Pr(>F)
block 2 30.9 15.46 0.306 0.7385
trt 2 273.8 136.88 2.709 0.0823 .
Residuals 31 1566.1 50.52
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,trt之間達(dá)到?jīng)]有極顯著水平。
5. 二因素方差分析(無交互)
這里區(qū)組的設(shè)置,可以控制一些環(huán)境誤差。
無交互的意思是,二因素之間不考慮互作。
「數(shù)據(jù)描述:」
?Switchback trial in dairy with three treatments
?
data(lucas.switchback)
dat <- lucas.switchback
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 36 obs. of 5 variables:
$ cow : Factor w/ 12 levels "C1","C10","C11",..: 1 5 6 7 8 9 10 11 12 2 ...
$ trt : Factor w/ 3 levels "T1","T2","T3": 1 2 3 1 2 3 1 2 3 1 ...
$ period: Factor w/ 3 levels "P1","P2","P3": 1 1 1 1 1 1 1 1 1 1 ...
$ yield : num 34.6 22.8 32.9 48.9 21.8 25.4 30.4 35.2 30.8 38.7 ...
$ block : Factor w/ 3 levels "B1","B2","B3": 1 1 1 1 1 1 2 2 2 3 ...
「建模:」
「R中的建模代碼:」
m3 = aov(yield ~ block +trt +period, data=dat)
summary(m3)
「結(jié)果:」
> summary(m3)
Df Sum Sq Mean Sq F value Pr(>F)
block 2 30.9 15.46 0.308 0.7374
trt 2 273.8 136.88 2.725 0.0823 .
period 2 109.5 54.74 1.090 0.3497
Residuals 29 1456.6 50.23
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,trt之間達(dá)到?jīng)]有極顯著水平,period之間沒有達(dá)到顯著性水平。
6. 二因素方差分析(有交互)
這里區(qū)組的設(shè)置,可以控制一些環(huán)境誤差。
交互的意思是,二因素之間考慮互作。
「數(shù)據(jù)描述:」
?Switchback trial in dairy with three treatments
?
data(lucas.switchback)
dat <- lucas.switchback
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 36 obs. of 5 variables:
$ cow : Factor w/ 12 levels "C1","C10","C11",..: 1 5 6 7 8 9 10 11 12 2 ...
$ trt : Factor w/ 3 levels "T1","T2","T3": 1 2 3 1 2 3 1 2 3 1 ...
$ period: Factor w/ 3 levels "P1","P2","P3": 1 1 1 1 1 1 1 1 1 1 ...
$ yield : num 34.6 22.8 32.9 48.9 21.8 25.4 30.4 35.2 30.8 38.7 ...
$ block : Factor w/ 3 levels "B1","B2","B3": 1 1 1 1 1 1 2 2 2 3 ...
「建模:」
「R中的建模代碼:」
m4 = aov(yield ~ block +trt*period, data=dat)
summary(m4)
注意,這里的trt*period
是R中公式的簡寫,表示trt + period + trt:period
,其中trt:period
表示互作效應(yīng)。
「結(jié)果:」
> summary(m4)
Df Sum Sq Mean Sq F value Pr(>F)
block 2 30.9 15.46 0.339 0.7160
trt 2 273.8 136.88 2.997 0.0681 .
period 2 109.5 54.74 1.199 0.3183
trt:period 4 315.0 78.75 1.725 0.1761
Residuals 25 1141.6 45.66
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,trt之間達(dá)到?jīng)]有極顯著水平,period之間沒有達(dá)到顯著性水平,trt和period交互沒有達(dá)到顯著水平。
7. 多因素方差分析
這里區(qū)組的設(shè)置,可以控制一些環(huán)境誤差。
多于兩個因素的方差分析
「數(shù)據(jù)描述:」
?Switchback trial in dairy with three treatments
?
data(lucas.switchback)
dat <- lucas.switchback
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 36 obs. of 5 variables:
$ cow : Factor w/ 12 levels "C1","C10","C11",..: 1 5 6 7 8 9 10 11 12 2 ...
$ trt : Factor w/ 3 levels "T1","T2","T3": 1 2 3 1 2 3 1 2 3 1 ...
$ period: Factor w/ 3 levels "P1","P2","P3": 1 1 1 1 1 1 1 1 1 1 ...
$ yield : num 34.6 22.8 32.9 48.9 21.8 25.4 30.4 35.2 30.8 38.7 ...
$ block : Factor w/ 3 levels "B1","B2","B3": 1 1 1 1 1 1 2 2 2 3 ...
「建模:」
「R中的建模代碼:」
m5 = aov(yield ~ block + trt*period + cow, data=dat)
summary(m5)
注意,這里的trt*period
是R中公式的簡寫,表示trt + period + trt:period
,其中trt:period
表示互作效應(yīng)。
「結(jié)果:」
> summary(m5)
Df Sum Sq Mean Sq F value Pr(>F)
block 2 30.9 15.46 11.155 0.000926 ***
trt 2 273.8 136.88 98.739 9.96e-10 ***
period 2 109.5 54.74 39.486 6.49e-07 ***
cow 9 1428.8 158.76 114.523 8.29e-13 ***
trt:period 4 5.6 1.41 1.015 0.429042
Residuals 16 22.2 1.39
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,trt之間達(dá)到極顯著水平,period之間達(dá)到顯著性水平,trt和period交互沒有達(dá)到顯著水平,cow達(dá)到極顯著水平。
8. 裂區(qū)試驗方差分析
裂區(qū)試驗,包括主區(qū)(wplot)和裂區(qū)(splot),其中裂區(qū)是鑲嵌在主區(qū)中的,主區(qū)和裂區(qū)的殘差不一樣,在模型中需要特殊定義。
「數(shù)據(jù)描述:」
?Strip-split plot of barley with fertilizer, calcium, and soil factors.
?
data(cox.stripsplit)
dat <- cox.stripsplit
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 96 obs. of 5 variables:
$ rep : Factor w/ 4 levels "R1","R2","R3",..: 1 1 1 1 1 1 1 1 1 1 ...
$ soil : Factor w/ 3 levels "S1","S2","S3": 1 1 1 1 1 1 1 1 2 2 ...
$ fert : Factor w/ 4 levels "F0","F1","F2",..: 1 1 2 2 3 3 4 4 1 1 ...
$ calcium: Factor w/ 2 levels "C0","C1": 1 2 1 2 1 2 1 2 1 2 ...
$ yield : num 4.91 4.63 4.76 5.04 5.38 6.21 5.6 5.08 4.94 3.98 ...
「建模:」
「R中的建模代碼:」
m6 = aov(yield ~ rep + soil*fert + Error(rep/fert),data=dat)
summary(m6)
注意,這里的Error(rep/fert)
是R中公式的定義殘差,主要用于不同因素使用不同殘差的情況,這里fert是主區(qū)。
「結(jié)果:」
> summary(m6)
Error: rep
Df Sum Sq Mean Sq
rep 3 6.28 2.093
Error: rep:fert
Df Sum Sq Mean Sq F value Pr(>F)
fert 3 7.221 2.4071 3.562 0.0604 .
Residuals 9 6.082 0.6758
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
soil 2 1.927 0.9633 7.155 0.00146 **
soil:fert 6 0.688 0.1147 0.852 0.53433
Residuals 72 9.693 0.1346
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看出,soil達(dá)到極顯著,fert不顯著,soil和fert的互作不顯著。
9. 正態(tài)性檢驗
方差分析中,結(jié)果是否可信,在于數(shù)據(jù)是否滿足假定條件。方差分析的假定包括數(shù)據(jù)正態(tài)性
,數(shù)據(jù)的方差齊性
,數(shù)據(jù)的獨(dú)立性
,其中可以檢驗的假定有:
這里,我們介紹如何對數(shù)據(jù)的正態(tài)性進(jìn)行檢驗。
可以使用球性檢驗(Shapiro-Wilk)檢驗數(shù)據(jù)的正態(tài)性,也可以用qqplot
查看殘差的圖,判斷數(shù)據(jù)的正態(tài)性,也可以對數(shù)據(jù)做直方圖,查看數(shù)據(jù)的正態(tài)性。
「數(shù)據(jù)描述:」
?A classical N, P, K (nitrogen, phosphate, potassium) factorial experiment on the growth of peas conducted on 6 blocks. Each half of a fractional factorial design confounding the NPK interaction was used on 3 of the plots.
?
data(npk)
dat <- npk
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 24 obs. of 5 variables:
$ block: Factor w/ 6 levels "1","2","3","4",..: 1 1 1 1 2 2 2 2 3 3 ...
$ N : Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 1 1 2 ...
$ P : Factor w/ 2 levels "0","1": 2 2 1 1 1 2 1 2 2 2 ...
$ K : Factor w/ 2 levels "0","1": 2 1 1 2 1 2 2 1 1 2 ...
$ yield: num 49.5 62.8 46.8 57 59.8 58.5 55.5 56 62.8 55.8 ...
一般分析時,我們僅對Y變量進(jìn)行正態(tài)性檢驗,如果是單因素或者多因素,也可以根據(jù)因素分組進(jìn)行正態(tài)性檢驗,數(shù)據(jù)量大時,對于稍微偏態(tài)的數(shù)據(jù),即使不太符合正態(tài)分布,也不影響結(jié)論。
這里,我們對yield進(jìn)行正態(tài)性檢驗
「作直方圖」
hist(dat$yield)
可以看到,yield大體符合正態(tài)分布。
「做qq圖」
使用car
軟件包中的qqPlot
函數(shù)。
library(car)
qqPlot(dat$yield)
可以看到,數(shù)據(jù)基本落在置信區(qū)間里面,數(shù)據(jù)符合正態(tài)分布。
「使用Shapiro-Wilk」檢驗數(shù)據(jù)正態(tài)分布
> shapiro.test(dat$yield)
Shapiro-Wilk normality test
data: dat$yield
W = 0.97884, p-value = 0.8735
可以看到,P值為0.8735,數(shù)據(jù)符合正態(tài)分布,與上圖顯示的結(jié)果一致。
10. 齊性檢驗
方差分析中,我們對結(jié)果是否自信,在于數(shù)據(jù)是否滿足假定條件,方差分析的假定條件包括數(shù)據(jù)正態(tài)性
,數(shù)據(jù)的方差齊性
,數(shù)據(jù)的獨(dú)立性
,其中可以檢驗的假定有:
這里,我們介紹如何對數(shù)據(jù)的齊性進(jìn)行檢驗。齊性檢驗,是檢驗不同樣本的總體方差是否相同,是根據(jù)特定的模型,需要考慮不同的因子放到模型中,不能單獨(dú)對某一列變量進(jìn)行齊性檢驗。
「齊性檢驗:」
「數(shù)據(jù)描述:」
?A classical N, P, K (nitrogen, phosphate, potassium) factorial experiment on the growth of peas conducted on 6 blocks. Each half of a fractional factorial design confounding the NPK interaction was used on 3 of the plots.
?
data(npk)
dat <- npk
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 24 obs. of 5 variables:
$ block: Factor w/ 6 levels "1","2","3","4",..: 1 1 1 1 2 2 2 2 3 3 ...
$ N : Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 1 1 2 ...
$ P : Factor w/ 2 levels "0","1": 2 2 1 1 1 2 1 2 2 2 ...
$ K : Factor w/ 2 levels "0","1": 2 1 1 2 1 2 2 1 1 2 ...
$ yield: num 49.5 62.8 46.8 57 59.8 58.5 55.5 56 62.8 55.8 ...
比如上面數(shù)據(jù)中,相對N進(jìn)行單因素方差分析,查看不同N的水平是否滿足方差齊性,可以這樣操作:
「Bartlett檢驗」
Bartlett檢驗可以比較多個總體的方差
bartlett.test(yield ~ N,data=dat)
結(jié)果:
> bartlett.test(yield ~ N,data=dat)
Bartlett test of homogeneity of variances
data: yield by N
Bartlett's K-squared = 0.057652, df = 1, p-value = 0.8102
結(jié)果可以看出,不同的N之間,方差滿足齊性要求。
「Levene檢驗」
Bartlett檢驗對數(shù)據(jù)的正態(tài)性非常敏感,而Levene檢驗是一種非參數(shù)檢驗方法,使用范圍更廣。
library(car)
leveneTest(yield ~ N, data=dat)
結(jié)果:
> leveneTest(yield ~ N, data=dat)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 1 0.0054 0.9421
22
結(jié)果可以看出,P值為0.9421,大于0.05,說明數(shù)據(jù)符合方差齊性。
11. 多重比較
這里,我們介紹一下方差分析中的多重比較方法。
「agricolae包」
?This package contains functionality for the Statistical Analysis of experimental designs applied specially for field experiments in agriculture and plant breeding.
?
「多重比較方法:」
「數(shù)據(jù)描述:」
?A classical N, P, K (nitrogen, phosphate, potassium) factorial experiment on the growth of peas conducted on 6 blocks. Each half of a fractional factorial design confounding the NPK interaction was used on 3 of the plots.
?
data(npk)
dat <- npk
str(dat)
「數(shù)據(jù)結(jié)構(gòu):」
> str(dat)
'data.frame': 24 obs. of 5 variables:
$ block: Factor w/ 6 levels "1","2","3","4",..: 1 1 1 1 2 2 2 2 3 3 ...
$ N : Factor w/ 2 levels "0","1": 1 2 1 2 2 2 1 1 1 2 ...
$ P : Factor w/ 2 levels "0","1": 2 2 1 1 1 2 1 2 2 2 ...
$ K : Factor w/ 2 levels "0","1": 2 1 1 2 1 2 2 1 1 2 ...
$ yield: num 49.5 62.8 46.8 57 59.8 58.5 55.5 56 62.8 55.8 ...
「方差分析」這里對N進(jìn)行單因素方差分析,block為區(qū)組:
> m9 = aov(yield ~ block + N, data=dat)
> summary(m9)
Df Sum Sq Mean Sq F value Pr(>F)
block 5 343.3 68.66 3.395 0.0262 *
N 1 189.3 189.28 9.360 0.0071 **
Residuals 17 343.8 20.22
---
Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
結(jié)果可以看到,N因素達(dá)到極顯著水平
11.1 LSD多重比較
?Multiple comparisons of treatments by means of LSD and a grouping of treatments. The level by alpha default is 0.05. Returns p-values adjusted using one of several methods
?
# LSD
re1 = LSD.test(m9,"N")
re1$groups
結(jié)果:
> re1 = LSD.test(m9,"N")
> re1$groups
yield groups
1 57.68333 a
0 52.06667 b
11.2 scheffe多重比較
?Scheffe 1959, method is very general in that all possible contrasts can be tested for significance and confidence intervals can be constructed for the corresponding linear. The test is conservative.
?
代碼:
(scheffe.test(m9,"N"))
結(jié)果
> (scheffe.test(m9,"N"))
$statistics
MSerror Df F Mean CV Scheffe CriticalDifference
20.22284 17 4.451322 54.875 8.194955 2.109816 3.873379
$parameters
test name.t ntr alpha
Scheffe N 2 0.05
$means
yield std r Min Max Q25 Q50 Q75
0 52.06667 5.377957 12 44.2 62.8 48.30 52.35 55.625
1 57.68333 5.791347 12 48.8 69.5 54.85 57.85 60.350
$comparison
NULL
$groups
yield groups
1 57.68333 a
0 52.06667 b
11.3 Tukey多重比較
?It makes multiple comparisons of treatments by means of Tukey. The level by alpha default is 0.05.
?
代碼:
# Turkey
(HSD.test(m9,"N"))
結(jié)果
> (HSD.test(m9,"N"))
$statistics
MSerror Df Mean CV MSD
20.22284 17 54.875 8.194955 3.873379
$parameters
test name.t ntr StudentizedRange alpha
Tukey N 2 2.98373 0.05
$means
yield std r Min Max Q25 Q50 Q75
0 52.06667 5.377957 12 44.2 62.8 48.30 52.35 55.625
1 57.68333 5.791347 12 48.8 69.5 54.85 57.85 60.350
$comparison
NULL
$groups
yield groups
1 57.68333 a
0 52.06667 b
11.4 SNK多重比較
?SNK is derived from Tukey, but it is less conservative (finds more differences). Tukey controls the error for all comparisons, where SNK only controls for comparisons under consideration. The level by alpha default is 0.05.
?
代碼:
# SNK
(SNK.test(m9,"N"))
結(jié)果
> (HSD.test(m9,"N"))
$statistics
MSerror Df Mean CV MSD
20.22284 17 54.875 8.194955 3.873379
$parameters
test name.t ntr StudentizedRange alpha
Tukey N 2 2.98373 0.05
$means
yield std r Min Max Q25 Q50 Q75
0 52.06667 5.377957 12 44.2 62.8 48.30 52.35 55.625
1 57.68333 5.791347 12 48.8 69.5 54.85 57.85 60.350
$comparison
NULL
$groups
yield groups
1 57.68333 a
0 52.06667 b
11.5 Duncan多重比較
?This test is adapted from the Newman-Keuls method. Duncan's test does not control family wise error rate at the specified alpha level. It has more power than the other post tests, but only because it doesn't control the error rate properly. The Experimentwise Error Rate at: 1-(1-alpha)^(a-1); where "a" is the number of means and is the Per-Comparison Error Rate. Duncan's procedure is only very slightly more conservative than LSD. The level by alpha default is 0.05.
?
代碼:
# Duncan
(duncan.test(m9,"N"))
結(jié)果
> (duncan.test(m9,"N"))
$statistics
MSerror Df Mean CV
20.22284 17 54.875 8.194955
$parameters
test name.t ntr alpha
Duncan N 2 0.05
$duncan
Table CriticalRange
2 2.98373 3.873379
$means
yield std r Min Max Q25 Q50 Q75
0 52.06667 5.377957 12 44.2 62.8 48.30 52.35 55.625
1 57.68333 5.791347 12 48.8 69.5 54.85 57.85 60.350
$comparison
NULL
$groups
yield groups
1 57.68333 a
0 52.06667 b
12. 獲得所有代碼及注釋腳本