|
(4)计算每一对观测值到样本均值向量的统计距离平方。
程序:proc iml;
n=10;p=2;
xx={x1 x2};
use awt5_2;
read all var xx into x;
e={[10] 1};
x0=(e*x)/n;
mm=i(10)-j(10,10,1)/n;
a=x`*mm*x;
s=a/(n-1);
si=inv(s);print x0 s si; /*si为s的逆矩阵*/
use awt5_2(obs=1);
read all var xx into xx1;
d1=(xx1-x0)*si*(xx1-x0)`; /*d 为马氏距离*/
use awt5_2(firstobs=2 obs=2);
read all var xx into xx2;
d2=(xx2-x0)*si*(xx2-x0)`;
use awt5_2(firstobs=3 obs=3);
read all var xx into xx3;
d3=(xx3-x0)*si*(xx3-x0)`;
use awt5_2(firstobs=4 obs=4);
read all var xx into xx4;
d4=(xx4-x0)*si*(xx4-x0)`;
use awt5_2(firstobs=5 obs=5);
read all var xx into xx5;
d5=(xx5-x0)*si*(xx5-x0)`;
use awt5_2(firstobs=6 obs=6);
read all var xx into xx6;
d6=(xx6-x0)*si*(xx6-x0)`;
use awt5_2(firstobs=7 obs=7);
read all var xx into xx7;
d7=(xx7-x0)*si*(xx7-x0)`;
use awt5_2(firstobs=8 obs=8);
read all var xx into xx8;
d8=(xx8-x0)*si*(xx8-x0)`;
use awt5_2(firstobs=9 obs=9);
read all var xx into xx9;
d9=(xx9-x0)*si*(xx9-x0)`;
use awt5_2(firstobs=10 obs=10);
read all var xx into xx10;
d10=(xx10-x0)*si*(xx10-x0)`;
print d1 d2 d3 d4 d5 d6 d7 d8 d9 d10;
run;
通过d1=(xx1-x0)*si*(xx1-x0)`可计算各样本到达样本均值的马氏距离。
(5)计算样本点落在二元正态50%置信区域内的比率。(χ22(0.5)=1.39)
先算dj*dj
d1*d1=3.4101>1.39 d2*d2=1.4915>1.39 d3*d3=0.8642
d4*d4=0.2344 d5*d5=1.2746 d6*d6=0.0052
d7*d7=0.1873 d8*d8=0.5593 d9*d9=1.0701
d10*d10=1.8592>1.39
所以有七组数据时小于1.39的,落在二元正态50%置信区域内的比率是70%。
程序:proc lifetest method=pl width=2;
time x2*x2(0);
freq x2;
run;
proc lifetest method=pl width=2;
time x1*x2(0);
freq x2;
run;
运行模块lifetest,我们可以得到x1,x2的点估计和区间估计,同时又相对应的75%、50%、25%三种情况下的置信区间比率。
(6)作(X1,X2)的Chi-square图。
程序:data md;
input n d @@;
cards;
1 4.0586824
2 2.1095808
3 2.1074318
4 0.6361144
5 3.2654794
6 0.0079034
7 0.5218616
8 0.6479336
9 2.0590803
10 2.5859323
;
run;
proc sort data=md;
by d;
run;
proc print data=md;
run;
proc means data=md noprint;
var d;
output out=chiqn n=totn;
run;
data chiqq;
if (_n_=1) then set chiqn;
set md;
novar=2;
chisq=cinv(((_n_-0.5)/totn),novar);
prop=0;
d0=cinv(0.5,novar);
if d <=d0 then prop=1;
proc univariate data=chiqq;
var prop;
run;
proc gplot;
plot d*chisq;
label d='Mahalanobis Distance'
chisq='Chi-Square Quantile';
symbol1 v=star;
*symbol2 i=join v=+;
run;
(7)判断(X1,X2)的二元正态性。
由(6)中图可知,(x1,x2)符合二元正态分布
|