R软件计算题-统计学专业.ppt

上传人:小飞机 文档编号:5447061 上传时间:2023-07-08 格式:PPT 页数:25 大小:218.49KB
返回 下载 相关 举报
R软件计算题-统计学专业.ppt_第1页
第1页 / 共25页
R软件计算题-统计学专业.ppt_第2页
第2页 / 共25页
R软件计算题-统计学专业.ppt_第3页
第3页 / 共25页
R软件计算题-统计学专业.ppt_第4页
第4页 / 共25页
R软件计算题-统计学专业.ppt_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《R软件计算题-统计学专业.ppt》由会员分享,可在线阅读,更多相关《R软件计算题-统计学专业.ppt(25页珍藏版)》请在三一办公上搜索。

1、例4.15 P179(一个正态总体的区间估计)为估计一件物体的重量a,将其称了10次,得到的重量(单位:kg)为10.1,10,9.8,10.5,9.7,10.1,9.9,10.2,10.3,9.9,假设所称出物体重量服从正态分布求该物体重量a的置信系数为0.95的置信区间。,x-c(10.1,10,9.8,10.5,9.7,10.1,9.9,10.2,10.3,9.9)t.test(x)程序结果:One Sample t-testdata:xt=131.59,df=9,p-value=4.296e-16alternative hypothesis:true mean is not equal

2、 to 095 percent confidence interval:9.877225 10.222775sample estimates:mean of x 10.05 得到的区间估计为:9.88,10.22,例4.18 P185(均值差的区间估计)现从生产线上随机抽取样本x1,x2,x12和y1,y2,y17,都服从正态分布,其均值分别为u1=201.1,u2=499.7,标准差分别为2.4,4.7。给定置信系数0.95,试求u1-u2的区间估计。,x-rnorm(12,501.1,2.4)y-rnorm(17,499.7,4.7)两样本方差不同t.test(x,y)程序结果:Welch

3、 Two Sample t-testdata:x and yt=-0.6471,df=25.304,p-value=0.5234alternative hypothesis:true difference in means is not equal to 095 percent confidence interval:-3.657121 1.907620sample estimates:mean of x mean of y 500.7888 501.6635u1-u2的置信系数为0.95的区间估计为-3.66,1.91方差相同t.test(x,y,var.equal=TRUE),例4.19

4、P186(配对数据情形下均值差的区间估计)抽查患者10名。记录下治疗前后血红蛋白的含量数据。试求治疗前后变化的区间估计。(a=0.05)。,x-c(11.3,15.0,15.0,13.5,12.8,10.0,11.0,12.0,13.0,12.3)y-c(14.0,13.8,14.0,13.5,13.5,12.0,14.7,11.4,13.8,12.0)t.test(x-y)程序结果:One Sample t-testdata:x-yt=-1.3066,df=9,p-value=0.2237alternative hypothesis:true mean is not equal to 095

5、 percent confidence interval:-1.8572881 0.4972881sample estimates:mean of x-0.68治疗前后变化的区间估计为-1.86,0.497,例4.22 P193(一个总体求均值的单侧置信区间估计)从一批灯泡中随机地取5只作寿命试验测得寿命以小时计为 1050 1100 1120 1250 1280 设灯泡的寿命服从正态分布.求灯泡寿命平均值的置信度为0.95的单侧置信下限,x-c(1050,1100,1120,1250,1280)t.test(x,alternative=greater)程序结果:One Sample t-te

6、stdata:xt=26.003,df=4,p-value=6.497e-06alternative hypothesis:true mean is greater than 095 percent confidence interval:1064.9 Infsample estimates:mean of x 116095%的灯泡寿命在1064.9小时以上,习题4.6 P201甲、乙两种稻种分布播种在10块试验田中,每块试验田甲、乙稻种各种一半,假设两稻种产量X,Y均服从正态分布,且方差相等,收获后10块试验田的产量如下所示(单位:千克)。求出两稻种产量的期望差u1-u2的置信区间(a=0.

7、05).,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,var.equal=T)程序结果 Two Sample t-testdata:x and yt=4.6287,df=18,p-value=0.0002087alternative hypothesis:true difference in means is not equal to 095 percent confidence interval:7.536261 20.063739samp

