1、P37.例 2.1build.price 例 2.4 p p1 t;t11 131 15binom.test(sum(scores0) fuhaoi0) fuhaoi0) fuhaoi320);ceo.numn=length(ceo)binom.test(ceo.num,n,0.5)例 2.13(P61)a1-alpha)conffy) sgni=1else if (xi=y)sgni=0elsesgni=-1sgnn130 n6nnmd.xy)lxmd.xy)if (alt=“greater“)wMXY“,“md.xy)lxmd.xy)#没有修正时的情形pvalue1yy,1)wm例 3.3
2、weight.low=c(134,146,104,119,124,161,107,83,113,129,97,123)m=length(weight.low)weight.high=c(70,118,101,85,112,132,94)n=length(weight.high)#方法一:wy=xy)zhi引例:x1=xy)zhi例 3.6x1W(0.975,m1,m2)其中 W(0.975,m1,m2)=m1*m2-W(0.025,m1,m2).#方法二(Wilcoxon 秩和检验)wilcox.test(SSA,SSB)#方法二(Mann-Whitney 秩和检验)m=length(SSA)
3、;mn=length(SSB);nmean_AB=m*n/2;mean_ABvar_AB=m*n*(m+n+1)/12;var_ABp_value=1-pnorm(S,mean_AB,sqrt(var_AB);p_value第四章4.1、试验设计和方差分析的基本概念回顾#R 软件中单因素方差分析的函数例 4.1#方法一:*Analysis of Variance Model *y=xy)zhia-c(80,203,236,252,284,368,457,393)b-c(133,180,100,160)c-c(156,295,320,448,465,481,279)d-c(194,214,272
4、,330,386,475)azhi=qiuzhi(a,b,c,d);azhibzhi=qiuzhi(b,a,c,d);bzhiczhi=qiuzhi(c,a,b,d);czhidzhi=qiuzhi(d,a,b,c);dzhiH=12/(n*(n+1)*(sum(azhi)2/length(a)+sum(bzhi)2/length(b)+sum(czhi)2/length(c)+sum(dzhi)2/length(d)-(3*(n+1)方法一:value=qchisq(1-0.05,3);value方法二:pvalue=1-pchisq(H,3);pvaluemean=c(mean(a),me
5、an(b),mean(c),mean(d)#两两比较的程序bjiao=function(azhi,bzhi,czhi,dzhi)n=length(c(azhi,bzhi,czhi,dzhi)av=sum(azhi)/length(azhi)bv=sum(bzhi)/length(bzhi)se=sqrt(n*(n+1)/12*(1/length(azhi)+1/length(bzhi)d=abs(av-bv)dab=d/sehuizong=c(d,se,dab,qnorm(1-0.05,0,1)huizongbjiao(azhi,bzhi,czhi,dzhi)bjiao(czhi,dzhi,azhi,bzhi)4.3、Jonckheere-Terpstra 检验例 4.5x=c(125,136,116,101,105,109)y=c(122,114,131,120,119,127)z=c(128,142,128,134,135,131,140,129)xm=mean(x);xmym=mean(y);ymzm=mean(z);zmg=c(rep(1,6),rep(2,6),rep(3,8)tapply(c(x,y,z),g,median)JT.test(data=t(c(x,y,z),class=g)Wij-function(x,y)