Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Sample size for equivalence trials in Stata

From   Philip Ryan <>
Subject   st: Sample size for equivalence trials in Stata
Date   Sun, 09 Feb 2003 00:38:29 +1030

Paul O'Brien wrote:

Can I calculate the sample size for an equivalence trial with binary

Can't find it with search.



This little program might help. There are no error traps and no help file but comments embedded in the program tell the story. -equivsize-, in *very* limited testing, appears to give the same answers as the commercial program nQuery Advisor 4 (2000, Statistical Solutions, Cork).

================ begin equivsize.ado ===============

prog def eqs, rclass
*! Phil Ryan v0.02 2002-02-06
*! program to calculate sample size for 1-sided equivalence test of 2
*! proportions assuming equal number in groups & using normal approximation
*! syntax: equivsize <p0> <p1> <eqdiff> <alpha> <power>
*! p0 is the prop'n of successes with existing, standard treatment. eg: 0.3
*! p1 is the prop'n of successes with the new treatment. eg: 0.3
*! p0 and p1 are most often hypothesised (under Ha) as being equal.
*! eqdiff is the difference between treatment successes which, if exceeded,
*! will support the null hypothesis of non-equivalence. It is important
*! to get the sign (+/-) of this right. eg: -0.1 means that the proportion
*! of successes with the new treatment is 10% less than with the standard
*! treatment (and if it were any worse we would reject equivalence).
*! alpha is the *1-sided* significance level, the probability of rejecting
*! the null hypothesis (Ho) of a difference in proportions, when there is
*! a difference at least as great as eqdiff. eg: 0.05
*! power is the probability that your test will reject the null hypothesis
*! of non-equivalence when the alternative hypothesis of equivalence is
*! true. eg: 0.8, 0.9

version 7
if "`1'" == "" {
which equivsize
args p0 p1 eqdiff alpha power
local q0 = 1-`p0'
local q1 = 1-`p1'
local expdiff = `p1'-`p0'
local zalpha = invnorm(1-`alpha')
local zbeta = invnorm(`power')

return scalar n = round((0.5+(((`zalpha'+`zbeta')/ /*
*/ (`expdiff'-`eqdiff'))^2) * /*
*/ ((`p0'*`q0')+(`p1'*`q1'))),1)

display as result _new " n (per group) = " return(n)

ret scalar p0 = `p0'
ret scalar p1 = `p1'
ret scalar eqdiff = `eqdiff'
ret scalar alpha = `alpha'
ret scalar power = `power'


==================== end equivsize.ado =========================


What sample size is required to demonstrate that a new treatment's efficacy is not worse than 10% less than a standard treatment's, given the standard treatment has a 30% success rate, and we require a power of 90% and a Type 1 error of 5%? Note this is one-sided, so that if the new treatment were in fact better than the old, we would not care (in the sense that we would still claim equivalence.)

Our p1 (the second argument of -equivsize- representing the expected efficacy of the new treatment under the alternative hypothesis of equivalence) is also 0.3.

. equivsize .3 .3 -.1 .05 .9
n(per group) = 360

If we had reason to believe that the new treatment was in fact somewhat less successful than the old but we still wanted the equivalence criterion to be within 0.1 (on the side of new worse than old) we might expect the required sample size to increase, since, a priori, things are getting more difficult to discriminate. Say a pilot study gave evidence that the new treatment was 5% less successful than the old, but we still wish to test for equivalence as before:

. equivsize .3 .25 -.1 .05 .9
n(per group) = 1362

Remember this simple program uses normal approximations, so when dealing with proportions less than about 0.2 you are on shaky ground.

As usual, watch for wrap-around problems if you cut and paste this from your mailer.


Philip Ryan
Associate Professor
Department of Public Health
Medical School
University of Adelaide
Adelaide 5005
South Australia

tel: +61 8 83033570
fax: +61 8 82234075

* For searches and help try:

© Copyright 1996–2019 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index