Mean Difference Interval

Description

Here, we will generate a confidence interval for the difference of two population means using the formula

(1)
\begin{align} (\bar{x}_1 - \bar{x}_2) \pm z^* \sqrt{\frac{\sigma_1}{n_1} + \frac{\sigma_2}{n_2}} \end{align}

Sage Cell

Code

x1 <- 15
x2 <- 17
n1 <- 210
n2 <- 190
st1 <- 2.2
st2 <- 1.8
conf.level <- .95
z <- qnorm(conf.level + (1 - conf.level)/2)
lower <- (x1 - x2) - z*sqrt(st1^2/n1 + st2^2/n2)
upper <- (x1 - x2) + z*sqrt(st1^2/n1 + st2^2/n2)
paste(lower, upper)

Options

Defining a Function

To save time for repeated calculations, we can define a function to calculate the interval.

twoMeanInterval <- function(x1, x2, st1, st2, n1, n2, conf.level) {
    z <- qnorm(conf.level + (1 - conf.level)/2)
    lower <- (x1 - x2) - z*sqrt(st1^2/n1 + st2^2/n2)
    upper <- (x1 - x2) + z*sqrt(st1^2/n1 + st2^2/n2)
    a <- c(lower, upper)
    return(a)
}

twoMeanInterval(15, 17, 2.2, 1.8, 210, 190, .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: 07 Jul 2019 22:54

Submitted by: Zane Corbiere

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