#set document(title: "9.3 Two Proportion Z-Test and Confidence Interval", author: "Rachel Webb") #set page(width: 8.5in, height: auto, margin: 1in) #import "@preview/cetz:0.5.2" #set text(font: ("STIX Two Text", "Libertinus Serif", "New Computer Modern"), size: 10.5pt, lang: "en") #show math.equation: set text(font: ("STIX Two Math", "New Computer Modern Math")) #set par(justify: true, leading: 0.62em, spacing: 0.9em) #set enum(spacing: 1.1em) // room between list items so tall inline fractions don't collide #set list(spacing: 1.1em) #set table(stroke: 0.5pt + rgb("#c7ccd3")) #let BLUE = rgb("#183B6F") // brand navy — section bars + example/solution labels (white on navy 11.09:1) #let ORANGE = rgb("#A94509") // brand primary-700 — AA-safe deep orange for TEXT (5.93:1 on white; raw brand #F37021 is 2.94:1 and must never carry text) #let RED = rgb("#DC2626") // brand error-600 #let GREEN = rgb("#059669") // brand success-600 (decoration only; small green text uses green-text #007942) #show heading.where(level: 1): it => block(width: 100%, above: 0pt, below: 16pt, fill: gradient.linear(BLUE, rgb("#2C5AA0")), inset: (x: 14pt, y: 12pt), radius: 3pt, text(fill: white, weight: "bold", size: 19pt, it.body)) #show heading.where(level: 2): it => block(width: 100%, above: 18pt, below: 10pt, fill: BLUE, inset: (x: 10pt, y: 6pt), radius: 2pt, text(fill: white, weight: "bold", size: 12pt, it.body)) #show heading.where(level: 3): it => text(fill: ORANGE, weight: "bold", size: 12.5pt, it.body) #show heading.where(level: 4): it => text(fill: BLUE, weight: "bold", size: 10.5pt, it.body) #let examplebox(label, title, body) = block(width: 100%, breakable: true, fill: rgb("#EFF1F5"), stroke: 0.5pt + rgb("#CFDDF0"), radius: 4pt, inset: 10pt, above: 12pt, below: 12pt)[ #block(below: 6pt)[#box(fill: BLUE, inset: (x: 6pt, y: 2pt), radius: 2pt, text(fill: white, weight: "bold", size: 8.5pt, label)) #h(0.4em) #strong[#title]] #body] // rail = decorative left rule (raw brand token); labelcolor = AA-safe label text shade #let notebox(label, rail, labelcolor, tint, body) = block(width: 100%, breakable: true, fill: tint, stroke: (left: 3pt + rail), inset: (left: 10pt, rest: 8pt), radius: (right: 4pt), above: 11pt, below: 11pt)[ #text(fill: labelcolor, weight: "bold", size: 7.5pt, tracking: 0.5pt)[#upper(label)] #linebreak() #body] #let solutionbox(body) = block(above: 4pt, below: 8pt)[ #text(fill: BLUE, weight: "bold", size: 8.5pt)[Solution] #linebreak() #body] #let figph(msg) = block(width: 100%, height: 60pt, fill: rgb("#f6f7f9"), stroke: (paint: rgb("#c7ccd3"), dash: "dashed"), radius: 4pt, inset: 10pt)[ #align(center + horizon, text(fill: rgb("#889"), style: "italic", size: 9pt, msg))] // Standardize inlined figure sizes: measure the natural CeTZ canvas, then scale to a // consistent envelope (aspect-aware; see build_typst.py FIG_* constants). Unlike the // print preamble, dimensions are FLOORED: in an editor a user can trim a figure to a // degenerate 1-D shape (a bare line), and w/h or tw/w would then divide by zero. #let _STD_W = 3.5 #let _WIDE_W = 5.6 #let _MAX_H = 3.4 #let _ASPECT_WIDE = 2.2 #let _UPSCALE_MAX = 1.15 #let stdfig(body) = context { let m = measure(body) let w = calc.max(m.width / 1in, 0.01) let h = calc.max(m.height / 1in, 0.01) let tw = if w / h > _ASPECT_WIDE { _WIDE_W } else { _STD_W } let s = calc.min(tw / w, _MAX_H / h, _UPSCALE_MAX) align(center, box(scale(x: s * 100%, y: s * 100%, reflow: true, body))) } #show figure: set block(breakable: false) #set figure(gap: 8pt) #show figure.caption: set text(size: 8.5pt, fill: rgb("#555")) == 9.3#h(0.6em)Two Proportion Z-Test and Confidence Interval This section will look at how to analyze a difference in the proportions for two independent samples. As with all other hypothesis tests and confidence intervals, the process of testing is the same, though the formulas and assumptions are different. There are three types of hypothesis tests for comparing the difference in 2 population proportions #emph[p]#sub[1] – #emph[p]#sub[2], see Figure 9-7. #figure(figph[Table of the three hypothesis setups for two proportions: two-tailed with H0: p1 = p2 and H1: p1 ≠ p2, right-tailed with H1: p1 \> p2, and left-tailed with H1: p1 \< p2, each with a normal curve shaded in both tails, the right tail, or the left tail, and the equivalent difference forms H0: p1 - p2 = 0 with H1: p1 - p2 ≠ 0, \> 0, or \< 0.], alt: "Table of the three hypothesis setups for two proportions: two-tailed with H0: p1 = p2 and H1: p1 ≠ p2, right-tailed with H1: p1 > p2, and left-tailed with H1: p1 < p2, each with a normal curve shaded in both tails, the right tail, or the left tail, and the equivalent difference forms H0: p1 - p2 = 0 with H1: p1 - p2 ≠ 0, > 0, or < 0.", caption: [Figure 9-7]) Note that for our purposes, #emph[p#sub[1]] – #emph[p#sub[2]] = 0. We could also use a variant of this model to test for a magnitude difference for when #emph[p#sub[1]] – #emph[p#sub[2]] ≠ 0, but we will not cover that scenario. #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ The z-test is a statistical test for comparing the proportions from two populations. It can be used when the samples are independent, #math.equation(block: false, alt: "n sub 1 p hat sub 1")[$n_(1) hat(p)_(1)$] ≥ 10, #math.equation(block: false, alt: "n sub 1 q hat sub 1")[$n_(1) hat(q)_(1)$] ≥ 10, #math.equation(block: false, alt: "n sub 2 p hat sub 2")[$n_(2) hat(p)_(2)$] ≥ 10, and #math.equation(block: false, alt: "n sub 2 q hat sub 2")[$n_(2) hat(q)_(2)$] ≥ 10. The formula for the z-test statistic is: #math.equation(block: true, alt: "z equals the fraction open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis minus open parenthesis p sub 1 minus p sub 2 close parenthesis over the square root of open parenthesis p hat times q hat open parenthesis the fraction 1 over n sub 1 plus the fraction 1 over n sub 2 close parenthesis close parenthesis")[$z = frac(( hat(p)_(1) − hat(p)_(2) ) − ( p_(1) − p_(2) ), sqrt(( hat(p) · hat(q) ( frac(1, n_(1)) + frac(1, n_(2)) ) )))$] Where #math.equation(block: false, alt: "p hat equals the fraction open parenthesis x sub 1 plus x sub 2 close parenthesis over open parenthesis n sub 1 plus n sub 2 close parenthesis equals the fraction open parenthesis p hat sub 1 times n sub 1 plus p hat sub 2 times n sub 2 close parenthesis over open parenthesis n sub 1 plus n sub 2 close parenthesis , q hat equals 1 minus p hat , p hat sub 1 equals the fraction x sub 1 over n sub 1 , p hat sub 2 equals the fraction x sub 2 over n sub 2")[$hat(p) = frac(( x_(1) + x_(2) ), ( n_(1) + n_(2) )) = frac(( hat(p)_(1) · n_(1) + hat(p)_(2) · n_(2) ), ( n_(1) + n_(2) )) , #h(1em) hat(q) = 1 − hat(p) , #h(1em) hat(p)_(1) = frac(x_(1), n_(1)) , hat(p)_(2) = frac(x_(2), n_(2))$]. ] The pooled proportion #math.equation(block: false, alt: "p hat")[$hat(p)$] is a weighted mean of the proportions and #math.equation(block: false, alt: "q hat")[$hat(q)$] is the complement of #math.equation(block: false, alt: "p hat")[$hat(p)$]. Some texts or software may use different notation for the pooled proportion, note that #math.equation(block: false, alt: "p hat equals p bar")[$hat(p) = overline(p)$]. #examplebox("Example 1")[][ A vice principal wants to see if there is a difference between the number of students who are late to class for the first class of the day compared to the student’s class right after lunch. To test their claim to see if there is a difference in the proportion of late students between first and after lunch classes, the vice-principal randomly selects 200 students from first class and records if they are late, then randomly selects 200 students in their class after lunch and records if they are late. At the 0.05 level of significance, can a difference be concluded? #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Both ways to finish the two-proportion test] The first link is the book's invNorm(0.025,0,1), giving the critical pair +/-1.96 that z = -0.5784 sits comfortably inside. The second link finishes the same test the p-value way: the area left of -0.5784 is 0.2815, doubled 0.5630, far above alpha = 0.05 -- same decision, and the same 1.96 builds the 95% interval that follows. - invNorm(0.025,0,1) = -1.96 - P(Z \< -0.5784) = 0.2815, doubled = 0.5630 ] First Class After Lunch Class Sample Size 200 200 Number of late students 13 16 #solutionbox[ Assumptions: We are comparing the proportion of late students’ first and after lunch classes. The number of “successes” and “failures” from each population must be greater than 10 ( = 13 ≥ 10, = 187 ≥ 10, = 16 ≥ 10, and = 184 ≥ 10). We must assume that the samples were independent. Using the Traditional Method The claim is that there is a difference between the proportion of late students. Let population 1 be the first class, and population 2 be the class after lunch. Our claim would then be #emph[p#sub[1]] ≠ #emph[p#sub[2]]. The correct hypotheses are: H0: #emph[p#sub[1]] = #emph[p#sub[2]] H1: #emph[p#sub[1]] ≠ #emph[p#sub[2]]. Compute the #math.equation(block: false, alt: "z sub α / 2")[$z_(α / 2)$] critical values. Draw and label the sampling distribution. Use the inverse normal function invNorm(0.025,0,1) to get #math.equation(block: false, alt: "z sub α / 2")[$z_(α / 2)$] = ±1.96. See Figure 9-8. #figure(figph[Standard normal curve with both tails shaded beyond the critical values -1.96 and 1.96, marking the two-tailed rejection regions.], alt: "Standard normal curve with both tails shaded beyond the critical values -1.96 and 1.96, marking the two-tailed rejection regions.", caption: [Figure 9-8]) In order to compute the test statistic, we must first compute the following proportions: \\(\\begin{array}{ll} #linebreak() \\hat{p}=\\frac{\\left(x\_{1}+x\_{2}\\right)}{\\left(n\_{1}+n\_{2}\\right)}=\\frac{(13+16)}{(200+200)}=0.0725 & \\hat{q}=1-\\hat{p}=1-0.0725=0.9275 \\\\ #linebreak() \\hat{p}\_{1}=\\frac{x\_{1}}{n\_{1}}=\\frac{13}{200}=0.065 & \\hat{p}\_{2}=\\frac{x\_{2}}{n\_{2}}=\\frac{16}{200}=0.08 #linebreak() \\end{array}\\) The test statistic is, #math.equation(block: false, alt: "z equals the fraction open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis minus open parenthesis p sub 1 minus p sub 2 close parenthesis over the square root of open parenthesis p hat times q hat open parenthesis the fraction 1 over n sub 1 plus the fraction 1 over n sub 2 close parenthesis close parenthesis equals the fraction open parenthesis 0.065 minus 0.08 close parenthesis over the square root of open parenthesis 0.0725 times 0.9275 open parenthesis the fraction 1 over 200 plus the fraction 1 over 200 close parenthesis close parenthesis equals minus 0.5784")[$z = frac(( hat(p)_(1) − hat(p)_(2) ) − ( p_(1) − p_(2) ), sqrt(( hat(p) · hat(q) ( frac(1, n_(1)) + frac(1, n_(2)) ) ))) = frac(( 0.065 − 0.08 ), sqrt(( 0.0725 · 0.9275 ( frac(1, 200) + frac(1, 200) ) ))) = − 0.5784$]. Decision: Because the test statistic is between the critical values, we do not reject H#sub[0]. Summary: There is not enough evidence to support any difference in the proportion of students that are late for their first class compared to the class after lunch. #strong[TI-84:] Press the \[STAT\] key, arrow over to the \[TESTS\] menu, arrow down to the option \[6:2-PropZTest\] and press the \[ENTER\] key. Type in the x#sub[1], n#sub[1], x#sub[2], and n#sub[2] arrow over to the #math.equation(block: false, alt: "not equal to")[$≠$], \<, \> sign that is the same in the problem’s alternative hypothesis statement, then press the \[ENTER\] key, arrow down to \[Calculate\] and press the \[ENTER\] key. The calculator returns the z-test statistic and the p-value. #figure(figph[TI-84 screens for a 2-PropZTest: the TESTS menu highlights 6:2-PropZTest, the input shows x1: 13, n1: 200, x2: 16, n2: 200 with p1 ≠ p2 selected, and the output shows z = -0.5784, p = 0.5630, sample proportions 0.065 and 0.08, and pooled proportion 0.0725.], alt: "TI-84 screens for a 2-PropZTest: the TESTS menu highlights 6:2-PropZTest, the input shows x1: 13, n1: 200, x2: 16, n2: 200 with p1 ≠ p2 selected, and the output shows z = -0.5784, p = 0.5630, sample proportions 0.065 and 0.08, and pooled proportion 0.0725.", caption: none) #strong[TI-89:] Go to the \[Apps\] #strong[Stat/List Editor], then press \[2#super[nd]\] then F6 \[Tests\], then select #strong[6: 2-PropZTest]. Type in the x#sub[1], n#sub[1], x#sub[2], and n2 arrow over to the #math.equation(block: false, alt: "not equal to")[$≠$], \<, \> and select the sign that is the same in the problem’s alternative hypothesis statement. Press the \[ENTER\] key to calculate. The calculator returns the z-test statistic, sample proportions, pooled proportion, and the p-value. #figure(figph[TI-89 screens for a 2-Proportion Z Test: the Tests menu highlights 6:2-PropZTest, the dialog lists Successes x1: 13, n1: 200, x2: 16, n2: 200 with alternate hypothesis p1 ≠ p2, and the output shows z = -0.578449, p-value 0.562961, sample proportions 0.065 and 0.08, and pooled proportion 0.0725.], alt: "TI-89 screens for a 2-Proportion Z Test: the Tests menu highlights 6:2-PropZTest, the dialog lists Successes x1: 13, n1: 200, x2: 16, n2: 200 with alternate hypothesis p1 ≠ p2, and the output shows z = -0.578449, p-value 0.562961, sample proportions 0.065 and 0.08, and pooled proportion 0.0725.", caption: none) ] ] #strong[Two Proportions Z-Interval] #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ A 100(1 – #math.equation(block: false, alt: "α")[$α$])% confidence interval for the difference between two population proportions p#sub[1] – p#sub[2]: #math.equation(block: true, alt: "open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis minus z sub α / 2 the square root of open parenthesis the fraction p hat sub 1 q hat sub 1 over n sub 1 plus the fraction p hat sub 2 q hat sub 2 over n sub 2 close parenthesis less than p sub 1 minus p sub 2 less than open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis plus z sub α / 2 the square root of open parenthesis the fraction p hat sub 1 q hat sub 1 over n sub 1 plus the fraction p hat sub 2 q hat sub 2 over n sub 2 close parenthesis")[$( hat(p)_(1) − hat(p)_(2) ) − z_(α / 2) sqrt(( frac(hat(p)_(1) hat(q)_(1), n_(1)) + frac(hat(p)_(2) hat(q)_(2), n_(2)) )) < p_(1) − p_(2) < ( hat(p)_(1) − hat(p)_(2) ) + z_(α / 2) sqrt(( frac(hat(p)_(1) hat(q)_(1), n_(1)) + frac(hat(p)_(2) hat(q)_(2), n_(2)) ))$] Or more compactly as #math.equation(block: false, alt: "open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis ± z sub α / 2 the square root of open parenthesis the fraction p hat sub 1 q hat sub 1 over n sub 1 plus the fraction p hat sub 2 q hat sub 2 over n sub 2 close parenthesis")[$( hat(p)_(1) − hat(p)_(2) ) ± z_(α / 2) sqrt(( frac(hat(p)_(1) hat(q)_(1), n_(1)) + frac(hat(p)_(2) hat(q)_(2), n_(2)) ))$] ] The requirements are identical to the 2-proportion hypothesis test. Note that the standard error does not rely on a hypothesized proportion so do not use a confidence interval to make decisions based on a hypothesis statement. #examplebox("Example 2")[][ Find the 95% confidence interval for the difference in the proportion of late students in their first class and the proportion who are late to their class after lunch. First Class After Lunch Class Sample Size 200 200 Number of late students 13 16 #solutionbox[ First, compute the following: #math.equation(block: true, alt: "p hat sub 1 equals the fraction x sub 1 over n sub 1 equals the fraction 13 over 200 equals 0.065 q hat sub 1 equals 1 minus p hat sub 1 equals 1 minus 0.065 equals 0.935")[$hat(p)_(1) = frac(x_(1), n_(1)) = frac(13, 200) = 0.065 #h(1em) hat(q)_(1) = 1 − hat(p)_(1) = 1 − 0.065 = 0.935$] #math.equation(block: true, alt: "p hat sub 2 equals the fraction x sub 2 over n sub 2 equals the fraction 16 over 200 equals 0.08 q hat sub 2 equals 1 minus p hat sub 2 equals 1 minus 0.08 equals 0.92")[$hat(p)_(2) = frac(x_(2), n_(2)) = frac(16, 200) #h(1em) = 0.08 #h(1em) hat(q)_(2) = 1 − hat(p)_(2) = 1 − 0.08 = 0.92$] Find the #math.equation(block: false, alt: "z sub α / 2")[$z_(α / 2)$] critical value. Use the inverse normal to get #math.equation(block: false, alt: "z sub α / 2")[$z_(α / 2)$] = 1.96. Now substitute the numbers into the interval estimate: #math.equation(block: false, alt: "open parenthesis p hat sub 1 minus p hat sub 2 close parenthesis ± z sub the fraction α over 2 the square root of open parenthesis the fraction p hat sub 1 q hat sub 1 over n sub 1 plus the fraction p hat sub 2 q hat sub 2 over n sub 2 close parenthesis")[$( hat(p)_(1) − hat(p)_(2) ) ± z_(frac(α, 2)) sqrt(( frac(hat(p)_(1) hat(q)_(1), n_(1)) + frac(hat(p)_(2) hat(q)_(2), n_(2)) ))$] \\(\\begin{aligned} #linebreak() &\\Rightarrow(0.065-0.08) \\pm 1.96 \\sqrt{\\left(\\frac{0.065 \\cdot 0.935}{200}+\\frac{0.08 \\cdot 0.92}{200}\\right)} \\\\ #linebreak() &\\Rightarrow \\quad-0.015 \\pm 0.0508 \\\\ #linebreak() &\\Rightarrow \\quad(-0.0508,0.0358) . #linebreak() \\end{aligned}\\) Use interval notation (–0.0508, 0.0358) or standard notation –0.0508 \< #emph[p#sub[1]] – #emph[p#sub[2]]\< 0.0358. Note that we can have negative numbers here since we are taking the difference of two proportions. Since p#sub[1] – p#sub[2]= 0 is in the interval, we are 95% confident that there is no difference in the proportion of late students between their first class or those who are late for their class after lunch. #strong[TI-84:] Press the \[STAT\] key, arrow over to the \[TESTS\] menu, arrow down to the option \[2-PropZInterval\] and press the \[ENTER\] key. Type in the x#sub[1], n#sub[1], x#sub[2], n#sub[2], the confidence level, then press the \[ENTER\] key, arrow down to \[Calculate\] and press the \[ENTER\] key. The calculator returns the confidence interval. #figure(figph[TI-84 screens for a 2-PropZInt: the TESTS menu highlights B:2-PropZInt, the input shows x1: 13, n1: 200, x2: 16, n2: 200 and C-Level 0.95, and the output gives the confidence interval (-0.0658, 0.0358) with sample proportions 0.065 and 0.08.], alt: "TI-84 screens for a 2-PropZInt: the TESTS menu highlights B:2-PropZInt, the input shows x1: 13, n1: 200, x2: 16, n2: 200 and C-Level 0.95, and the output gives the confidence interval (-0.0658, 0.0358) with sample proportions 0.065 and 0.08.", caption: none) #strong[TI-89:]Go to the \[Apps\]#strong[Stat/List Editor], then press \[2#super[nd]\] then F7 \[Ints\], then select #strong[6: 2-PropZInt]. Type in the x#sub[1], n#sub[1], x#sub[2], n#sub[2], the confidence level, then press the \[ENTER\] key to calculate. The calculator returns the confidence interval. ] ]