options ls=78; title "Paired Hotelling's T-Square"; /* The differences 'd1' through 'd4' are defined * and added to the data set. */ data spouse; infile "D:\Statistics\STAT 505\data\spouse.csv" firstobs=2 delimiter=','; input h1 h2 h3 h4 w1 w2 w3 w4; d1=h1-w1; d2=h2-w2; d3=h3-w3; d4=h4-w4; run; proc print data=spouse; run; /* The iml code below defines and executes the 'hotel' module * for calculating the one-sample Hotelling T2 test statistic. * The calculations are based on the differences, which is why * there is a single null vector consisting of only 0s. * The commands between 'start' and 'finish' define the * calculations of the module for an input vector 'x'. * The 'use' statement makes the 'spouse' data set available, from * which the difference variables are taken. The difference variables * are then read into the vector 'x' before the 'hotel' module is called. */ proc iml; start hotel; mu0={0, 0, 0, 0}; one=j(nrow(x),1,1); ident=i(nrow(x)); ybar=x`*one/nrow(x); s=x`*(ident-one*one`/nrow(x))*x/(nrow(x)-1.0); print mu0 ybar; print s; t2=nrow(x)*(ybar-mu0)`*inv(s)*(ybar-mu0); f=(nrow(x)-ncol(x))*t2/ncol(x)/(nrow(x)-1); df1=ncol(x); df2=nrow(x)-ncol(x); p=1-probf(f,df1,df2); print t2 f df1 df2 p; finish; use spouse; read all var{d1 d2 d3 d4} into x; run hotel;