powerrxc Power analysis for Chi-sqare tests of independence powerrxc

SAS Macro Programs: powerrxc

$Version: 1.0 (19 Dec 1999)
Michael Friendly
York University

The powerrxc macro ( [download] get powerrxc.sas)

Power analysis for Chi-sqare tests of independence

The powerrxc macro computes approximate power for Pearson and Likelihood Ratio Chi-square tests of independence in PROC FREQ.

The powerrxc macro was written by SAS Institute. It requires Version 6.10 or later of SAS.


The macro uses PROC FREQ to calculate the values of Pearson and Likelihood Ratio Chi-squares for the given data. These values are then used to calculate the non-centrality value of the Chi-square distribution, and power is calculated as
power = 1 - probchi(cinv(1-alpha,df), df, noncent);


powerrxc is a macro program. Values must be supplied for the ROW= and COL= arguments.

The arguments may be listed within parentheses in any order, separated by commas. For example:

   %powerrxc(data=inputdataset, row=age, col=improved, ..., )


Default values are shown after the name of each parameter.
Specifies the SAS data set to be analyzed. If the DATA= option is not supplied, the most recently created SAS data set is used.
REQUIRED. Specifies the variable defining the rows of the table.
REQUIRED. Specifies the variable defining the columns of the table.
Specifies a variable containing the cell counts of the table. Omit this option if each observation in the DATA= data set represents only a single entry in the table. This variable, if specified, is used on the WEIGHT statement in PROC FREQ.
Specifies the significance level of the test.
NRANGE= Specifies the sample size or list of sample sizes for which approximate power is to be computed. If omitted, the actual sample size is used. You may specify a list of values separated by commas, a range of the form x TO y BY z, or a combination of these. However, you must surround the NRANGE= value with %STR() if any commas appear in it. For example,
nrange=20 to 200 by 20
nrange=%str(10, 20, 50 to 100 by 10)
FREQOPT= Specifies options for PROC FREQ. Default=NOROW NOCOL NOPERCENT.
OUT= Specifies the name of the output dataset.


The FREQ procedure prints the table and related chi-square statistics. Following this, the macro prints the approximate power of the Pearson chi-square test and the Likelihood Ratio chi-square test for range of sample sizes requested. For example:
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
            30      0.07393       0.07650
            40      0.08241       0.08592
            50      0.09111       0.09562
            60      0.10003       0.10558
            70      0.10916       0.11577
            80      0.11847       0.12619
            90      0.12797       0.13681
            100      0.13763       0.14762


From Example 3 in the FREQ procedure chapter. Note that each observation is a cell count instead of a single entry, so a count variable (FREQ) is created to hold the cell counts. The observed sample size is used for computing approximate power.
%include macros(powerrxc);        *-- or include in an autocall library;
data a;
do row=1 to 2; do col=0,1;
	input freq @@; output;
end; end; cards;
3 11
6 2

%powerRxC(row=row, col=col, count=freq)
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. The cell probabilities (e.g., .315 = .63 * .5) are entered as the value of the COUNT= variable.
data c; 
	do row=1 to 2; do col=0,1;
		input freq @@; 
	end; end; 
.315 .185 
.285 .215

%powerRxC(data=c, row=row, col=col, count=freq, 
			nrange=%str(20,50 to 200 by 50))

See also

csmpower Power estimation for Covariance Structure Models
fpower Power computations for ANOVA designs
mpower Retrospective power analysis for multivariate GLMs
power Power calculations for general linear models