*****************************************
** **
** Hotelling's T**2 & Profile Analysis **
** **
*****************************************
* Input matrix of raw scores for group X.
MATRIX.
COMPUTE X = { 7, 5, 9, 8;
8, 8, 5, 6;
16, 18, 11, 9;
8, 3, 7, 9;
6, 3, 13, 9;
11, 8, 10, 10;
12, 7, 9, 8;
8, 11, 9, 3;
14, 12, 11, 4;
13, 13, 13, 6;
13, 9, 9, 9;
13, 10, 15, 7;
14, 11, 12, 8;
15, 11, 11, 10;
13, 10, 15, 9;
10, 5, 8, 6;
10, 3, 7, 7;
17, 13, 13, 7;
10, 6, 10, 7;
10, 10, 15, 8;
14, 7, 11, 5;
16, 11, 12, 11;
10, 7, 14, 6;
10, 10, 9, 6;
10, 7, 10, 10;
7, 6, 5, 9;
15, 12, 10, 6;
17, 15, 15, 8;
16, 13, 16, 9;
13, 10, 17, 8;
13, 10, 17, 10;
19, 12, 16, 10;
19, 15, 17, 11;
13, 10, 7, 8;
15, 11, 12, 8;
16, 9, 11, 11;
14, 13, 14, 9 }.
COMPUTE NX = NROW(X).
COMPUTE KX = NCOL(X).
PRINT {NX, KX} /TITLE "No. of Cases, No. of Vars. in X".
* Input matrix of raw scores for group Y.
COMPUTE Y = { 9, 5, 10, 8;
10, 0, 6, 2;
8, 9, 11, 1;
13, 7, 14, 9;
4, 0, 4, 0;
4, 0, 6, 0;
11, 9, 9, 8;
5, 3, 3, 6;
9, 7, 8, 6;
7, 2, 6, 4;
12, 10, 14, 3;
13, 12, 11, 10 }.
COMPUTE NY = NROW(Y).
COMPUTE KY = NCOL(Y).
PRINT {NY, KY} /TITLE "No. of Cases, No. of Vars. in Y".
* Calculate sample means.
COMPUTE UNITX = MAKE (NX, 1, 1.0).
COMPUTE MEANSX = T(UNITX) * X &* (1.0 / NX).
PRINT MEANSX /TITLE "Sample means for group X".
COMPUTE UNITY = MAKE (NY, 1, 1.0).
COMPUTE MEANSY = T(UNITY) * Y &* (1.0 / NY).
PRINT MEANSY /TITLE "Sample means for group Y".
COMPUTE DIFF = MEANSX - MEANSY.
PRINT DIFF /TITLE "Differences".
* Calculate mean-corrected SSCP matrices.
COMPUTE BXX = SSCP(X).
COMPUTE SX = BXX - ((1/NX) &* (T(X) * UNITX) * (T(UNITX) * X)).
COMPUTE BYY = SSCP(Y).
COMPUTE SY = BYY - ((1/NY) &* (T(Y) * UNITY) * (T(UNITY) * Y)).
* Calculate covariance-variance matrices.
COMPUTE CX = (1/(NX-1.0)) &* SX.
COMPUTE CY = (1/(NY-1.0)) &* SY.
* Pooled covariance matrix.
COMPUTE COV = (((NX-1) &* CX) + ((NY-1) &* CY)) &/ (NX+NY-2).
COMPUTE ICOV = INV(COV).
* "Hotelling's T**2 statistic".
COMPUTE T2 = (NX * NY * DIFF * ICOV * T(DIFF)) / (NX+NY).
PRINT /TITLE " ========== Hotelling's Two-Sample T**2 Test of Means ========== ".
PRINT T2 /TITLE "Hotelling's T**2 Statistic".
COMPUTE F = T2 * (NX+NY-KX-1) / ((NX+NY-2)*KX).
PRINT { F, KX, NX+NY-KX-1 } /Title "Equivalent F & d.f.".
COMPUTE P = 1.0 - FCDF(F, KX, NX+NY-KX-1).
PRINT P /TITLE "P-value" /FORMAT = F10.9.
PRINT /TITLE " ========== Hotelling's Profile Analysis ========== ".
* Create Design Matrix C for successive contrasts.
COMPUTE V1 = { 1, -1 }.
COMPUTE V2 = MAKE (1, KX-1, 0).
COMPUTE V3 = {V1, V2}.
COMPUTE V4 = V3.
LOOP I = 1 to KX-1.
COMPUTE V4 = {V4 ; V3}.
END LOOP.
COMPUTE C = RESHAPE (V4, KX+1, KX).
COMPUTE C = C(1:(KX-1), 1:KX).
PRINT C /TITLE "Contrast matrix".
* Differences between adjacent scales for group X.
COMPUTE DIFF1 = MEANSX * T(C).
PRINT DIFF1 /TITLE "Differences between adjacent scales for group X".
* Differences Between adjacent scales for group Y.
COMPUTE DIFF2 = MEANSY * T(C).
PRINT DIFF2 /TITLE "Differences between adjacent scales for group Y".
* Pooled covariance matrix of differences.
COMPUTE POOL = C * COV * T(C).
PRINT POOL /TITLE "Pooled covariance matrix of differences".
COMPUTE IPOOL = INV(POOL).
PRINT IPOOL /TITLE "Inverted pooled cov. matrix of diff.".
PRINT /TITLE " ----- Hypothesis 1: Parallelism (no group X scale interactions) ----- ".
COMPUTE PARALLEL = (NX * NY * DIFF * T(C) * IPOOL * C * T(DIFF)) / (NX+NY).
PRINT PARALLEL /TITLE "Hotelling's T**2 statistic for Parallelism".
COMPUTE F = PARALLEL * (NX+NY-KX) / ((NX+NY-2)*(KX-1)).
PRINT { F, KX-1, NX+NY-KX } /TITLE "Equivalent F & d.f.".
COMPUTE P = 1.0 - FCDF(F, KX-1, NX+NY-KX).
PRINT P /TITLE "P-value" /FORMAT F10.9.
PRINT /TITLE " ----- Hypothesis 2: Equal Levels (assuming parallelism) ----- ".
* Create design vector J for equal levels.
COMPUTE J = MAKE (1, KX, 1.0).
* Grand total for group x.
COMPUTE GRANDX = MEANSX * T(J).
PRINT GRANDX /TITLE "Grand mean for group X".
* Grand total for group y.
COMPUTE GRANDY = MEANSY * T(J).
PRINT GRANDY /TITLE "Grand mean for group Y".
* Differences in levels.
COMPUTE DIF = J * T(DIFF).
PRINT DIF /TITLE "Difference in levels".
* Variance of differences.
COMPUTE CV = J * COV * T(J).
PRINT CV /TITLE "Variance of differences".
COMPUTE EQUAL = J * T(DIFF) / (SQRT ( CV * (1/NX + 1/NY) ) ).
PRINT { EQUAL, NX+NY-2 } /TITLE "Hotelling's t-test for Equal levels (one-tailed)".
COMPUTE P = (1.0 - TCDF(ABS(EQUAL), NX+NY-2 )) * 0.5.
PRINT P /TITLE "P-value" /FORMAT F10.9.
PRINT /TITLE " ----- Hypothesis 3: Flatness (again assuming parallelism) ----- ".
* Total Grand Means.
COMPUTE GRAND = ((MEANSX * NX) + (MEANSY * NY)) / (NX + NY).
PRINT GRAND /TITLE "Total Group Means".
COMPUTE FLAT = (NX+NY) * GRAND * T(C) * IPOOL * C * T(GRAND).
PRINT FLAT /TITLE "Hotelling's T**2 statistic for Flat Profiles".
COMPUTE F = FLAT * (NX+NY-KX) / ((NX+NY-2) * (KX-1)).
PRINT { F, KX-1, NX+NY-KX } /TITLE "Equivalent F & d.f.".
COMPUTE P = 1.0 - FCDF( F, KX-1, NX+NY-KX ).
PRINT P /TITLE "P-value" /FORMAT F10.9.
END MATRIX.