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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
* ======================================================================= 
*  File:  	power analysis.SPS .
*  Date:  	09-Oct-2003 .
*  Author:  	Bruce Weaver, weaverb@mcmaster.ca .
*  Notes:	Power analysis examples.
* ======================================================================= .

* The following examples are from a paper by D'Amico, Neilands, and
* Zambarano in Behavior Research Methods, Instruments, & Computers,
* 2001, 33(4), 479-484.

* These examples use the MATRIX DATA command to input the data.
* For a brief explanation of how this works, go to
*  http://www.utexas.edu/cc/faqs/stat/spss/spss33.html .


* -------------------------------------------------- .
* Example 1:  ANCOVA with 3 groups and 2 covariates .
* -------------------------------------------------- .

* The data for this example are as follows.

*               Patient   # of     Parent   .
*               Anxiety  Siblings  Anxiety  .
* AGE GROUP      M    SD    M  SD    M   SD .
*  6-12         7.5  1.9    3  1     4  2.3 .
* 13-19         6.8  2.5    2  2     5  1.4 .
* 20-45         7.1  2.1    4  1     6  1.8 .

* Patient Anxiety is the dependent variable.
* Age Group is the independent variable.
* # of siblings and Parent Anxiety are covariates.

* The following syntax reads in these data in matrix format.

matrix data 
 variables = agegroup rowtype_ pat_anx sibnumbr prnt_anx
 /factor = agegroup
 /format = lower nodiagonal.
begin data.
1 mean 7.5 3.0 4.0
1 n 50 50 50
2 mean 6.8 2.0 5.0
2 n 50 50 50
3 mean 7.1 4.0 6.0
3 n 50 50 50
. sd 2.17 1.33 1.83
. corr 0.3
. corr 0.3 0.3
end data.

* NOTE:  	Only 3 SDs are read in, one for the DV, and one for each covariate.
*		These are MEAN standard deviations, i.e., mean of the SDs for the
*		3 age groups.  For Patient Anxiety, for example, the mean SD is
*		(1.9 + 2.5 + 2.1)/3 = 2.17.  Using the mean SD makes sense if
*		the assumption of homogeneous variances is tenable.  You can enter
*		the SDs for each group (like you do the means), but you have to
*		also enter the mean SDs as we did in order for the procedure to
*		work properly.  (I tried it with only the individual group SDs,
*		and got an error message indicating that needed SDs were missing.)

manova
 pat_anx by agegroup(1,3) with prnt_anx sibnumbr
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* For the main effect of Age Group, power = 0.742.
* This is a bit lower than the usual figure one shoots for, 0.80.
* So let's repeat the exercise, but with increased sample sizes.
* The following sets each group size = 60 instead of 50.

matrix data 
 variables = agegroup rowtype_ pat_anx sibnumbr prnt_anx
 /factor = agegroup
 /format = lower nodiagonal.
begin data.
1 mean 7.5 3.0 4.0
1 n 60 60 60
2 mean 6.8 2.0 5.0
2 n 60 60 60
3 mean 7.1 4.0 6.0
3 n 60 60 60
. sd 2.17 1.33 1.83
. corr 0.3
. corr 0.3 0.3
end data.

manova
 pat_anx by agegroup(1,3) with prnt_anx sibnumbr
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* With n=60 per group, Power for the main effect of Age Group = 0.823 .

* ---------------------------------------- .
* Power for One-way ANOVA on the same data .
* ---------------------------------------- .

* Suppose you dropped the two covariates from the analysis,
* and used one-way ANOVA to analyze these data.  Power would 
* be calculated as shown below (for n=60 per group).

matrix data 
 variables = agegroup rowtype_ pat_anx 
 /factor = agegroup .
begin data.
1 mean 7.5 
1 n 60 
2 mean 6.8 
2 n 60 
3 mean 7.1 
3 n 60 
. sd 2.17 
. corr 1
end data.

* NOTE THE FOLLOWING CHANGES TO THE MATRIX DATA COMMAND (compared to previous example).

