2
$\begingroup$

I have the following problem: given a proportion $p_1=\frac{X_1}{n}$, where $X_1$ is the number of succesful outcomes in $n$ tries ($X_1$ and $n$ are both > 100), I have to find the smallest proportion $p_2$ that is greater than and statistically different from $p_1$ at a given confidence level (e.g. 95%). An application of this would be to find out a success rate (i.e., $X_2$ successes in $n$ tries) that would ensure that a given enhancement to a system would actually be beneficial.

I could find the confidence interval for $p_1$ but merely having $p_2$ outside this interval wouldn't be enough to assure these proportions would be different. Doubling the interval didn't seem right either.

I also tried using the formulas for the confidence interval for the difference of proportions

$c = p\mp z\cdot s_p$

where $p = p_1-p_2$ is the difference between the proportions and $s_p$ is given by

$s_p = \sqrt{\frac{p_1(1-p_1)+p_2(1-p_2)}{n}}$

but I couldn't figure out how to get $p_2$ from them. Any hints on how I might proceed?

For what it's worth, this is not homework, but a slightly reworded problem from a book I'm using for self-study.

EDIT: Glen's answer put me in the right direction. It also occurred to me to brute force a solution, posted below.

$\endgroup$
  • $\begingroup$ "a slightly reworded problem from a book I'm using for self-study" ... which sounds like it might still count as worthy of the self-study tag. (take a look and decide for yourself) $\endgroup$ – Glen_b Apr 14 '14 at 4:05
  • $\begingroup$ Your 'brute-force' answer at the end is a legitimate way of solving the problem. In practice, often all that's needed in practice is a fast numerical answer in this case, not an algebraic answer in every case. I also use such approaches to double check my algebra, or to guide my intuition. I encourage you to post it below as an answer, so that your question and answer stand on their own, as question and answer. $\endgroup$ – Glen_b Apr 14 '14 at 20:50
2
$\begingroup$

This is pretty straightforward.

Consider that framed in terms of a confidence interval you need an interval for $p_2-p_1$ to be all positive:

interval for difference of proportions all positive

In particular, you need the lower limit of the interval to be positive (that the rest is positive then follows automatically).

If we assume $n$ is large enough to apply the normal approximation, then the lower limit is $p_2 - p_1 - z_{1-\alpha/2}s_p$ and you need

$p_2 - p_1 - z_{1-\alpha/2}s_p >0\,$, or

$p_2 - p_1 - z_{1-\alpha/2}\sqrt{\frac{p_1(1-p_1)+p_2(1-p_2)}{n}}>0\,$.

Here $p_1$, $n$ and $z_{1-\alpha/2}$ are all known, so $p_2$ is the only variable.

Can you do it from there?


The algebra is doable, but if it gets too hard, one can simply use simple numerical calculation over a grid (and then find the zeroes) to identify the region that satisfies the conditions $p_2>p_1$ and $p_2 - p_1 - z_{1-\alpha/2}s_p >0\,$.

$\endgroup$
1
$\begingroup$

In addition to Glen's analytical approach, I also developed an iterative solution (kind of a brute force solution, actually). R snippet follows:

prop2 <- function(x1, n1, n2=n1, ascending=TRUE, conf.level=0.95) {
  p1 <- x1/n1
  start <- end <- 0
  if (ascending) {
    start <- round(p1*n2)+1
    end <- n2
  } else {
    start <- round(p1*n2)-1
    end <- 1
  }
  alpha <- 1-conf.level
  z <- qnorm(1-alpha/2)
  found <- FALSE
  for (x2 in start:end) {
    p2 <- x2/n2
    p <- p1-p2
    sp <- sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2)
    ci <- p + c(-1,1)*z*sp
    if ((ci[1] < 0 & ci[2] < 0) | (ci[1] > 0 & ci[2] > 0)) {
      cat(sprintf("x2=%d, p2=%f, ci=[%f ; %f]\n", x2, p2, ci[1], ci[2]))
      found <- TRUE
      break
    }
  }
  if (!found)
    cat("could not find answer\n")
}    

So, prop2(x1, n1) will show the values for $x_2$ and $p_2$ that solve the problem. With ascending=FALSE, it finds the largest $p_2$ that is less than and statistically different from $p_1$. It also works for $n_2\not= n_1$, and for any confidence level (just set conf.level).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.