DIXC ;SFISC/GFT-DESCRIPTIVE STATS, CORRELATION MATRIX ;22APR2010
 ;;22.0;VA FileMan;**2,1002,1003,1039**;Mar 30, 1999
 ;
 N DIXSKIP,DJ S DIXSKIP=1,DJ=$P G DESCX
D N SZ,SZT,DJ,DN,DHDR,DS,DIXSKIP
 D DESC G DESCX
 ;
C D CORR G CORRX
 ;
SQR S Y=0 Q:X'>0  S Y=1+X/2
L S T=Y,Y=X/T+T/2 G L:Y<T
 K T Q
 ;
DLCOR S DJ=IO(0),U="^",SZ=0
 F SZT=1:1 S:$D(^DOSV(0,DJ,"CP",SZT)) SZ=SZT Q:'$D(^DOSV(0,DJ,0,SZT,"S"))  Q:'$D(^DOSV(0,DJ,"F",SZT))  S DN(SZT)=$E($P(^(SZT),U,3),1,8)
 S SZT=SZT-1 Q
 ;
DESC ;CALCULATE THE DESCRIPTIVE STATISTICS
 D DLCOR K DS F I=1:1:SZT I $D(^DOSV(0,DJ,0,I,"Q")) S X=^("Q")-((^("S")*^("S"))/^("N"))/(^("N")) D SQR S ^("D")=Y
 Q
 ;
DESCX ;PRINT DESCRIPTIVE STATS
 N DIXDELIM,DHDR,DIFF,%ZIS
 S:$D(^%ZTSK) %ZIS="Q" D ^%ZIS G Q:POP
 S DIFF=$D(^DOSV(0,DJ,1))!$D(^(2))!$D(^(3))
 I DIFF,$G(IOT)="HFS" W !,"USE COMMA AS DELIMITER FOR SPEADSHEET" S %=2 D YN^DICN G Q:%<1 S:%=1 DIXDELIM=","
 I $D(IO("Q")) D  G KL
 .F I="DIFF","DIX*","^DOSV(0,$I,","SZT","DN*" S ZTSAVE(I)=""
 .S ZTIO=ION_";"_IOST_";"_IOM_";"_IOSL,ZTRTN="DQ^DIXC"
 .D ^%ZTLOAD
D1 I '$G(DIXSKIP),$D(SZT) S DHDR="77CUST",DHDR(1)="DESCRIPTIVE STATISTICS" D DQ^DIX D:SZT  G KL:'DIFF
 .W !!,?13,"N OF",?39,"STANDARD"
 .W !,?13,"CASES",?25,"MEAN",?39,"DEVIATION",?54,"MINIMUM",?69,"MAXIMUM"
 .F I=1:1:SZT D
 ..W !,DN(I),?10
 ..I $D(^DOSV(0,DJ,0,I,"N")) W $J(^("N"),6) W:^("N") $J(^("S")/^("N"),15,4)
 ..F X="D","L","H" W $S($D(^(X)):$J(^(X),15,4),1:$J("",15))
 .D EOP^DIG Q
  D STATS^DIG($NA(^DOSV(0,DJ)),.DIXDELIM) Q
  ;
CORR ;CALCULATE THE CORRELATION MATRIX
 K ^UTILITY($J),ERR I $O(^DOSV(0,IO(0),1))'>0 W !!,"*****     AT LEAST TWO VARIABLES MUST BE DEFINED     *****" S ERR=1 Q
 D DLCOR ;F I=1:1:SZ I ^DOSV(0,IO(0),"BY",I,"H")=^("L") W $C(7),!,"CAN'T COMPUTE CORRELATION MATRIX--",DN(I+100)," IS SINGLE-VALUED" S ERR=1 G KL
 F I=2:1:SZ S N=^DOSV(0,DJ,0,I,"N"),S=^("S"),C=^DOSV(0,DJ,"CP",I,I) F J=1:1:I-1 I $D(^DOSV(0,DJ,"CP",I,J)) D C1
 G KL
C1 S X=N*C-(S*S)*(N*^DOSV(0,DJ,"CP",J,J))-(^DOSV(0,DJ,0,J,"S")*^("S"))
 D SQR S (^UTILITY($J,J,I),^UTILITY($J,I,J))=(N*^DOSV(0,DJ,"CP",I,J))-(S*^DOSV(0,DJ,0,J,"S"))/Y
 Q
CORRX ;OUTPUT THE CORRELATION MATRIX
 G:$D(ERR) KL K DHDR S DHDR="72TSU",DHDR(1)="CORRELATION MATRIX",DHDR(2)="" D DHDR^DIX G Q:POP
 F I=1:1:SZ S ^UTILITY($J,I,I)=1 I $D(^UTILITY($J,I,I)) W ?I*10-2,$J(DN(I),10)
 F I=1:1:SZ I $D(^UTILITY($J,I,I)) W !,DN(I) F J=1:1:I I $D(^UTILITY($J,I,J)) W ?J*10,$J(^UTILITY($J,I,J),8,4)
 W !!
KL W:$E(IOST)'="C"&($Y) @IOF I IO(0)'=IO D CLOSE^DIO4
Q U $P K C,DHDR,I,II,J,JJ,N,POP,S,X,Y,Z,DJ,DN,SZ,SZT,DIFF
 Q
 ;
 ;
DQ ;FOR QUEUED OUTPUT
 S DJ=$I G D1
