资源描述:
《r软件后作业解四》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、习题4.1计算代码如下(极大似然估计):x<-c(0.1,0.2,0.9,0.8,0.7,0.7)n<-length(x)f<-function(a){n/(a+1)+sum(log(x))}uniroot(f,c(0,1))$root[1]0.211182$f.root[1]-3.844668e-05$iter[1]5$estim.prec[1]6.103516e-05习题4.2(指数分布)x<-c(5,15,25,35,45,55,65)v<-c(365,245,150,100,70,45,2
2、5)y<-x*vf<-function(k){1000/k-sum(y)}uniroot(f,c(0,100))$root[1]0.05002618$f.root[1]-10.46586$iter[1]14$estim.prec[1]6.103516e-05估计值为0.05002618习题4.3(极大似然估计)(作业)解:设为字样的一组观测值,所以似然函数为取对数,所以求偏导,并令其等于0,解得,,所以的极大似然估计量为.x<-rep(0:6,c(17,20,10,2,1,0,0))mean(x)
3、[1]1习题4.4y<-function(x){f<-c(-13+x[1]+((5-x[2])*x[2]-2)*x[2],-29+x[1]+((x[2]+1)*x[2]-14)*x[2]);sum(f^2)} 矚慫润厲钐瘗睞枥庑赖。x0<-c(0.5,-2)nlm(y,x0)$minimum[1]48.98425$estimate[1]11.4127791-0.8968052$gradient[1]1.415447e-08-1.435296e-07$code[1]1$iterations[1]16
4、习题4.5X<-c(54,67,68,78,70,66,67,70,65,69)t.test(X)OneSamplet-testdata:Xt=35.947,df=9,p-value=4.938e-11alternativehypothesis:truemeanisnotequalto0聞創沟燴鐺險爱氇谴净。95percentconfidenceinterval:63.158571.6415sampleestimates:meanofx67.4因此,10名患者平均脉搏在95%的置信区间为[63.1
5、6,71.64]10个人的平均脉搏为67.4,所以这10名患者的平均脉搏属不低于正常人的平均脉搏残骛楼諍锩瀨濟溆塹籟。习题4.6(作业)x<-c(140,137,136,140,145,148,140,135,144,141)y<-c(135,118,115,140,128,131,130,115,131,125)t.test(x,y)WelchTwoSamplet-testdata:xandyt=4.6287,df=13.014,p-value=0.0004712alternativehypot
6、hesis:truedifferenceinmeansisnotequalto0酽锕极額閉镇桧猪訣锥。95percentconfidenceinterval:7.35971320.240287sampleestimates:meanofxmeanofy140.6126.8所以u1-u2的置信区间为[7.53626,20.06374]习题4.7x<-c(0.143,0.142,0.143,0.137)y<-c(0.140,0.142,0.136,0.138,0.140)t.test(x,y,var.
7、equal=TRUE)##注意:如果方差相同,需要声明var.equal=TRUE彈贸摄尔霁毙攬砖卤庑。TwoSamplet-testdata:xandyt=1.198,df=7,p-value=0.2699alternativehypothesis:truedifferenceinmeansisnotequalto0謀荞抟箧飆鐸怼类蒋薔。95percentconfidenceinterval:-0.0019963510.006096351sampleestimates:meanofxmeanof
8、y0.141250.13920习题4.8(作业)x<-c(140,137,136,140,145,148,140,135,144,141)y<-c(135,118,115,140,128,131,130,115,131,125)var.test(x,y)Ftesttocomparetwovariancesdata:xandyF=0.2353,numdf=9,denomdf=9,p-value=0.04229厦礴恳蹒骈時盡继價骚。alternativehypothesis:truer