资源描述:
《生统答案homework3单样本t版本.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Homework3BirthWeight<-c(123,98,115,120,105,135,126,119,141,116,132,140,106,128,112,109,131,121,108,115)ID<-c(1:20)n<-20Table<-data.frame(ID,BirthWeight)head(Table,4)##IDBirthWeight##11123##2298##33115##44120χ2=(n-1)s2σ2p=pχn-12(χ2)chi<-((n-1)*var(Tabl
2、e$BirthWeight))/25^2min(pchisq(chi,n-1),1-pchisq(chi,n-1))*2##[1]0.0004309117Becausep=4.310^{-4}<0.05,thestandarddeviationofthesampleisdifferentfromthenational-wideone.Q1.P(100.0≤μ<126.0)=P(μ<126.0)-P(μ<100.0)=ptn-1(126-Xs/n)-ptn-1(126-Xs/n)mu<-mean(T
3、able$BirthWeight)s<-sd(Table$BirthWeight)p.upper<-pt((126.0-mu)/(s/sqrt(n)),n-1)p.lower<-pt((100.0-mu)/(s/sqrt(n)),n-1)p<-p.upper-p.lowerp##[1]0.9811361Sotheprobabilitythatthemeanbirthweightofthesamplefallsbetween100.0and126.0is0.981.Q2.CI=[X-tα/2(n-1
4、)sn,X+tα/2(n-1)sn]CI<-mu-c(-1,1)*qt(0.025,n-1)*s/sqrt(n)CI##[1]114.3777125.6223Sothe95%confidenceintervalofthesamplemeanis[114.378,125.622].Q3.t=X-μ0s/np=1-ptn-1(t)t<-(mu-118)/s*sqrt(n)p<-1-pt(t,n-1)p##[1]0.2328299Sothehypothesisthattheunderlyingmeanb
5、irthweightfromthishospitalishigherthanthenationalaverageisFALSE.Q4.p=2×min(ptn-1(X-μ0s/n),1-ptn-1(X-μ0s/n))p<-2*min(pt((mu-118)/s*sqrt(n),n-1),1-pt((mu-118)/s*sqrt(n),n-1))p##[1]0.4656597Thehypothesisthatthemeanbirthweightofsamplesize20isdifferentfrom
6、thenationalaverageisFALSE.Q5.Power=F[tα/2+
7、X-μ0
8、s/n]power<-pt(qt(0.05/2,n-1)+abs(mu-118)/s*sqrt(n),n-1)power##[1]0.09667934Thepowerofthetestperformedin(4)withsignificancelevel0.05is0.0967.Q6.•Method1:Usingpwrpackagelibrary(pwr)pwr.t.test(d=abs(mu-118)
9、/s,sig.level=0.01,power=1-0.05,type="one.sample",alternative="two.sided")####One-samplettestpowercalculation####n=646.0381##d=0.1664842##sig.level=0.01##power=0.95##alternative=two.sided•Method2:UsingNormalDistributionforapproximation.n=(z1-β+z1-α/2)2
10、s2(X-μ0)2(qnorm(1-0.05)+qnorm(1-0.01/2))^2*s^2/(mu-118)^2##[1]642.7163