Page 12. Example
wt <-c(13.9, 10.8,13.9, 9.3,11.7,9.1,12.0,10.4,13.3,11.1)
wt
## [1] 13.9 10.8 13.9 9.3 11.7 9.1 12.0 10.4 13.3 11.1
n <-length(wt)
n
## [1] 10
wt_mean <- mean(wt)
wt_mean
## [1] 11.55
wt_S2 <-sum((wt-wt_mean)^2)/(n-1)
wt_S2
## [1] 3.053889
T <-sqrt(n)*(wt_mean-10)/sqrt(wt_S2)
T
## [1] 2.804821
p_value_ts <-2*(1-pt(T,(n-1)))
t.test(wt, mu=10)
##
## One Sample t-test
##
## data: wt
## t = 2.8048, df = 9, p-value = 0.02055
## alternative hypothesis: true mean is not equal to 10
## 95 percent confidence interval:
## 10.29989 12.80011
## sample estimates:
## mean of x
## 11.55
p_value_ts <-(1-pt(T,(n-1)))
t.test(wt, mu=10, alternative="greater")
##
## One Sample t-test
##
## data: wt
## t = 2.8048, df = 9, p-value = 0.01028
## alternative hypothesis: true mean is greater than 10
## 95 percent confidence interval:
## 10.53699 Inf
## sample estimates:
## mean of x
## 11.55
Page 14. Example
w1 <-c( 13.9, 10.8, 13.9, 9.3, 11.7, 9.1, 12.0, 10.4, 13.3, 11.1)
w2 <-c(14.1, 10.7, 13.2, 10.4, 10.0, 10.1, 10.6, 12.5, 14.5, 10.9)
n1<-length(w1)
n2<-length(w2)
w1
## [1] 13.9 10.8 13.9 9.3 11.7 9.1 12.0 10.4 13.3 11.1
w2
## [1] 14.1 10.7 13.2 10.4 10.0 10.1 10.6 12.5 14.5 10.9
n1
## [1] 10
n2
## [1] 10
S1_2<-sum((w1-mean(w1))^2)/(n1-1)
S2_2<-sum((w2-mean(w2))^2)/(n2-1)
Sp_2<-((n1-1)*S1_2+(n2-1)*S2_2)/(n1+n2-2)
T <- (mean(w1)-mean(w2))/(sqrt(Sp_2)*sqrt(1/n1+1/n2))
T
## [1] -0.193712
p_2_value <-2*(1-pt(abs(T),(n1+n2-2)))
p_2_value
## [1] 0.8485707
t.test(w1,w2)
##
## Welch Two Sample t-test
##
## data: w1 and w2
## t = -0.19371, df = 17.994, p-value = 0.8486
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.77688 1.47688
## sample estimates:
## mean of x mean of y
## 11.55 11.70
t.test(w1,w2,paired=TRUE)
##
## Paired t-test
##
## data: w1 and w2
## t = -0.39071, df = 9, p-value = 0.7051
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.0184707 0.7184707
## sample estimates:
## mean of the differences
## -0.15