- Example 1: Power for 2x2 table with cell count data
-
In this example, each
observation is a cell count instead of a single response, so a count
variable (FREQ) is created to hold the cell counts. The observed
sample size is used for computing approximate power.
data a;
do row=1 to 2;
do col=0,1;
input freq @@; output;
end;
end;
datalines;
3 11
6 2
;
/* Define the POWER2x2 macro */
%inc "<location of your file containing the POWERRxC macro>";
%powerRxC(row=row, col=col, count=freq)
Results:
Approximate Power of Chi-square Tests for Independence
Test Level=.05
Power of Power
Pearson of L.R.
n Chi-square Chi-square
22 0.69093 0.70345
- Example 2: Power for 2x2 table with individual data
-
This example is identical to the previous one except that raw, individual data are used instead of summarized, cell-count data. That is, each observation in data set AA contributes a count of one in one cell of the table. With individual data, a count variable is not needed.
data aa;
do row=1 to 2;
do col=0,1;
input freq @@;
do i=1 to freq;
drop i freq;
output;
end;
end;
end;
datalines;
3 11
6 2
;
%powerRxC(row=row, col=col)
Results:
The results are identical to Example 1.
- Example 3: Power for RxC table
-
Suppose subjects are to be given one of four treatments and a
binary response will be recorded for each subject resulting in a
4x2 table. Determine the sample size needed to detect a 0.1
difference in response probabilities with adequate power. This is
done by entering cell values that exhibit the worst case scenario
-- three rows with response probability .2 (=.05/(.2+.05)) and one
row with response probability .1 (=.025/(.225+.025)). Treatment
sample sizes are to be equal, so the marginal row (treatment) probabilities are
all 0.25. Here, column 2 is regarded as the response category,
though the columns could be reversed without effect.
data bb;
do trt=1 to 4;
do response=0,1;
input prob @@; output;
end;
end;
datalines;
.2 .05
.2 .05
.2 .05
.225 .025
;
%powerRxC(row=trt, col=response, count=prob,
nrange=%str(20,50,100 to 1000 by 100))
Results:
Approximate Power of Chi-square Tests for Independence
Test Level=.05
Power of Power
Pearson of L.R.
n Chi-square Chi-square
20 0.06570 0.06735
50 0.09111 0.09562
100 0.13763 0.14762
200 0.24106 0.26305
300 0.34986 0.38282
400 0.45603 0.49715
500 0.55420 0.59999
600 0.64131 0.68842
700 0.71608 0.76178
800 0.77855 0.82086
900 0.82955 0.86728
1000 0.87038 0.90299
Beginning in SAS 9.4 TS1M4, the same results can be obtained using the CUSTOM statement in PROC POWER. As described in the documentation of the CUSTOM statement, an exemplary data set is created and the chi-square statistic and degrees of freedom are obtained for this data set. The chi-square statistic is used to provide the noncentrality value (PRIMNC=) in PROC POWER. In this example, the treatments are to have equal sample sizes so a single instance of each is created in the exemplary data set, BB (one instance involves one observation for each response level). Note that this is 4 times the proportion (0.25) of each treatment in the data. Hence, the chi-square statistic is divided by four for use as the noncentrality value.
The following statements produce the power analysis and yields the same power values as the PowerRxC macro above.
data BB;
do trt=1 to 4;
input p0 p1;
y=0; py=p0/(p0+p1); output;
y=1; py=p1/(p0+p1); output;
end;
datalines;
.2 .05
.2 .05
.2 .05
.225 .025
;
proc freq data=bb;
weight py;
table trt*y/chisq;
ods output chisq=cs(where=(statistic="Chi-Square")) ;
run;
data _null_;
set cs;
call symput('cs',value/4);
call symput('df',df);
run;
proc power;
custom
dist = chisquare
primnc = &cs
testdf = &df
ntotal = 20, 50, 100 to 1000 by 100
power = .;
run;
- Example 4: Power for range of sample sizes in a 2x2 table
-
Example from Agresti (1990) pp 241-243. Column 1 probabilities for
each row are hypothesized to be .63 and .57. Row sample sizes are
to be equal, so the marginal row probabilities are both 0.5.
data c;
do row=1 to 2;
do col=0,1;
input freq @@;
output;
end;
end;
datalines;
.315 .185
.285 .215
;
%powerRxC(data=c, row=row, col=col, count=freq,
nrange=%str(20,50 to 200 by 50))
Results:
Approximate Power of Chi-square Tests for Independence
Test Level=.05
Power of Power
Pearson of L.R.
n Chi-square Chi-square
20 0.05864 0.05864
50 0.07174 0.07176
100 0.09395 0.09398
150 0.11651 0.11656
200 0.13935 0.13941
- Example 5: Power for observed 3x2 table
-
Get power for a .10 level test performed on previously-collected
data.
data d;
input type $ sex $ ;
datalines;
a m
b m
c f
b m
c f
c f
b f
a m
a f
a m
b m
c f
b m
c f
c f
b f
a m
a f
;
%powerRxC(row=type, col=sex, level=.10)
Results:
Approximate Power of Chi-square Tests for Independence
Test Level=.10
Power of Power
Pearson of L.R.
n Chi-square Chi-square
18 0.77402 0.87034