R软件课后习题解第四章-

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

习题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,25)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(极大似然估计)(作业)解:设nxxx,,21为字样n,...,21的一组观测值,所以似然函数为nnxniixnexxxexxxxLLniii!!...!!),,;()(211211取对数,所以niiniixxnL11)!ln(ln)(ln求偏导,并令其等于0,01ln1niixnL解得,x^,所以的极大似然估计量为.x-rep(0:6,c(17,20,10,2,1,0,0))mean(x)[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.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:truemeanisnotequalto095percentconfidenceinterval:63.158571.6415sampleestimates:meanofx67.4因此,10名患者平均脉搏在95%的置信区间为[63.16,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.0004712alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval: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.equal=TRUE)##注意:如果方差相同,需要声明var.equal=TRUETwoSamplet-testdata:xandyt=1.198,df=7,p-value=0.2699alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-0.0019963510.006096351sampleestimates:meanofxmeanofy0.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.04229alternativehypothesis:trueratioofvariancesisnotequalto195percentconfidenceinterval:0.058452760.94743902sampleestimates:ratioofvariances0.2353305t.test(x,y)WelchTwoSamplet-testdata:xandyt=4.6287,df=13.014,p-value=0.0004712alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:7.35971320.240287sampleestimates:meanofxmeanofy140.6126.8所以所求置信区间为[7.359713,20.240287]习题4.9X-rep(0:6,c(7,10,12,8,3,2,0))t.test(X)OneSamplet-testdata:Xt=9.0895,df=41,p-value=2.238e-11alternativehypothesis:truemeanisnotequalto095percentconfidenceinterval:1.4815562.327968sampleestimates:meanofx1.904762所以估计值为1.904762,置信区间为[1.481556,2.327968]习题4.10(作业)X-c(1067,919,1196,785,1126,936,918,1156,920,948)t.test(X,alternative=greater)OneSamplet-testdata:Xt=23.9693,df=9,p-value=9.148e-10alternativehypothesis:truemeanisgreaterthan095percentconfidenceinterval:920.8443Infsampleestimates:meanofx997.1所以有95%的灯泡寿命在920.8443h以上.习题5.1x-c(220,188,162,230,145,160,238,188,247,113,126,245,164,231,256,183,190,158,224,175)t.test(x,mu=225)OneSamplet-testdata:xt=-3.4783,df=19,p-value=0.002516alternativehypothesis:truemeanisnotequalto22595percentconfidenceinterval:172.3827211.9173sampleestimates:meanofx192.15原假设:油漆工人的血小板计数与正常成年男子无差异。备择假设:油漆工人的血小板计数与正常成年男子有差异。p值小于0.05,拒绝原假设,认为油漆工人的血小板计数与正常成年男子有差异。上述检验是双边检验。也可采用单边检验。备择假设:油漆工人的血小板计数小于正常成年男子。t.test(x,mu=225,alternative=less)OneSamplet-testdata:xt=-3.4783,df=19,p-value=0.001258alternativehypothesis:truemeanislessthan22595percentconfidenceinterval:-Inf208.4806sampleestimates:meanofx192.15同样可得出油漆工人的血小板计数小于正常成年男子的结论。习题5.2x-c(1067,919,1196,785,1126,936,918,1156,920,948)pnorm(1000,mean(x),sd(x))[1]0.5087941x=1000的概率为0.509,故x大于1000的概率为0.491.要点:pnorm计算正态分布的分布函数。在R软件中,计算值均为下分位点。习题5.3A-c(113,120,138,120,100,118,138,123)B-c(138,116,125,136,110,132,130,110)t.test(A,B,paired=TRUE)Pairedt-testdata:AandBt=-0.6513,df=7,p-value=0.5357alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-15.6288918.878891sampleestimates:meanofthedifferences-3.375习题5.4(作业)(1)正态性W检验:x-c(-0.70,-5.60,2.00,2.80,0.70,3.50,4.00,5.80,7.10,-0.50,2.50,-1.60,1.70,3.00,0.40,4.50,4.60,2.50,6.00,-1.40)a-shapiro.test(x);aShapiro-Wilknormalitytestdata:xW=0.9699,p-value=0.7527y-c(3.70,6.50,5.00,5.20,0.80,0.20,0.60,3.40,6.60,-1.10,6.00,3.80,2.00,1.60,2.00,2.20,1.20,3.10,1.70,-2.00)b-shapiro.test(y);bShapiro-Wilknormalitytestdata:yW=0.971,p-value=0.7754Kolmogorov-Smirnor检验:(K-S检验)ks.test(x,pnorm,mean(x),sd(x))One-sampleKolmogorov-Smirnovtestdata:xD=0.1065,p-value=0.9771alternativehypothesis:two-sided警告信息:Inks.test(x,pnorm,mean(x),sd(x)):Kolmogorov-Smirnov检验里不应该有连结ks.test(y,pnorm,mean(y),sd(y))One-sampleKolmogorov-Smirnovtestdata:yD=0.1197,p-value=0.9368alternativehypothesis:two-sided警告信息:Inks.test(y,pnorm,mean(y),sd(y)):Kolmogorov-Smirnov检验里不应该有连结Pearson拟合优度卡方检验:对x有:sort(x)[1]-5.6-1.6-1.4-0.7-0.50.40.71.72.02.52.52.83.03.54.04.54.65.86.07.1x1-table(cut(x,br=c(-6,-3,0,3,6,9)))p-pnorm(c(-3,0,3,6,9),mean(x),

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功