Proportion Difference Interval

## Description

Here, we will generate a confidence interval for the difference between two population proportions, using the formula

(1)
\begin{align} (\hat{p}_1 - \hat{p}_2) \pm z^* \sqrt{\frac{\hat{p}_1(1 - \hat{p}_1)}{n_1} + \frac{\hat{p}_2(1 - \hat{p}_2)}{n_2}} \end{align}

## Sage Cell

#### Code

p1 <- .52
p2 <- .47
n1 <- 245
n2 <- 234
conf.level <- .95
z <- qnorm(conf.level + (1 - conf.level)/2)
lower <- (p1 - p2) - z * sqrt((p1 * (1 - p1))/n1 + (p2 * (1 - p2))/n2)
upper <- (p1 - p2) + z * sqrt((p1 * (1 - p1))/n1 + (p2 * (1 - p2))/n2)
paste(lower, upper)

## Options

#### For repeated calculations, we can define a function to save time.

twoPropInterval <- function(p1, p2, n1, n2, conf.level) {
z <- qnorm(conf.level + (1 - conf.level)/2)
lower <- (p1 - p2) - z * sqrt((p1 * (1 - p1))/n1 + (p2 * (1 - p2))/n2)
upper <- (p1 - p2) + z * sqrt((p1 * (1 - p1))/n1 + (p2 * (1 - p2))/n2)
a <- c(lower, upper)
return(a)
}

twoPropInterval(.52, .47, 245, 234, .95)

## Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

## Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.