8、le estimates:mean of x mean of y 140.6 126.8 置信区间为7.536261,20.063739,习题4.7 甲、乙两组生产同种导线,现从甲组生产的导线中随机抽取4根,从乙组生产的导线中随机抽取5根,它们的电阻值分别为:甲:0.143,0.142,0.143,0.137;乙:0.140,0.142,0.136,0.138,0.140;假设两组电阻值分别服从正态分布,方差相同但未知,试求u1-u2的置信系数为0.95的区间估计。,x-c(0.143,0.142,0.143,0.137)y-c(0.140,0.142,0.136,0.138,0.140)a-

9、rnorm(4,mean(x),var(x)b-rnorm(5,mean(y),var(y)t.test(a,b)程序结果:Welch Two Sample t-testdata:a and bt=636.28,df=5.788,p-value=3.028e-15alternative hypothesis:true difference in means is not equal to 095 percent confidence interval:0.002041440 0.002057343sample estimates:mean of x mean of y 0.1412494 0.

10、1392000区间为:0.00204,0.00205,例5.2 P209(单个正态总体均值的假设检验)某种元件的寿命X(小时),服从正态分布,其中f方差和均值均未知,16只元件的寿命如下:问是否有理由认为元件的平均寿命大于255小时。,x-c(159,280,101,212,224,379,179,264,222,362,168,250,149,260,485,170)t.test(x,alternative=greater,mu=225)程序结果:One Sample t-testdata:xt=0.66852,df=15,p-value=0.257alternative hypothesi

11、s:true mean is greater than 22595 percent confidence interval:198.2321 Infsample estimates:mean of x 241.5计算出P值为0.257大于0.05,所以,接受原假设,即认为元件的平均寿命不大于255小时,例5.6 P221(二项分布总体的假设检验)有一批蔬菜种子的平均发芽率为P=0.85,现在随机抽取500粒,用种衣剂进行浸种处理,结果有445粒发芽,问种衣剂有无效果。,binom.test(445,500,p=0.85)程序结果:Exact binomial testdata:445 and

12、500number of successes=445,number of trials=500,p-value=0.01207alternative hypothesis:true probability of success is not equal to 0.8595 percent confidence interval:0.8592342 0.9160509sample estimates:probability of success 0.89 P值=0.012070.05,拒绝原假设,认为种衣剂对种子发芽率有显著效果。,习题5.1 P249正常男子血小板计数均值为225*109/L,

13、今测得20名男性油漆作业工人的血小板计数值如下。问油漆工人的血小板计数与正常成年男子有无差异?,x-c(220,188,162,230,145,160,237,188,247,113,126,245,164,231,250,183,190,158,224,175)t.test(x,alternative=two.side,mu=225)程序结果:One Sample t-testdata:xt=-3.5588,df=19,p-value=0.002096alternative hypothesis:true mean is not equal to 22595 percent confiden

14、ce interval:172.2743 211.3257sample estimates:mean of x 191.8P值=0.0020960.05,拒绝原假设,认为油漆工人的血小板计数与正常成年男子有差异。,习题5.3为研究某铁剂治疗和饮食治疗营养性缺铁性贫血的效果,将16名患者按年龄、体重、病程和病情相近的原则配成8对,分别使用饮食疗法和补充铁剂治疗的方法,三个月后测得两种患者血红蛋白如表5.1所示,问两种方法治疗后的患者血红蛋白有无差异.,x0.05,接受原假设,两种方法治疗后的患者血红蛋白无差异,例6.2 P257(回归方程的显著性检验)求例6.1的回归方程,并对相应的方程做检验。

15、,x-c(0.1,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.20,0.21,0.23)y-c(42.0,43.5,45.0,45.5,45.0,47.5,49.0,53.0,50.0,55.0,55.0,60.0)lm.sol-lm(y1+x)summary(lm.sol)程序结果见下一张PPT回归方程为:从回归结果可以看出,回归方程通过了回归参数的检验与回归方程的检验。,例6.2的程序结果,程序结果:Call:lm(formula=y 1+x)Residuals:Min 1Q Median 3Q Max-2.0431-0.7056 0.1694 0.

16、6633 2.2653 Coefficients:Estimate Std.Error t value Pr(|t|)(Intercept)28.493 1.580 18.04 5.88e-09*x 130.835 9.683 13.51 9.50e-08*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:1.319 on 10 degrees of freedomMultiple R-squared:0.9481,Adjusted R-squared:0.9429 F-statistic:182.6 on 1 and 1

17、0 DF,p-value:9.505e-08,例6.4 P260(预测)求例6.1中X=x0=0.16时相应的Y的概率为0.95的预测区间,new-data.frame(x=0.16)lm.pred-predict(lm.sol,new,interval=prediction,level=0.95)lm.pred程序结果:fit lwr upr 49.42639 46.36621 52.48657预测值为49.43,预测区间46.37,52.49,例6.5 P261(全面展示一元回归模型的计算过程)Forbes数据,X-matrix(c(194.5,20.79,1.3179,131.79,19

18、4.3,20.79,1.3179,131.79,197.9,22.40,1.3502,135.02,198.4,22.67,1.3555,135.55,199.4,23.15,1.3646,136.46,199.9,23.35,1.3683,136.83,200.9,23.89,1.3782,137.82,201.1,23.99,1.3800,138.00,201.4,24.02,1.3806,138.06,201.3,24.01,1.3805,138.05,203.6,25.14,1.4004,140.04,204.6,26.57,1.4244,142.44,209.5,28.49,1.45

19、47,145.47,208.6,27.76,1.4434,144.34,210.7,29.04,1.4630,146.30,211.9,29.88,1.4754,147.54,212.2,30.06,1.4780,147.80),ncol=4,byrow=T,dimnames=list(1:17,c(F,h,log,log100)forbes-data.frame(X)plot(forbes$F,forbes$log100)程序结果是出现散点图,lm.sol|t|)(Intercept)-42.13087 3.33895-12.62 2.17e-09*F 0.89546 0.01645 54.

20、45 2e-16*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:0.3789 on 15 degrees of freedomMultiple R-squared:0.995,Adjusted R-squared:0.9946 F-statistic:2965 on 1 and 15 DF,p-value:2.2e-16,abline(lm.sol)程序结果:得到散点图和相应的回归直线y.res|t|)(Intercept)-41.30180 1.00038-41.29 5.01e-16*F 0.89096 0.004

21、93 180.73 2e-16*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:0.1133 on 14 degrees of freedomMultiple R-squared:0.9996,Adjusted R-squared:0.9995 F-statistic:3.266e+04 on 1 and 14 DF,p-value:2.2e-16,例6.14 P292某公司为了研究产品的营销策略,对产品的销售情况进行了调查,设Y为某地区该产品的家庭人均购买量(单位:元),X为家庭收入(单位:元),表6.8给出了53个家

22、庭的数据。试通过这些数据建立Y与X的关系。,X-scan()679 292 1012 493 582 1156 997 2189 1097 20781818 1700 747 2030 1643 414 354 1276 745 435 540 874 1543 1029 710 1434 837 1748 1381 1428 1255 1777 370 2316 1130 463 770 724 808 790 783 406 1242 658 1746 468 1114 413 1787 35601495 2221 1526Y-scan()0.79 0.44 0.56 0.79 2.70

23、3.64 4.73 9.50 5.34 6.855.84 5.21 3.25 4.43 3.16 0.50 0.17 1.88 0.77 1.39 0.56 1.56 5.28 0.64 4.00 0.31 4.20 4.88 3.48 7.58 2.63 4.99 0.59 8.19 4.79 0.51 1.74 4.10 3.94 0.963.29 0.44 3.24 2.14 5.71 0.64 1.90 0.51 8.33 14.945.11 3.85 3.93,lm.sol|t|)(Intercept)-0.8313037 0.4416121-1.882 0.0655.X 0.003

24、6828 0.0003339 11.030 4.11e-15*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:1.577 on 51 degrees of freedomMultiple R-squared:0.7046,Adjusted R-squared:0.6988 F-statistic:121.7 on 1 and 51 DF,p-value:4.106e-15y.rst-rstandard(lm.sol);y.fit-predict(lm.sol)plot(y.rsty.fit)abline(0.1,0.5)

25、;abline(-0.1,-0.5)程序结果:画出了标准化后的残差图,lm.new|t|)(Intercept)5.822e-01 1.299e-01 4.481 4.22e-05*X 9.529e-04 9.824e-05 9.699 3.61e-13*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:0.464 on 51 degrees of freedomMultiple R-squared:0.6485,Adjusted R-squared:0.6416 F-statistic:94.08 on 1 and 51

