1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
*****************************************
**                                     **
** 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.