Population Proportion Interval

Description

Here, we will generate a confidence interval for a population proportion using the formula

(1)
\begin{align} \hat{p}\pm z^* \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}} \end{align}

where $\hat{p}$ is the sample proportion, $n$ is the sample size and $z^*$ is the positive z-score corresponding to the desired confidence level.

Sage Cell

Note that paste is used to return the results, not print. In R, print is a difficult to use generic function, and so paste can be used for intuitive, python-style printing.

Code

n <- 200
phat <- .62
conflevel <- .95
zstar <- qnorm(conflevel + (1 - conflevel)/2)

lower <- phat - zstar * sqrt((phat * (1 - phat))/n)
upper <- phat + zstar * sqrt((phat * (1 - phat))/n)
paste("(", lower, " , ", upper, ")")

Options

Defining a function for generating a confidence interval

Using the function method, we can define a function to generate a confidence interval for a population proportion.

Code

propInterval <- function(n, phat, conf.level) {
    zstar <- qnorm(conf.level + (1 - conf.level)/2)
    lower <- phat - zstar * sqrt((phat * (1 - phat))/n)
    upper <- phat + zstar * sqrt((phat * (1 - phat))/n)
    return(c(lower, upper))
    }

propInterval(200, .62, .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.

Attribute

Permalink:

Author:

Date: 06 Jul 2019 20:15

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License