|
|
SAS/INSIGHTと同等の信頼楕円を描く
[OS]ALL
[リリース] 6.07, 6.08, 6.09, 6.10
[キーワード] graph, gcontour, gplot, greplay, standard, std=, var, corr, varwith
[質問]SAS/INSIGHTで描くのと同様の信頼楕円を、SAS/GRAPHで描けるでしょうか。
[回答]
残念ながら、標準機能にはこのような機能は有りません。
/*データを標準化します*/
proc standard data=sasuser.class
out=standard mean=0 std=1;
var height weight;
run;
/*heightとweightの相関を求めます*/
proc corr data=standard noprint outp=corrout;
var height;
with weight;
run;
/*楕円を描く際のデータを作成します*/
data contour;
set corrout(where=(_type_='CORR')
keep=_type_ height);
r=height;
pai=3.141593;
c=(1/(2*pai*(1-r**2)**0.5));
do height=-2 to 2 by 0.1;
do weight=-2 to 2 by 0.1;
d=c*exp(-(0.5/(1-r**2)*
(height**2-2*r*height*weight+
weight**2)));
output;
end;
end;
run;
goptions nodisplay;
axis1 order=(-2 to 2) origin=(18pct,18pct)
length=70pct offset=(0,0);
axis2 order=(-2 to 2) origin=(18pct,18pct)
length=70pct offset=(0,0);
axis3 order=(-2 to 2) origin=(18pct,18pct)
length=70pct offset=(0,0)
label=none value=none major=none
minor=none style=0;
axis4 order=(-2 to 2) origin=(18pct,18pct)
length=70pct offset=(0,0)
label=none value=none major=none
minor=none style=0;
/*プロットを描きます*/
proc gplot data=standard ;
plot weight*height
/ haxis=axis1 vaxis=axis2 frame;
run;
/*楕円を描きます*/
proc gcontour data=contour;
plot weight*height=d
/ haxis=axis3 vaxis=axis4
levels=0.05 nolegend;
run;
/* 信頼楕円を描く際の%値は、GCONTORプロシジャのLEVELS=オプションで
1-(\%値/100) の値を指定します。たとえば、95%信頼楕円の場合は
"LEVELS=0.05" になります。 */
goptions display;
/*プロットと楕円を合成します*/
proc greplay nofs igout=gseg
tc=sashelp.templt
template=whole;
treplay 1: gcontour 1: gplot;
run;
quit;
|
|||||