Skip to main content
moved solution to my own answer
Source Link
user43734
  • 113
  • 1
  • 1
  • 5

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. 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 with $n_2\not= n_1$posted below.

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. 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 with $n_2\not= n_1$.

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.

added 1135 characters in body
Source Link
user43734
  • 113
  • 1
  • 1
  • 5

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. 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 with $n_2\not= n_1$.

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.

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. 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 with $n_2\not= n_1$.

Added [tag:self-study] tag.
Link
user43734
  • 113
  • 1
  • 1
  • 5
Source Link
user43734
  • 113
  • 1
  • 1
  • 5
Loading