#匯入資料、檢視資料
dta <- ToothGrowth
dim(dta)
## [1] 60 3
str(dta)
## 'data.frame': 60 obs. of 3 variables:
## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
## $ dose: num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
aggregate(len ~ supp, mean, data=dta)
## supp len
## 1 OJ 20.66333
## 2 VC 16.96333
lattice::bwplot(len ~ supp, data=dta,
main="boxplot of length at different supplements",
xlab="Supplement (OJ & VC)", ylab="Length")
t.test(len ~ supp, data = dta)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1710156 7.5710156
## sample estimates:
## mean in group OJ mean in group VC
## 20.66333 16.96333
由於P值=0.06>0.05 ,故使用不同維他命的兩組,沒有達到統計上顯著差異。
with(dta, lattice::histogram(~ len | supp, type="density", xlab="Supplement"))