*   [1] The "/format = lower nodiagonal" line has been removed;
*   [2] The correlation matrix consists of a single line "corr 1".

* We only need one line to represent the correlation matrix, because
* the correlation is of the DV with itself.

manova
 pat_anx by agegroup(1,3)
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* Without the 2 covariates, power drops from .823 to .329.


* ---------------------------------------------------------- .
* Example 2:  MANOVA with 3 groups and 2 dependent variables .
* ---------------------------------------------------------- .

* Research Question:  Are there differences among 3 ethnic groups
* on ratings of risks and benefits of alcohol consumption?

* Independent variable: ethnic group (3 levels).
* Dependent variables:	1) ratings of risks of alcohol consumption
*				2) ratings of benefits of alcohol consumption.

* Read in data in matrix format.

matrix data
 variables = group rowtype_ risk benefit
 /factor = group
 /format = lower nodiagonal.
begin data.
1 mean 4.8 3.9
1 n 20 20
2 mean 5.3 4.0
2 n 20 20
3 mean 5.8 3.5
3 n 20 20 
. sd 1.27 1.4
. corr .3
end data.

manova
 risk benefit by group(1,3)
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* There are 3 Power estimates to examine here:

* 	1) Power = 0.57 for the univariate test for RISK
* 	2) Power = 0.17 for the univariate test for BENEFIT
* 	3) Power = 0.65 to 0.67 for the various multivariate tests .

* You would probably want to add more subjects here, no matter what.
* But how many more would depend on which of the DVs you were
* primarily interested in.  If RISK is of primary concern, and
* you were not too bothered about BENEFIT, you would not need to
* add as many subjects to get the Power for RISK up to acceptable
* levels.  But if you wanted to have 80% power for BENEFIT, you'd
* have to add a lot more.

* Let's try again with n = 30 per group instead of 20.

matrix data
 variables = group rowtype_ risk benefit
 /factor = group
 /format = lower nodiagonal.
begin data.
1 mean 4.8 3.9
1 n 30 30
2 mean 5.3 4.0
2 n 30 30
3 mean 5.8 3.5
3 n 30 30 
. sd 1.27 1.4
. corr .3
end data.

manova
 risk benefit by group(1,3)
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* We now have roughly 85% power for the multivariate test,
* power = 0.77 for RISK, and power = 0.23 for BENEFIT .

* ---------------------------------------------------------- .
* Example 3:  Mixed design (between-within) ANOVA            .
* ---------------------------------------------------------- .

* Dependent variable: 		Ratings of depression .
* Between-subjects factor:  	Group (3 levels).
* Within-subjects factor:	Time (DV measured on 3 occasions).

* The effect of most interest is the Group x Time interaction.
* How many subjects do we need to have 80% power for this term?.

* Read in data in matrix format .

matrix data
 variables = group rowtype_ depress1 depress2 depress3
 /factor = group
 /format = lower nodiagonal.
begin data.
1 mean 11 10 9
1 n 33 33 33
2 mean 11 10 10
2 n 33 33 33
3 mean 11 11 10
3 n 34 34 34
. sd 2.3 2.0 1.8
. corr 0.3
. corr 0.3 0.3
end data.

manova
 depress1 depress2 depress3 by group(1,3)
 /wsfactors depress(3)
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* Power = 0.56 for the interaction term, so we need to increase n.
* Try again with n = 55 per group .

matrix data
 variables = group rowtype_ depress1 depress2 depress3
 /factor = group
 /format = lower nodiagonal.
begin data.
1 mean 11 10 9
1 n 55 55 55
2 mean 11 10 10
2 n 55 55 55
3 mean 11 11 10
3 n 55 55 55
. sd 2.3 2.0 1.8
. corr 0.3
. corr 0.3 0.3
end data.

manova
 depress1 depress2 depress3 by group(1,3)
 /wsfactors depress(3)
 /method = unique
 /error = within+residual
 /matrix = in(*)
 /power t (.05) F (.05)
 /print signif (mult averf)
 /noprint param(estim).

* With n=55 per group, power = .813 for the interaction term.

* ======================================================================= .