




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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)$root1 0.$f.root1 -3.e-05$iter1 5$estim.prec1 6.e-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)$root1 0.$f.root1 -10.46586$
2、iter1 14$estim.prec1 6.e-05估计值为0.习题4.3(极大似然估计)(作业)解:设为字样的一组观测值,所以似然函数为取对数,所以 求偏导,并令其等于0,解得,所以的极大似然估计量为.x-rep(0:6,c(17,20,10,2,1,0,0)mean(x)1 1习题4.4y-function(x)f-c(-13+x1+(5-x2)*x2-2)*x2,-29+x1+(x2+1)*x2-14)*x2);sum(f2)x0-c(0.5,-2)nlm(y,x0)$minimum1 48.98425$estimate1 11. -0.$gradient1 1.e-08 -1.e-0
3、7$code1 1$iterations1 16习题4.5X- c(54,67,68,78,70,66,67,70,65,69)t.test(X) One Sample t-testdata: X t = 35.947, df = 9, p-value = 4.938e-11alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: 63.1585 71.6415 sample estimates:mean of x 67.4因此,10名患者平均脉搏在95%的置信区间为63.16,71.
4、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) Welch Two Sample t-testdata: x and y t = 4.6287, df = 13.014, p-value = 0.alternative hypothesis: true difference in means is not equal to 0 95 perc
5、ent confidence interval: 7. 20. sample estimates:mean of x mean of y 140.6 126.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=TRUE Two Sample t-testdata: x and y t = 1.198, df = 7, p-value = 0.269
6、9alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0. 0. sample estimates:mean of x mean of y 0.14125 0.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) F test to compare two variance
7、sdata: x and y F = 0.2353, num df = 9, denom df = 9, p-value = 0.04229alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0. 0. sample estimates:ratio of variances 0. t.test(x,y) Welch Two Sample t-testdata: x and y t = 4.6287, df = 13.014, p-value = 0.a
8、lternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 7. 20. sample estimates:mean of x mean of y 140.6 126.8所以所求置信区间为7.,20.习题4.9X-rep(0:6,c(7,10,12,8,3,2,0)t.test(X) One Sample t-testdata: X t = 9.0895, df = 41, p-value = 2.238e-11alternative hypothesis:
9、true mean is not equal to 0 95 percent confidence interval: 1. 2. sample estimates:mean of x 1. 所以估计值为1.,置信区间为1.,2.习题4.10(作业)X-c(1067,919,1196,785,1126,936,918,1156,920,948)t.test(X,alternative=greater) One Sample t-testdata: X t = 23.9693, df = 9, p-value = 9.148e-10alternative hypothesis: true mea
10、n is greater than 0 95 percent confidence interval: 920.8443 Inf sample estimates:mean of x 997.1所以有95%的灯泡寿命在920.8443h以上.习题5.1 x-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) One Sample t-testdata: x t = -3.4783, df = 19, p-val
11、ue = 0.alternative hypothesis: true mean is not equal to 225 95 percent confidence interval: 172.3827 211.9173 sample estimates:mean of x 192.15原假设:油漆工人的血小板计数与正常成年男子无差异。备择假设:油漆工人的血小板计数与正常成年男子有差异。p值小于0.05,拒绝原假设,认为油漆工人的血小板计数与正常成年男子有差异。上述检验是双边检验。也可采用单边检验。备择假设:油漆工人的血小板计数小于正常成年男子。t.test(x,mu=225,alternat
12、ive=less) One Sample t-testdata: x t = -3.4783, df = 19, p-value = 0.alternative hypothesis: true mean is less than 225 95 percent confidence interval: -Inf 208.4806 sample estimates:mean of x 192.15同样可得出油漆工人的血小板计数小于正常成年男子的结论。习题5.2x-c(1067,919,1196,785,1126,936,918,1156,920,948)pnorm(1000,mean(x),sd
13、(x)1 0.x=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) Paired t-testdata: A and B t = -0.6513, df = 7, p-value = 0.5357alternative hypothesis: true difference in means is not eq
14、ual to 0 95 percent confidence interval: -15. 8. sample estimates:mean of the differences -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);a Shapiro-Wilk normality testdata: x W = 0.9699, p-value =
15、 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);b Shapiro-Wilk normality testdata: y W = 0.971, p-value = 0.7754Kolmogorov-Smirnor检验:(K-S检验)ks.test(x,pnorm,mean(x),sd(x) One-sample Kolmogorov-Smirnov testdata: x D = 0
16、.1065, p-value = 0.9771alternative hypothesis: two-sided 警告信息:In ks.test(x, pnorm, mean(x), sd(x) : Kolmogorov - Smirnov检验里不应该有连结ks.test(y,pnorm,mean(y),sd(y) One-sample Kolmogorov-Smirnov testdata: y D = 0.1197, p-value = 0.9368alternative hypothesis: two-sided 警告信息:In ks.test(y, pnorm, mean(y), sd
17、(y) : Kolmogorov - Smirnov检验里不应该有连结Pearson拟合优度卡方检验:对x有:sort(x) 1 -5.6 -1.6 -1.4 -0.7 -0.5 0.4 0.7 1.7 2.0 2.5 2.5 2.8 3.0 3.5 4.0 4.5 4.6 5.8 6.0 7.1x1-table(cut(x,br=c(-6,-3,0,3,6,9)p-pnorm(c(-3,0,3,6,9),mean(x),sd(x);p1 0. 0. 0. 0. 0.p-c(p1,p2-p1,p3-p2,p4-p3,1-p4);p1 0. 0. 0. 0. 0.chisq.test(x1,p=
18、p) Chi-squared test for given probabilitiesdata: x1 X-squared = 0.5639, df = 4, p-value = 0.967警告信息:In chisq.test(x1, p = p) : Chi-squared近似算法有可能不准对y有:对x有,p值为0.967,接受原假设,x符合正态分布。对y同理,所以,两组数据均为正态分布。(2)方差相同模型t检验: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.
19、60,2.50,6.00,-1.40)y-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)t.test(x,y,var.equal=TRUE) Two Sample t-testdata: x and y t = -0.6419, df = 38, p-value = 0.5248alternative hypothesis: true difference in means is not equal to 0 95 percent c
20、onfidence interval: -2. 1. sample estimates:mean of x mean of y 2.065 2.625 方差不同模型t检验: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)y-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
21、)t.test(x,y) Welch Two Sample t-testdata: x and y t = -0.6419, df = 36.086, p-value = 0.525alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -2.32926 1.20926 sample estimates:mean of x mean of y 2.065 2.625成对t检验:x-c(-0.70,-5.60,2.00,2.80,0.70,3.50,4.0
22、0,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)y-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)t.test(x,y,paired=TRUE) Paired t-testdata: x and y t = -0.6464, df = 19, p-value = 0.5257alternative hypothesis: true differ
23、ence in means is not equal to 0 95 percent confidence interval: -2. 1. sample estimates:mean of the differences -0.56以上P值均大于0.05,故均值无差异。(三种检验的结果都显示两组数据均值无差异。)(3)方差检验: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)y-c(3.70,6.50,5.00,5.20,0
24、.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)var.test(x,y) F test to compare two variancesdata: x and y F = 1.5984, num df = 19, denom df = 19, p-value = 0.3153alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0. 4.
25、sample estimates:ratio of variances 1.P值大于0.05,接受原假设,所以方差无差异。习题5.5(1)正态性检验,采用ks检验:a - c(126,125,136,128,123,138,142,116,110,108,115,140)b - c(162,172,177,170,175,152,157,159,160,162)ks.test(a,pnorm,mean(a),sd(a) One-sample Kolmogorov-Smirnov testdata: a D = 0.1464, p-value = 0.9266alternative hypoth
26、esis: two-sided ks.test(b,pnorm,mean(b),sd(b) One-sample Kolmogorov-Smirnov testdata: b D = 0.2222, p-value = 0.707alternative hypothesis: two-sided 警告信息:In ks.test(b, pnorm, mean(b), sd(b) : Kolmogorov - Smirnov检验里不应该有连结a和b都服从正态分布。(2)方差齐性检验:var.test(a,b) F test to compare two variancesdata: a and b
27、 F = 1.9646, num df = 11, denom df = 9, p-value = 0.32alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 0. 7. sample estimates:ratio of variances 1.可认为a和b的方差相同。(3)选用方差相同模型t检验:t.test(a,b,var.equal=TRUE) Two Sample t-testdata: a and b t = -8.8148, df = 2
28、0, p-value = 2.524e-08alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -48.24975 -29.78358 sample estimates:mean of x mean of y 125.5833 164.6000 可认为两者有差别。习题5.6(作业)直接调用binom.test()函数可得:binom.test(57, 400, p = 0.147) Exact binomial testdata: 57 and 40
29、0 number of successes = 57, number of trials = 400, p-value = 0.8876alternative hypothesis: true probability of success is not equal to 0.147 95 percent confidence interval: 0. 0. sample estimates:probability of success 0.1425 P值大于0.05,所以支持结果。习题5.7二项分布总体的假设检验:binom.test(178,328,p=0.5,alternative=gre
30、ater) Exact binomial testdata: 178 and 328 number of successes = 178, number of trials = 328, p-value = 0.06794alternative hypothesis: true probability of success is greater than 0.5 95 percent confidence interval: 0. 1. sample estimates:probability of success 0.不能认为这种处理能增加母鸡的比例。习题5.8利用pearson卡方检验是否
31、符合特定分布:chisq.test(c(315,101,108,32),p=c(9,3,3,1)/16) Chi-squared test for given probabilitiesdata: c(315, 101, 108, 32) X-squared = 0.47, df = 3, p-value = 0.9254接受原假设,符合自由组合定律。习题5.9(作业)X-0:5;Y-c(92,68,28,11,1,0)q-ppois(X,mean(rep(X,Y);n-length(Y);p-numeric(n)p1-q1;pn-1-qn-1for(i in 2:(n-1)pi-qi-qi-
32、1chisq.test(Y,p=p) Chi-squared test for given probabilitiesdata: Y X-squared = 2.1596, df = 5, p-value = 0.8267警告信息:In chisq.test(Y, p = p) : Chi-squared近似算法有可能不准以下是矫正后的结果:X-0:3;Z-c(92,68,28,12)q-ppois(X,mean(rep(X,Z);n-length(Z);p-numeric(n)p1-q1;pn-1-qn-1for(i in 2:(n-1)pi0.1,所以,可以认为每分钟顾客数X服从Poiss
33、on分布。习题5.10ks检验 两个分布是否相同:x-c(2.36,3.14,752,3.48,2.76,5.43,6.54,7.41)y-c(4.38,4.25,6.53,3.28,7.21,6.55)ks.test(x,y) Two-sample Kolmogorov-Smirnov testdata: x and y D = 0.375, p-value = 0.6374alternative hypothesis: two-sided 习题5.11列联数据的独立性检验:x- c(358,2492,229,2745)dim(x)-c(2,2)chisq.test(x) Pearsons
34、Chi-squared test with Yates continuity correctiondata: x X-squared = 37.4143, df = 1, p-value = 9.552e-10P 值0.05 ,拒绝原假设,有影响。习题5.12(作业)列联数据的独立性检验:x-c(45,46,28,11,12,20,23,12,10,28,30,35)dim(x)-c(4,3)chisq.test(x,correct = FALSE) Pearsons Chi-squared testdata: x X-squared = 40.401, df = 6, p-value = 3
35、.799e-07P值小于0.05,所以B与C不独立。习题5.13因有的格子的频数小于5,故采用fiser确切概率法检验独立性。x-c(3,6,4,4);dim(x)-c(2,2)fisher.test(x) Fishers Exact Test for Count Datadata: x p-value = 0.6372alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0. 5. sample estimates:odds ratio 0.p值大于0.05,两变量独
36、立,两种工艺对产品的质量没有影响。习题5.14由于是在相同个体上的两次试验,故采用McNemar检验。x-c(58,1,8,2,42,9,3,7,17);dim(x)=14.6;H1: 中位数14.6x14.6,length(x),al=l) Exact binomial testdata: sum(x) 14.6 and length(x) number of successes = 1, number of trials = 10, p-value = 0.01074alternative hypothesis: true probability of success is less th
37、an 0.5 95 percent confidence interval: 0. 0. sample estimates:probability of success 0.1拒绝原假设,中位数小于14.6(2)Wilcoxon符号秩检验:wilcox.test(x,mu=14.6,al=l,exact=F) Wilcoxon signed rank test with continuity correctiondata: x V = 4.5, p-value = 0.01087alternative hypothesis: true location is less than 14.6 拒绝
38、原假设,中位数小于14.6习题5.16(作业)(1)采用成对符号检验,输入数据,调用binom.test()作检验:x-c(48.0,33.0,37.5,48.0,42.5,40.0,42.0,36.0,11.3,22.0,36.0,27.3,14.2,32.1,52.0,38.0,17.3,20.0,21.0,46.1)y-c(37.0,41.0,23.4,17.0,31.5,40.0,31.0,36.0,5.7,11.5,21.0,6.1,26.5,21.3,44.5,28.0,22.6,20.0,11.0,22.3)binom.test(sum(xy),length(x) Exact b
39、inomial testdata: sum(x y) and length(x) number of successes = 3, number of trials = 20, p-value = 0.alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0. 0. sample estimates:probability of success 0.15P值0.0.05,所以,2种方法有显著差异。(2)Wilcoxon符号秩检验:输入数据,调
40、用wilcox.test()函数:x-c(48.0,33.0,37.5,48.0,42.5,40.0,42.0,36.0,11.3,22.0,36.0,27.3,14.2,32.1,52.0,38.0,17.3,20.0,21.0,46.1)y-c(37.0,41.0,23.4,17.0,31.5,40.0,31.0,36.0,5.7,11.5,21.0,6.1,26.5,21.3,44.5,28.0,22.6,20.0,11.0,22.3)wilcox.test(x,y,alternative=greater,paired=TRUE) Wilcoxon signed rank test wi
41、th continuity correctiondata: x and y V = 136, p-value = 0.alternative hypothesis: true location shift is greater than 0 警告信息:1: In wilcox.test.default(x, y, alternative = greater, paired = TRUE) : 无法精確計算带连结的p值2: In wilcox.test.default(x, y, alternative = greater, paired = TRUE) : 有0时无法計算精確的p值P值0.0.
42、05,所以,2种方法有显著差异。(3)Wilcoxon秩和检验:输入数据,调用wilcox.test()函数:x-c(48.0,33.0,37.5,48.0,42.5,40.0,42.0,36.0,11.3,22.0,36.0,27.3,14.2,32.1,52.0,38.0,17.3,20.0,21.0,46.1)y0.05,所以,2种方法有显著差异。(4)正态性检验:ks.test(x,pnorm,mean(x),sd(x) One-sample Kolmogorov-Smirnov testdata: x D = 0.1407, p-value = 0.8235alternative hypothesis: two-sided 警告信息:In ks.test(x, pnorm, mean(x), sd(x) : Kolmogor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 3-3编码器1电子课件教学版
- 粮食仓储企业绿色税收政策考核试卷
- 玻璃管道生产考核试卷
- 油气仓储与能源安全风险管理体系构建策略研究考核试卷
- 残疾人座车内饰设计与材料选择考核试卷
- 游乐设施施工电气安全知识考核试卷
- 电气设备数字化设计与制造考核试卷
- 电机专利技术考核试卷
- 竹浆在纸品印刷适应性改进的技术研究考核试卷
- 纱线国际贸易的风险防范考核试卷
- 《花生膜下滴灌技术》课件
- 名片设计教程
- 森林消防员劳务派遣服务投标方案技术标
- 妇科学妇科感染病
- 《内科常见病的诊治》课件
- 离心泵有效汽蚀余量计算公式
- 第十一章计划调控法律制度
- 《我的家乡日喀则》课件
- 语文版一年级下册语文阅读理解(15篇)
- 华文版书法五年级下册 第12课 同字框 教案
- 国网装表接电(初级)理论考试复习题库(含答案)
评论
0/150
提交评论