为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > 统计建模与r软件第八章答案

统计建模与r软件第八章答案

2023-03-21 6页 doc 19KB 16阅读

用户头像 个人认证

海冰

暂无简介

举报
统计建模与r软件第八章答案统计建模与r软件第八章答案【篇一:统计建模与r软件-第4~9章习题】x-c(0.1,0.2,0.9,0.8,0.7,0.7)n-length(x)a1-mean(x);m2-(n-1)/n*var(x)a1-1/(1-a1)-2;a1[1]0.3076923极大似然估计f-function(a2){sum(log(x))+n/(1+a2)}out-uniroot(f,c(0,1));a2-out$root;a2[1]0.2111824.2x-c(rep(5,365),rep(15,245),rep(25,150),rep(35...
统计建模与r软件第八章答案
统计建模与r软件第八章【篇一:统计建模与r软件-第4~9章习题】x-c(0.1,0.2,0.9,0.8,0.7,0.7)n-length(x)a1-mean(x);m2-(n-1)/n*var(x)a1-1/(1-a1)-2;a1[1]0.3076923极大似然估计f-function(a2){sum(log(x))+n/(1+a2)}out-uniroot(f,c(0,1));a2-out$root;a2[1]0.2111824.2x-c(rep(5,365),rep(15,245),rep(25,150),rep(35,100),rep(45,70),rep(55,45),rep(65,25))lamda-length(x)/sum(x);lamda[1]0.054.3取均值即可。x-c(rep(0,17),rep(1,20),rep(2,10),rep(3,2),rep(4,1))mean(x)[1]1平均为1个。4.4obj-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(fA2)}x0-c(0.5,-2)nlm(obj,x0)$minimum[1]48.98425$estimate[1]11.4127791-0.8968052$gradient[1]1.411401e-08-1.493206e-07$code[1]1$iterations[1]164.5x-c(54,67,68,78,70,66,67,70,65,69)t.test(x)#t.test()做单样本正态分布区间估计onesamplet-testdata:xt=35.947,df=9,p-value=4.938e-11alternativehypothesis:truemeanisnotequalto095percentconfidenceinterval:63.158571.6415sampleestimates:meanofx67.4平均脉搏点估计为67.4,95%区间估计为63.158571.6415。t・test(x,alternative=less,mu=72)#t.test()做单样本正态分布单侧区间估计onesamplet-testdata:xt=-2.4534,df=9,p-value=0.01828alternativehypothesis:truemeanislessthan7295percentconfidenceinterval:-inf70.83705sampleestimates:meanofx67.4p值小于0.05,拒绝原假设,平均脉搏低于常人。4.6x-c(140,137,136,140,145,148,140,135,144,141);x[1]140137136140145148140135144141y-c(135,118,115,140,128,131,130,115,131,125);y[1]135118115140128131130115131125t.test(x,y,var.equal=true)twosamplet-testdata:xandyt=4.6287,df=18,p-value=0.0002087alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:7.5362620.06374sampleestimates:meanofxmeanofy140.6126.8期望差的95%置信区间为7.5362620.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)twosamplet-testdata:xandyt=1.198,df=7,p-value=0.2699alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-0.0019963510.006096351sampleestimates:meanofxmeanofy0.141250.13920期望差的95%的区间估计为-0.0019963510.0060963514.8接4.6var.test(x,y)ftesttocomparetwovariancesdata:xandyf=0.2353,numdf=9,denomdf=9,p-value=0.04229alternativehypothesis:trueratioofvariancesisnotequalto195percentconfidenceinterval:0.058452760.94743902sampleestimates:ratioofvariances0.2353305var.test可做两样本方差比的估计。此结果可认为方差不等,因此,在4.6中,计算期望差时应该采取方差不等的参数。t.test(x,y)welchtwosamplet-testdata:xandyt=4.6287,df=13.014,p-value=0.0004712alternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:7.35971320.240287sampleestimates:meanofxmeanofy140.6126.8期望差的95%置信区间为7.35971320.240287。4.9x-c(rep(0,7),rep(1,10),rep(2,12),rep(3,8),rep(4,3),rep(5,2))n-length(x)tmp-sd(x)/sqrt(n)*qnorm(1-0.05/2)mean(x)[1]1.904762mean(x)-tmp;mean(x)+tmp[1]1.494041[1]2.315483平均呼唤次数为1.90.95的置信区间为1.49,2,324.10x-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.84435.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.15p值小于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.2pnorm(1000,mean(x),sd(x))[1]0.5087941x[1]1067919119678511269369181156920948pnorm(1000,mean(x),sd(x))[1]0.5087941结论:x=100O的概率为0・509,x大于1000的概率为0.491.a-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.628898.87889sampleestimates:meanofthedifferences-3.375p值大于0.05,接受原假设,即两种治疗方法无差异。5.4(1)正态性w检验:x-c(-0.7,-5.6,2,2.8,0.7,3.5,4,5.8,7.1,-0.5,2.5,-1.6,1.7,3,0.4,4.5,4.6,2.5,6,-1.4)y-c(3.7,6.5,5,5.2,0.8,0.2,0.6,3.4,6.6,-1.1,6,3.8,2,1.6,2,2.2,1.2,3.1,1.7,-2)shapiro.test(x)shapiro-wilknormalitytestdata:xw=0.9699,p-value=0.7527shapiro.test(y)shapiro-wilknormalitytestdata:y【篇二:统计建模与r软件课后习题答案2-5章】用薛毅编的《统计建模与r软件》吧,找不出更好的了……工作环境仍是linux。第二章答案:ex2.1x-c(1,2,3)y-c(4,5,6)e-c(1,1,1)z=2*x+y+ez1=crossprod(x,y)#z1为x1与x2的内积或者x%*%yz2=tcrossprod(x,y)#z1为x1与x2的外积或者x%o%yz;z1;z2要点:基本的列表赋值方法,内积和外积概念。内积为标量,外积为矩阵。ex2.2a-matrix(1:20,c(4,5));ab-matrix(1:20,ow=4,byrow=true);bc=a+b;c#不存在ab这种写法e=a*b;ef-a[1:3,1:3];fh-matrix(c(1,2,4,5),ow=1);h#h起过渡作用,不规则的数组下标g-b[,h];g要点:矩阵赋值方法。默认是byrow=false,数据按列放置。取出部分数据的方法。可以用数组作为数组的下标取出数组元素。ex2.3x-c(rep(1,times=5),rep(2,times=3),rep(3,times=4),rep(4,times=2));x#或者省略times=,如下面的形式x-c(rep(1,5),rep(2,3),rep(3,4),rep(4,2));x要点:rep()的。rep(a,b)即将a重复b次ex2.4n-5;h-array(0,dim=c(n,n))for(iin1:n){for(jin1:n){h[i,j]-1/(i+j1)}};hg-solve(h);g#求h的逆矩阵ev-eigen(h);ev#求h的特征值和特征向量要点:数组初始化;for循环的使用待解决:如何将很长的命令(如for循环)用几行打出来再执行?每次想换行的时候一按回车就执行了还没打完的命令...ex2.5studentdata-data.frame(name=c(zhangsan,lisi,wangwu,zhaoliu,dingyi),sex=c(f,m,f,m,f),age=c(14,15,16,14,15),height=c(156,165,157,162,159),weight=c(42,49,41.5,52,45.5));studentdata要点:数据框的使用待解决:ssh登陆linux服务器中文显示乱码。此处用英文代替。ex2.6write.table(studentdata,file=studentdata.txt)#把数据框studentdata在工作目录里输出,输出的文件名为studentdata.txt.studentdata_a-read.table(studentdata.txt);studentdata_a#以数据框的形式读取文档studentdata・txt,存入数据框studentdata_a中。write.csv(studentdata_a,studentdata.csv)#把数据框studentdata_a在工作目录里输出,输出的文件名为studentdata・csv,可用excel打开.要点:读写文件。read.table(file)write.table(rdata,file)read.csv(file)write.csv(rdata,file)外部文件,不论是待读入或是要写出的,命令中都得加双引号。ex2.7fun-function(n){if(n=0)list(fail=pleaseinputaintegerabove0!)else{repeat{if(n==1)breakelseif(n%%2==0){n-n/2}elsen-3*n+1}list(sucess!)}}在linux下新建一个r文件,输入上述代码,保存为2.7.r然后在当前目录下进入r环境,输入source(2・7・r),即打开了这个程序脚本。然后就可以执行函数了。输入fun(67),显示输入fun(-1),显示$fail[1]pleaseinputaintegerabove0!待解决:source(*.r)是可以理解为载入这个r文件吧?如何在r环境下关闭r文件呢?ok,自己写的第一个r程序~~第二章答案:ex2.1x-c(1,2,3)y-c(4,5,6)e-c(1,1,1)z=2*x+y+ez1=crossprod(x,y)#z1为x1与x2的内积或者x%*%yz2=tcrossprod(x,y)#z1为x1与x2的外积或者x%o%yz;z1;z2要点:基本的列表赋值方法,内积和外积概念。内积为标量,外积为矩阵。ex2.2a-matrix(1:20,c(4,5));ab-matrix(1:20,ow=4,byrow=true);bc=a+b;c#不存在ab这种写法e=a*b;ef-a[1:3,1:3];fh-matrix(c(1,2,4,5),ow=1);h#h起过渡作用,不规则的数组下标g-b[,h];g要点:矩阵赋值方法。默认是byrow=false,数据按列放置。取出部分数据的方法。可以用数组作为数组的下标取出数组元素。ex2.3x-c(rep(1,times=5),rep(2,times=3),rep(3,times=4),rep(4,times=2));x#或者省略times=,如下面的形式x-c(rep(1,5),rep(2,3),rep(3,4),rep(4,2));x要点:rep()的使用方法。rep(a,b)即将a重复b次ex2.4n-5;h-array(0,dim=c(n,n))for(iin1:n){for(jin1:n){h[i,j]-1/(i+j-1)}};hg-solve(h);g#求h的逆矩阵ev-eigen(h);ev#求h的特征值和特征向量要点:数组初始化;for循环的使用待解决:如何将很长的命令(如for循环)用几行打出来再执行?每次想换行的时候一按回车就执行了还没打完的命令...ex2.5studentdata-data.frame(name=c(zhangsan,lisi,wangwu,zhaoliu,dingyi),sex=c(f,m,f,m,f),age=c(14,15,16,14,15),height=c(156,165,157,162,159),weight=c(42,49,41.5,52,45.5));studentdata要点:数据框的使用待解决:ssh登陆linux服务器中文显示乱码。此处用英文代替。ex2.6write.table(studentdata,file=studentdata.txt)#把数据框studentdata在工作目录里输出,输出的文件名为studentdata.txt.studentdata_a-read.table(studentdata.txt);studentdata_a#以数据框的形式读取文档studentdata・txt,存入数据框studentdata_a中。write.csv(studentdata_a,studentdata.csv)#把数据框studentdata_a在工作目录里输出,输出的文件名为studentdata・csv,可用excel打开.要点:读写文件。read.table(file)write.table(rdata,file)read.csv(file)write.csv(rdata,file)外部文件,不论是待读入或是要写出的,命令中都得加双引号。ex2.7fun-function(n){if(n=0)list(fail=pleaseinputaintegerabove0!)else{repeat{if(n==1)breakelseif(n%%2==0){n-n/2}elsen-3*n+1}list(sucess!)}}在linux下新建一个r文件,输入上述代码,保存为2.7.r然后在当前目录下进入r环境,输入source(2・7・r),即打开了这个然后就可以执行函数了。输入fun(67),显示sucess!输入fun(-1),显示$fail[1]pleaseinputaintegerabove0!待解决:source(*.r)是可以理解为载入这个r文件吧?如何在r环境下关闭r文件呢?ex3.1新建txt文件如下:3.1.txt79.575.073.575.874.073.567.275.873.578.875.673.575.075.872.079.576.573.579.568.875.078.872.068.876.572.775.070.478.078.874.364.376.574.374.770.472.770.472.075.875.870.476.565.077.273.572.780.572.065.080.371.277.676.568.873.577.280.572.074.369.781.281.667.372.784.369.774.371.274.375.072.075.467.375.071.271.269.773.570.475.072.767.370.376.573.572.068.073.568.074.372.772.774.370.4编写一个函数(程序名为data_outline・r)描述样本的各种描述性统计量。data_outline-function(x){n-length(x)m-mean(x)v-var(x)s-sd(x)me-median(x)cv-100*s/mcss-sum((x・m)八2)uss-sum(xA2)r-max(x)-min(x)r1-quantile(x,3/4)-quantile(x,1/4)sm-s/sqrt(n)g1-n/((n-1)*(n-2))*sum((x-m)A3)/sA3g2-((n*(n+1))/((n-1)*(n-2)*(n-3))*s【篇三:统计建模与r软件#实验#】3月日开课学院、实验室:与统计学院实验时间:2013年3月日开课学院、实验室:数学与统计学院实验时间:2013年月日
/
本文档为【统计建模与r软件第八章答案】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索