UCLA Academic Technology Services HomeServicesClassesContactJobs

Stata FAQ
How can I compute power for contingency tables in Stata?

There are many different programs that will compute power for contingency tables including online power calculators. This FAQ page will show you how to compute contingency table power using a Stata program called chi2power. You can download this program within Stata by typing the command, findit chi2power, and following the instructions.

The chi2power programs takes advantage of the fact that the observed likelihood-ratio chi-square statistic can be used as an estimate of a noncentrality parameter parameter for a noncentral chi-square distribution. The noncentral chi-square distribution is the distribution under the alternative hypothesis. To see how this works, consider a 2-by-2 contingency table with a likelihood-ratio chi-square value of 4.6. The critical value of chi-square for 2-by-2 table with one degree of freedom is 3.84. Using the nchi2() function, which gives the cumulative noncentral chi-squared distribution, we can compute the power as follows.

display 1 - nchi2(1, 4.6, 3.84)

.57347213
This calculates a power of about .57. Notice that we haven't mentioned anything about the sample size. Say we double the sample size but multiplying each cell frequency by two. All of the cell proportions will remain the same but the chi-square value will double. Meaning, of course, that the noncentrality parameter is doubled. Here is what the power looks like if the sample size is doubled obtained by multiplying the noncentrality parameter by 2.

display 1 - nchi2(1, 2*4.6, 3.84)

.85848997
Doubling the sample size has increased the power to about .86. This means that we can get the power for any multiple of the sample size by multiplying the noncentrality parameter by a sample size factor. The chi2power program computes noncentrality for varying sample size factors to come up with estimates of power for the different sample sizes.

The chi2power command has a syntax that looks as follows:

