4

I would like to solve for $\pi_1$ in equation 7.14 of Hayes and Moulton's Cluster Randomized Trials. I can't for the life of me remember how to do so. Here is a link to the equation. $$ c = 2\;+\;(z_{\alpha/2}+z_{\beta})^2\frac{\pi_0(1-\pi_0)/m\;+\;\pi_1(1-\pi_1)/m\;+\;k_m^2(\pi_0^2+\pi_1^2)}{(\pi_0-\pi_1)^2} \tag{7.14} $$
Here is the R script I wrote to calculate c as shown in equation 7.14:

# inputs
arms  <-  2
alpha <-  0.05
tails <-  1
power <-  0.80
m     <- 50        # observations per cluster
p0    <-  0.40     # true proportion in absence of treatment
p1    <-  0.60     # true proportion in presence of treatment
km    <-  0.25     # between-cluster coefficient of variation within strata

num   <- (p0*(1-p0)/m)  +  (p1*(1-p1)/m)  +  (km^2*(p0^2+p1^2))
denom <- (p0 - p1)^2

x <- num/denom
c <- 2 + ( abs(qnorm(alpha/tails)) + qnorm(power) )^2*x

Could anyone help me to re-write this to calculate p1 given c and all of the other variables? I'd be happy with a written formula that I can code if someone wants to help but not in R.

gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
eg_23611
  • 39
  • 1
  • 1
    @whuber is right, this is a quadratic equation in $\pi_1$. So it's just a matter of rearranging the terms properly. – StasK Feb 17 '15 at 18:13

1 Answers1

-1

Via Wolfram Alpha (I renamed the variables from first equation to save space):

a <- abs(qnorm(alpha/tails))
b <- qnorm(power)
x <- p0
c <- c.arm
k <- km
p1 <- (-sqrt((a^2+2*a*b+b^2+2*c*m*x-2*m*x)^2 - 
             4*(a^2*k^2*m-a^2+2*a*b*k^2*m-2*a*b+b^2*k^2*m-b^2-c*m+m) * 
             (a^2*k^2*m*x^2-a^2*x^2+a^2*x+2*a*b*k^2*m*x^2 -     
              2*a*b*x^2+2*a*b*x+b^2*k^2*m*x^2-b^2*x^2+b^2*x-c*m*x^2+m*x^2)) - 
             a^2-2*a*b-b^2-2*c*m*x+2*m*x) / 
             (2*(a^2*k^2*m-a^2+2*a*b*k^2*m-2*a*b+b^2*k^2*m-b^2-c*m+m))

Could be cleaned up.

gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
eg_23611
  • 39
  • 1
  • 5
    Because this is merely a quadratic equation for $\pi_1$, it can be cleaned up quite a bit! In fact, this expression is so complex it would take more time to check that you entered the equation correctly into Wolfram Alpha than to solve it in the first place. – whuber Dec 11 '14 at 23:51