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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
*(Q) How can I study interaction in factorial designs if the dependent
variable is not normal? (Non parametric 2-way ANOVA)

*(A) There are several ways:

*References:
*1) Shirley EAC. "Applications of Ranking Methods to Multiple Comparison
   Procedures and Factorial Experiments". Appl Statist
	1987;36(2):205-213.
*2) Conover WJ and Iman RL. "Rank Transformations as a Bridge between
   Parametric and Nonparametric Statistics". The American Statistician
   1981;35:124-129.
* Code written by Marta Garcia-Granero, sent to rlevesque by email on 2002/02/05.

******************** EXAMPLE ****************************.
DATA LIST LIST /altit(f2.0) splenec(f2.0) fibrinog(f4.0).
BEGIN DATA
1	1	528
1	1	444
1	1	338
1	1	342
1	1	338
1	2	434
1	2	331
1	2	312
1	2	575
1	2	472
2	1	294
2	1	254
2	1	352
2	1	241
2	1	291
2	2	272
2	2	275
2	2	350
2	2	350
2	2	466
END DATA.
VARIABLE LABELS altit "Altitude".
VALUE LABELS altit
 1 "Sea level"
 2 "15.000 ft." .
VARIABLE LABELS splenec "Splenectomy".
VALUE LABELS splenec
 1 "No"
 2 "Yes" .

* SOLUTION #1: FOR BALANCED AND SQUARE DESIGNS ONLY
* (AS THIS ONE IS: n=5; 2x2 design)
* (in this situation, Chi square values are additive)
*********************************************************.

COMPUTE group = splenec+2*(altit=2) .
* (for a 3x3 design: COMPUTE group = splenec+3*(altit=2)+6*(altit=3)
* and so on...).
EXECUTE .
VARIABLE LABELS group "Combined group".
VALUE LABELS group
 1 "Sea lev/No"
 2 "Sea lev/Yes"
 3 "15.000 ft/No"
 4 "15.000 ft/Yes" .

NPAR TESTS
  /K-W=fibrinog BY group(1 4)
  /K-W=fibrinog BY altit(1 2)
  /K-W=fibrinog BY splenec(1 2).

* Now, read the 3 Chi-square values + df from output and compute
* Interaction Chi-square (and df) as difference: group - altit- splenec
* The values have to be copied to the two first COMPUTE statements
* (I still haven't found a solution for this).

DO IF $casenum=1.
COMPUTE chi=5.774-4.487-0.824.
COMPUTE df=3-1-1.
COMPUTE sig = 1-CDF.CHISQ(chi,df) .
END IF.
EXECUTE.
FORMAT chi (F8.3) df (F2.0) sig (F8.4).
REPORT FORMAT=LIST AUTOMATIC ALIGN(CENTER)
  /VARIABLES=chi df sig
  /MISSING=LIST
  /TITLE "Kruskal-Wallis test for interaction".


* For unbalanced and/or non-square designs (2x3, 3x4...), the above
* solution doesn't work (you can end up with a negative Chi-square!).

* SOLUTION #2 (GENERAL): 2-WAY ANOVA (WITH TYPE 3 SS) WITH THE RANKS
*****************************************************************************.
DATA LIST LIST /altit(f2.0) splenec(f2.0) fibrinog(f4.0).
BEGIN DATA
1	1	528
1	1	444
1	1	338
1	1	342
1	1	338
1	2	434
1	2	331
1	2	312
1	2	575
1	2	472
2	1	294
2	1	254
2	1	352
2	1	241
2	1	291
2	2	272
2	2	275
2	2	350
2	2	350
2	2	466
END DATA.
VARIABLE LABELS altit "Altitude".
VALUE LABELS altit
 1 "Sea level"
 2 "15.000 ft." .
VARIABLE LABELS splenec "Splenectomy".
VALUE LABELS splenec
 1 "No"
 2 "Yes" .


* First, rank the dependent variable (as Kruskal-Wallis test does).
RANK VARIABLES=fibrinog (A) /RANK INTO yranks /PRINT=NO /TIES=MEAN .

* Now, a factorial ANOVA with the ranks.
UNIANOVA  yranks BY altit splenec.

* According to Conover and Iman, the F values and significance are
* approximately valid, but, if you want to have more appropriate
* p-values you must calculate Kruskal-Wallis Chi squares with their
* significance (according to Shirley).

* The following MACRO does all the work (from ranking to Chi square
* significance, + two profile plots with medians, to interpret the
* interaction if significant).

********************
* MACRO DEFINITION *
********************.

DEFINE rank2w (facta=!CHAREND ('/') /factb=!CHAREND ('/')
/depvar=!CMDEND ).
GRAPH /LINE(MULTIPLE)MED(!depvar) BY !facta BY !factb.
GRAPH /LINE(MULTIPLE)MED(!depvar) BY !factb BY !facta.
RANK VARIABLES=!depvar (A) /RANK INTO yranks /PRINT=NO /TIES=MEAN .
UNIANOVA  yranks BY !facta !factb /OUTFILE=EFFECT ('report_.sav').
GET FILE='report_.sav' /KEEP= source_ ss df.
EXECUTE.
SELECT IF((source_='CorModel') or (source_='CorTotal') or (source_='S2')
or (source_='S3') or (source_='S4')).
EXECUTE .
COMPUTE pos=$casenum.
execute.
SORT CASES BY pos(D).
compute varri=ss/df.
if $casenum>1 varri=lag(varri,1).
execute.
DO IF $casenum>1.
COMPUTE chi=ss/varri.
COMPUTE sig = 1-CDF.CHISQ(chi,df) .
END IF.
execute.
VARIABLE LABELS sig "Sig.".
VARIABLE LABELS chi "Chi square".
FORMAT ss (F8.3) df (F4.0) chi (F8.3) sig (F9.4).
SORT CASES by pos(A).
REPORT FORMAT=LIST AUTOMATIC ALIGN(CENTER)
  /VARIABLES=source_(label) ss df chi sig
  /TITLE "2-way Kruskal-Wallis".
!ENDDEFINE.

* MACRO call *.
rank2w facta=altit /factb=splenec /depvar=fibrinog.