5-1
q<-qnorm(0.975)
LCI<-120-q*(15/sqrt(49))
UCI<-120+q*(15/sqrt(49))
data.frame(LCI,UCI)
5-2
#5-2-1
q<-qnorm(0.95)
LCI<-8900-q*(500/sqrt(15))
UCI<-8900+q*(500/sqrt(15))
data.frame(LCI,UCI)
#5-2-2
q<-qnorm(0.975)
LCI<-8900-q*(500/sqrt(35))
UCL<-8900+q*(500/sqrt(35))
data.frame(LCI,UCI)
#5-2-3
q<-qnorm(0.90)
LCI<-8900-q*(510/sqrt(35))
UCI<-8900+q*(510/sqrt(35))
data.frame(LCI,UCI)
#5-2-4
q<-qnorm(0.975)
LCI<-8900-q*(510/sqrt(100))
UCI<-8900+q*(510/sqrt(100))
data.frame(LCI,UCI)
5-3
load("C:/exercise/ch5/exercise5_3.RData")
library(BSDA)
#90%
z.test(exercise5_3$涓婄綉鏃堕棿,mu=0,sigma.x=sd(exercise5_3$涓婄綉鏃堕棿),conf.level=0.90)
#95%
z.test(exercise5_3$涓婄綉鏃堕棿,mu=0,sigma.x=sd(exercise5_3$涓婄綉鏃堕棿),conf.level=0.95)
#99%
z.test(exercise5_3$涓婄綉鏃堕棿,mu=0,sigma.x=sd(exercise5_3$涓婄綉鏃堕棿),conf.level=0.99)
5-4
n<-500
x<-50
p<-x/n
q<-qnorm(0.975)
LCI<-p-q*sqrt(p*(1-p)/n)
UCI<-p+q*sqrt(p*(1-p)/n)
data.frame(LCI,UCI)
5-5
load("C:/exercise/ch5/exercise5_5.RData")
t.test(exercise5_5$鏂瑰紡1,paired=TRUE,conf.level=0.95)$conf.int
t.test(exercise5_5$鏂瑰紡2,paired=TRUE,conf.level=0.95)$conf.int
t.test(x=exercise5_5$鏂瑰紡1,y=exercise5_5$鏂瑰紡2,var.equal=TRUE)$conf.int
t.test(x=exercise5_5$鏂瑰紡1,y=exercise5_5$鏂瑰紡2,var.equal=FALSE)$conf.int
5-6
#5-6-1
q1<-qnorm(0.95)
p1<-((14-1)*96.8+(7-1)*102.0)/(14+7-2)
LCI<-(53.2-43.4)-q1*(14+7-2)*sqrt(sp1*(1/14+1/7))
UCI<-(53.2-43.4)+q1*(14+7-2)*sqrt(sp1*(1/14+1/7))
data.frame(LCI,UCI)
#5-6-2
q2<-qnorm(0.99)
p2<-((14-1)*96.8+(7-1)*102.0)/(14+7-2)
LCI<-(53.2-43.4)-q2*(14+7-2)*sqrt(sp2*(1/14+1/7))
UCI<-(53.2-43.4)-q2*(14+7-2)*sqrt(sp2*(1/14+1/7))
data.frame(LCI,UCI)
5-7
load("C:/exercise/ch5/exercise5_7.RData")
t.test(exercise5_7$鏂规硶1,exercise5_7$鏂规硶2,paired=TRUE)$conf.int
5-8
#5-8-1
n1=250
n2=250
p1=0.4
p2=0.3
q1<-qnorm(0.90)
LCI<-p1-p2-q1*sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2)
UCI<-p1-p2+q1*sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2)
data.frame(UCI,LCI)
#5-8-2
n1=250
n2=250
p1=0.4
p2=0.3
q2<-qnorm(0.95)
UCI<-p1-p2-q2*sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2)
LCI<-p1-p2+q2*sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2)
data.frame(LCI,UCI)
5-9
load("C:/exercise/ch5/exercise5_9.RData")
var.test(exercise5_9$鏈哄櫒1,exercise5_9$鏈哄櫒2,alternative="two.sided")$conf.int