《R语言与统计分析第五章习题答案(7页).doc》由会员分享,可在线阅读,更多相关《R语言与统计分析第五章习题答案(7页).doc(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-#5.1x-c(3,5,7,9,11,13,15,17,19,21)y-c(21,16,15,26,22,14,21,22,18,25)e=sum(x*y)/sum(y) #样本期望d=(sum(x*x*y)/sum(y)-e2 #样本方差a=(8*e+sqrt(64*e2-4*4*(4*e2-12*d)/8 #估计结果b=(8*e-sqrt(64*e2-4*4*(4*e2-12*d)/8ab#5.2x-c(0,1,2,3,4,5,6)y-c(17,20,10,2,1,0,0)e=2.718281828459 f-function()(e(-50*)*50)/(210*62*24) #似然函
2、数optimize(f,c(0,2),maximum=TRUE)#5.3x-c(482,493,457,471,510,446,435,418,394,469) #0.95置信区间t.test(x)$conf.intchisq.var.test-function(x,var,alpha,alternative=two.sided) options(digits=4) result-list() n-length(x) v-var(x) result$var-v chi2-(n-1)*v/var result$chi2-chi2 p-pchisq(chi2,n-1) result$p.value
3、-p if(alternative=less) result$p.value-pchaisq(chi2,n-1,lower.tail=F) else if (alternative=two.sider) result$p.value-2*min(pchaisq(chi2,n-1),pchaisq(chi2,n-1,lower.tail=F) result$conf.int-c( (n-1)*v/qchisq(alpha/2,df=n-1,lower.tail=F), (n-1)*v/qchisq(alpha/2,df=n-1,lower.tail=T) ) resultchisq.var.te
4、st(x,var(x),0.90,alternative=two.side)$conf.int #0.90置信区间#5.4x-c(25,28,23,26,29,22)y-c(28,23,30,35,21,27)chisq.var.test(x,var(x),0.95,alternative=two.side)$conf.int #卷烟A方差0.95置信区间chisq.var.test(y,var(y),0.95,alternative=two.side)$conf.int #卷烟B方差0.95置信区间#方法二 两方差比0.95的置信区间var.test(x,y)two.sample.ci-fu
5、nction(x,y,conf.level=0.95,sigma1,sigama2) #样本方差作为整体方差 options(digits=4) m=length(x) n=length(y) xbar=mean(x)-mean(y) alpha=1-conf.level zstar=qnorm(1-alpha/2)*(sigma1/m+sigma2/n)(1/2) xbar+c(-zstar,+zstar)sigma1-var(x)sigma2-var(y)two.sample.ci(x,y,conf.level=0.95,sigma1,sigma2)#5.5x-c(628,583,510,
6、554,612,523,530,615,573,603,334,564)y-c(535,433,398,470,567,480,498,560,503,426,338,547)two.sample.ci-function(x,y,conf.level=0.95,sigma1,sigama2) options(digits=4) m=length(x) n=length(y) xbar=mean(x)-mean(y) alpha=1-conf.level zstar=qnorm(1-alpha/2)*(sigma1/m+sigma2/n)(1/2) xbar+c(-zstar,+zstar)si
7、gma1=2140sigma2=3250a-two.sample.ci(x,y,conf.level=0.95,sigma1,sigma2)b-two.sample.ci(x,y,conf.level=0.90,sigma1,sigma2)a2 #置信水平为0.95的置信上限b1 #置信水平为0.90的置信下限#5.6x-c(15.2,14.5,15.5,14.8,15.1,15.6,14.7)y-c(15.2,15.0,14.8,15.2,15.0,14.9,15.1,14.8,15.3)var.test(x,y) #x方差与y方差的比值极大,说明x方差大于y方差#5.7prop.test(
8、224,400,conf.level=0.99,correct=TRUE)#5.8size.norm2-function(s,alpha,d,m) t0-qt(alpha/2,m,lower.tail=FALSE) n0-(t0*s/d)2 t1-qt(alpha/2,n0,lower.tail=FALSE) n10.5) n0-(qt(alpha/2,n1,lower.tail=FALSE)*s/d)2 n1-(qt(alpha/2,n0,lower.tail=FALSE)*s/d)2 n1size.norm2(10,0.05,2,100)#5.8size.bin-function(d,p,conf.level=0.95) alpha=1-conf.level (qnorm(1-alpha/2)/d)2*p*(1-p)size.bin(0.01,0.05,0.90)第 8 页-