26、 DF,p-value:3.614e-13yn.rst-rstandard(lm.new);yn.fit-predict(lm.new)plot(yn.rstyn.fit),习题6.1 P331为估计山上积雪融化后对下游灌溉的影响,在山上建立一个观测站,测量最大积雪深度X(米)与当年灌溉面积Y(公颂),测得连续10年的数据如表6.1所示。,snow|t|)x 385.51 5.09 75.74 6.17e-14*-Signif.codes:0*0.001*0.01*0.05.0.1 1Residual standard error:104.6 on 9 degrees of freedomMu

27、ltiple R-squared:0.9984,Adjusted R-squared:0.9983 F-statistic:5736 on 1 and 9 DF,p-value:6.169e-14,现测得今年的数据是X=7m,给出今年灌溉面积的预测值与相应的区间估计。(a=0.05),4)X-data.frame(x=7)lm.pred-predict(lm.sol,X,interval=prediction,level=0.95)lm.pred#拟合新数据,并生成置信区间程序结果:fit lwr upr 1 2698.603 2448.718 2948.488,例7.2 P339(方差分析表

28、的计算)(续例7.1),lampF)A 3 49212 16404 2.166 0.121Residuals 22 166622 7574,例7.3 P341小白鼠在接种了3种不同菌型的伤寒杆菌后的存活天数如表所示,判断小白鼠被注射3种菌型后的平均存活天数有无显著差异?,mouseF)A 2 94.26 47.13 8.484 0.0012*Residuals 30 166.65 5.56-Signif.codes:0*0.001*0.01*0.05.0.1 1 P值远小于0.01应拒绝原假设,即认为小白鼠被注射3种菌型后的平均存活天数有显著差异,习题7.1 P3713个工厂生产同一种零件。现

29、从各厂产品中选取4件产品做检测,其检测程度如表所示:,lampF)A 2 1304 652.0 4.923 0.0359*Residuals 9 1192 132.4-Signif.codes:0*0.001*0.01*0.05.0.1 1P值大于0.01,接受原假设。没有显著差异,(2)对每个工厂生产的产品零件强度的均值,作出相应的区间估计,甲的区间估计a-c(115,116,98,83)t.test(a)程序结果:One Sample t-testdata:at=13.134,df=3,p-value=0.0009534alternative hypothesis:true mean is not equal to 095 percent confidence interval:78.04264 127.95736sample estimates:mean of x 103均值为103,区间估计为(78.04264,127.9574)同理,乙的均值为111,区间估计为(99.59932,122.4007)3)多重t检验attach(lamp)pairwise.t.test(X,A,p.adjust.method=none),

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号