chi2power [, Startf(#) Endf(#) Incr(#) Alpha(#) ]
You can run the command without any sample size factor options, in which case, it defaults the calculating the power of the current sample. You can also use the command with with only a sample size starting factor, startf(). Or, you can use both sample size starting and ending options, startf() and endf(), without an increment, in which case, the increment will default to 1. Finally, the full form of chi2power includes starting and ending factors as well as an increment option, incr().

To compute the prospective power for a 2-by-2 table we need to come up with some reasonably good guesses as to how the observations will be distributed among the cells of the contingency table. Let's say that we believe that the row variable will be split 70/30 between rows one and two. And further, within row one the split will be 50/50 while within row two the split will be 66/33. We can use tabi with frequencies taken from our guesses to compute a likelihood-ratio chi-square.

tabi 35 35 \ 20 10, row lrchi2

           |          col
       row |         1          2 |     Total
-----------+----------------------+----------
         1 |        35         35 |        70 
           |     50.00      50.00 |    100.00 
-----------+----------------------+----------
         2 |        20         10 |        30 
           |     66.67      33.33 |    100.00 
-----------+----------------------+----------
     Total |        55         45 |       100 
           |     55.00      45.00 |    100.00 

 likelihood-ratio chi2(1) =   2.3963   Pr = 0.122
This table has 100 observations with a likelihood-ratio chi-square of 2.396 and a p-value of .122. We can get the power of this analysis by using chi2power without any sample size factors.
chi2power

alpha = .05
sample size factor = 1.00 power = 0.3404 for n = 100
This shows that the power for the sample with our guesses is approximately .34.

Now, let's see what happens to the power when we multiple each cell frequency by 2.

tabi 70 70 \ 40 20, row lrchi2

           |          col
       row |         1          2 |     Total
-----------+----------------------+----------
         1 |        70         70 |       140 
           |     50.00      50.00 |    100.00 
-----------+----------------------+----------
         2 |        40         20 |        60 
           |     66.67      33.33 |    100.00 
-----------+----------------------+----------
     Total |       110         90 |       200 
           |     55.00      45.00 |    100.00 

 likelihood-ratio chi2(1) =   4.7926   Pr = 0.029
 
chi2power

alpha = .05
sample size factor = 1.00 power = 0.5907 for n = 200
There are 200 observations and the power has increased to .5907. Let's go back and rerun the original tabi and view the power for samples sizes ranging from 100 to 500. To do this we will need to use sample size factors between 1 and 5.
chi2power, startf(1) endf(5)

alpha = .05
sample size factor = 1.00 power = 0.3404 for n = 100
sample size factor = 2.00 power = 0.5907 for n = 200
sample size factor = 3.00 power = 0.7646 for n = 300
sample size factor = 4.00 power = 0.8720 for n = 400
sample size factor = 5.00 power = 0.9334 for n = 500
First note that the power for the sample size of 200 is .5907 which is the same as when we doubled each of the cell frequencies. Also, the power for a sample of 300 is about .76 while for 400 it is about .87. We can refine this estimate by starting with a sample size factor of three and using an increment of .1. We will use the following abbreviations, s for startf, e for endf and i for incr.
chi2power, s(3) e(4) i(.1)

alpha = .05
sample size factor = 3.00 power = 0.7646 for n = 300
sample size factor = 3.10 power = 0.7780 for n = 310
sample size factor = 3.20 power = 0.7908 for n = 320
sample size factor = 3.30 power = 0.8029 for n = 330
sample size factor = 3.40 power = 0.8144 for n = 340
sample size factor = 3.50 power = 0.8254 for n = 350
sample size factor = 3.60 power = 0.8358 for n = 360
sample size factor = 3.70 power = 0.8456 for n = 370
sample size factor = 3.80 power = 0.8549 for n = 380
sample size factor = 3.90 power = 0.8637 for n = 390
sample size factor = 4.00 power = 0.8720 for n = 400
We now see that around a sample size of 330 the power for the likelihood-ratio chi-square test will be about .80, which is the standard for many research studies.

All of the above results used the default alpha of .05. If we change alpha to be .01 the power will go down as shown in the next example.

chi2power, s(3) e(4) i(.1) alpha(.01)

alpha = .01
sample size factor = 3.00 power = 0.5420 for n = 300
sample size factor = 3.10 power = 0.5595 for n = 310
sample size factor = 3.20 power = 0.5766 for n = 320
sample size factor = 3.30 power = 0.5934 for n = 330
sample size factor = 3.40 power = 0.6097 for n = 340
sample size factor = 3.50 power = 0.6256 for n = 350
sample size factor = 3.60 power = 0.6411 for n = 360
sample size factor = 3.70 power = 0.6561 for n = 370
sample size factor = 3.80 power = 0.6707 for n = 380
sample size factor = 3.90 power = 0.6848 for n = 390
sample size factor = 4.00 power = 0.6985 for n = 400
Next, let's try an example that invovles a 3-by-3 table. We will use the hsbdemo data set.
use http://www.ats.ucla.edu/stat/data/hsbdemo, clear

tab ses prog, row lrchi2

           |         type of program
       ses |   general   academic   vocation |     Total
-----------+---------------------------------+----------
       low |        16         19         12 |        47 
           |     34.04      40.43      25.53 |    100.00 
-----------+---------------------------------+----------
    middle |        20         44         31 |        95 
           |     21.05      46.32      32.63 |    100.00 
-----------+---------------------------------+----------
      high |         9         42          7 |        58 
           |     15.52      72.41      12.07 |    100.00 
-----------+---------------------------------+----------
     Total |        45        105         50 |       200 
           |     22.50      52.50      25.00 |    100.00 

 likelihood-ratio chi2(4) =  16.7830   Pr = 0.002
The large chi-square and small p-value suggests that the power will be quite high so we will run the chi2power command starting with a sample size factor of .2 with increments of .1.
chi2power, s(.2) e(1) i(.1)

alpha = .05
sample size factor = 0.20 power = 0.2710 for n = 40
sample size factor = 0.30 power = 0.3988 for n = 60
sample size factor = 0.40 power = 0.5205 for n = 80
sample size factor = 0.50 power = 0.6285 for n = 100
sample size factor = 0.60 power = 0.7194 for n = 120
sample size factor = 0.70 power = 0.7928 for n = 140
sample size factor = 0.80 power = 0.8501 for n = 160
sample size factor = 0.90 power = 0.8935 for n = 180
sample size factor = 1.00 power = 0.9256 for n = 200
A power of approximately .8 is associated with a sample size of 140. This is not necessarily the most useful information considering that our data set has 200 observations but if we had started with a pilot sample of size 40 then the information would be useful in planning a full study.

Reference

Satorra, A. and Sarris, W.E. 1985. Power of the likelihood ratio test in covariance structure analysis. Psychometrica, 50: 83-90.


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.