最新SAS例题及程序输出6.doc
精品资料SAS例题及程序输出6.地质勘探中,在A,B,C三个地区采集了一些岩石,测量其部分化学成分,其数据见表3.5。假定这三个地区掩饰的成分遵从。(1)检验不全(2)检验;(3)检验。表3.5 岩石部分化学成分数据SiO2FeOK2OA地区47.225.060.1047.454.350.1547.526.850.1247.864.190.1747.317.570.18B地区54.336.220.1256.173.310.1554.402.430.2252.625.920.12C地区43.1210.330.0542.059.670.0842.509.620.0240.779.680.04解:(1)检验假设,在H0成立时,取近似检验统计量为 统计量:。由样本值计算三个总体的样本协方差阵:进一步计算可得对给定显著性水平,利用软件SAS9.3进行检验时,首先计算p值:p=P13.896916=0.3073394。因为p值=0.3073394>0.05,故接收,即认为方差阵之间无显著性差异。proc iml;n1=5;n2=4;n3=4;n=n1+n2+n3;k=3;p=3;x1=47.22 5.06 0.1,47.45 4.35 0.15,47.52 6.85 0.12,47.86 4.190.17,47.31 7.570.18;x2=54.33 6.22 0.12,56.17 3.310.15,54.4 2.430.22,52.62 5.920.12;x3=43.12 10.33 0.05,42.05 9.670.08,42.5 9.62 0.02,40.77 9.680.04;xx=x1/x2/x3; /*三组样本纵向拼接*/mm1=i(5)-j(5,5,1)/n1;mm2=i(4)-j(4,4,1)/n2;mm=i(n)-j(n,n,1)/n;a1=x1*mm1*x1;print a1;a2=x2*mm2*x2;print a2;a3=x3*mm2*x3;print a3;tt=xx*mm*xx;print tt;/*总离差阵*/a=a1+a2+a3;print a;/*组内离差阵*/da=det(a/(n-k);/*合并样本协差阵*/da1=det(a1/(n1-1);/*每个总体的样本协差阵阵*/da2=det(a2/(n2-1);da3=det(a3/(n3-1);m=(n-k)*log(da)-(4*log(da1)+3*log(da2)+3*log(da3);dd=(2*p*p+3*p-1)*(k+1)/(6*(p+1)*(n-k);df=p*(p+1)*(k-1)/2; /*卡方分布自由度*/kc=(1-dd)*m; /*统计量值*/print da da1 da2 da3 m dd df;p0=1-probchi(kc,df); /*显著性概率*/print kc p0;quit;(2) 提出假设。取检验统计量为,由样本值计算得:进一步计算得:对给定显著性水平,利用软件SAS9.3进行检验时,首先计算p值:p=PF32.098939=0.0010831。因为p值=0.0010831<0.05,故否定,即认为A,B两地岩石化学成分数据存在显著性差异。在这种情况下,可能犯第一类错误,且犯第一类错误的概率为0.05。SAS程序及结果如下:proc iml;n=5;m=4; p=3;x= 47.22 5.06 0.1,47.45 4.35 0.15,47.52 6.85 0.12,47.86 4.190.17,47.31 7.570.18 ;ln=5 1 ;x0=(ln*x)/n; print x0;mx=i(n)-j(n,n,1)/n;a1=x*mx*x; print a1;y= 54.33 6.22 0.12,56.17 3.310.15,54.4 2.430.22,52.62 5.920.12 ;lm=4 1 ;y0=(lm*y)/m; print y0;my=i(m)-j(m,m,1)/m;a2=y*my*y; print a2;a=a1+a2; xy=x0-y0;ai=inv(a); print a ai;dd=xy*ai*xy; d2=(m+n-2)*dd;t2=n*m*d2/(n+m) ;f=(n+m-1-p)*t2/(n+m-2)*p);fa=finv(0.95,p,m+n-p-1);beta=probf(f,p,m+n-p-1,t2);print d2 t2 f beta;pp=1-probf(f,p,m+n-p-1);print pp; quit;(3) 检验假设;因似然比统计量 ,本题中k-1=2,可以利用统计量与F统计量的关系,去检验统计量为F统计量:由样本值计算得:及 ,进一步计算得:对给定显著性水平,利用软件SAS9.3进行检验时,首先计算p值:p=PF18.390234=2.3451×10-6。因为p值=2.3451×10-6<0.05,故否定,即认为A,B,C三地岩石化学成分数据存在显著性差异。在这种情况下,可能犯第一类错误,且犯第一类错误的概率为0.05。proc iml;n1=5;n2=4;n3=4;n=n1+n2+n3;k=3;p=3;x1=47.22 5.06 0.1,47.45 4.35 0.15,47.52 6.85 0.12,47.86 4.190.17,47.31 7.570.18;x2=54.33 6.22 0.12,56.17 3.310.15,54.4 2.430.22,52.62 5.920.12;x3=43.12 10.33 0.05,42.05 9.670.08,42.5 9.62 0.02,40.77 9.680.04;xx=x1/x2/x3; /*三组样本纵向拼接*/ln=51;lnn41;lnnn=131;x10=(ln*x1)/n1;x20=(lnn*x2)/n2;x30=(lnn*x3)/n3;xx0=(lnnn*x1)/n1;mm1=i(5)-j(5,5,1)/n1;mm2=i(4)-j(4,4,1)/n2;mm=i(n)-j(n,n,1)/n;a1=x1*mm1*x1;a2=x2*mm2*x2;a3=x3*mm2*x3;tt=xx*mm*xx;print tt;/*总离差阵*/a=a1+a2+a3; print a;/*组内离差阵*/da=det(a);/*合并样本协差阵*/dt=det(tt);a0=da/dt;print da dt a0;b=sqrt(a0); print b;f=(n-k-p+1)*(1-b)/(b*p);df1=2*p;df2=2*(n-k-p+1);p0=1-probf(f,df1,df2); /*显著性概率*/print f p0;f1=(tt1,1-a1,1)*(n-k)/(k-1)*a1,1);p1=1-probf(f1,k-1,n-k);fa=finv(0.95,k-1,n-k);print fa f1 p1;quit;