作業題目:Please use the dataset (anova_data1.txt or anova_data1.csv) to run ANOVA and post-hoc testusing R and SAS.

資料匯入

dta<-read.csv("C:/Users/User/Desktop/LearnR/CA/CAdata/anova_data1.csv")
View(dta)

Analysis of Variance in R (ANOVA)

anova(lm(Score ~ Dosage, dta))
## Analysis of Variance Table
## 
## Response: Score
##           Df Sum Sq Mean Sq F value   Pr(>F)   
## Dosage     2 426.25  213.12  8.7887 0.002977 **
## Residuals 15 363.75   24.25                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Tukey事後比較

TukeyHSD(aov(Score ~ Dosage, data=dta))
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Score ~ Dosage, data = dta)
## 
## $Dosage
##       diff       lwr       upr     p adj
## b-a  -4.25 -11.15796  2.657961 0.2768132
## c-a -13.25 -21.50659 -4.993408 0.0022342
## c-b  -9.00 -16.83289 -1.167109 0.0237003

事後比較(bonferroni)

pairwise.t.test(dta$Score, dta$Dosage , p.adj= "bonf")
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  dta$Score and dta$Dosage 
## 
##   a      b     
## b 0.3926 -     
## c 0.0025 0.0278
## 
## P value adjustment method: bonferroni