#set document(title: "10.10 Difference between Means", author: "OpenStax") #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")) == 10.10#h(0.6em)Difference between Means #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Prerequisites] Sampling Distribution of Difference between Means, Confidence Intervals, Confidence Interval on the Mean #linebreak() #linebreak() ] #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Learning Objectives] + State the assumptions for computing a confidence interval on the difference between means + Compute a confidence interval on the difference between means + Format data for computer analysis ] It is much more common for a researcher to be interested in the difference between means than in the specific values of the means themselves. We take as an example the data from the "#link("https://onlinestatbook.com/2/case_studies/animal_research.html")[Animal Research]" case study. In this experiment, students rated (on a 7-point scale) whether they thought animal research is wrong. The sample sizes, means, and variances are shown separately for males and females in Table 1. Table 1. Means and Variances in Animal Research study. #figure(table( columns: 4, align: left, inset: 6pt, table.header([Condition], [n], [Mean], [Variance]), [Females], [17], [5.353], [2.743], [Males], [17], [3.882], [2.985], )) As you can see, the females rated animal research as more wrong than did the males. This sample difference between the female mean of 5.35 and the male mean of 3.88 is 1.47. However, the gender difference in this particular sample is not very important. What is important is the difference in the #strong[population]. The difference in sample means is used to estimate the difference in population means. The accuracy of the estimate is revealed by a #strong[confidence interval]. In order to construct a confidence interval, we are going to make three assumptions: + The two populations have the same variance. This assumption is called the assumption of #strong[homogeneity of variance]. + The populations are #strong[normally distributed]. + Each value is sampled #strong[independently] from each other value. The consequences of violating these assumptions are discussed in a later section. For now, suffice it to say that small-to-moderate violations of assumptions 1 and 2 do not make much difference. A confidence interval on the difference between means is computed using the following formula: Lower Limit = M#sub[1] - M#sub[2] -(t#sub[CL])(#math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]) #linebreak() Upper Limit = M#sub[1] - M#sub[2] +(t#sub[CL])(#math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]) where M#sub[1] - M#sub[2] is the difference between sample means, t#sub[CL] is the t for the desired level of confidence, and #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$] is the estimated #strong[standard error] of the difference between sample means. The meanings of these terms will be made clearer as the calculations are demonstrated. We continue to use the data from the "Animal Research" case study and will compute a confidence interval on the difference between the mean score of the females and the mean score of the males. For this calculation, we will assume that the variances in each of the two populations are equal. The first step is to compute the estimate of the standard error of the difference between means (#math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]). Recall from the relevant section in the chapter on sampling distributions that the formula for the standard error of the difference in means in the population is: #linebreak() #linebreak() #math.equation(block: true, alt: "σ sub M sub 1 minus M sub 2 equals the square root of the fraction σ sub 1 squared over n sub 1 plus the fraction σ sub 2 squared over n sub 2 equals the square root of the fraction σ squared over n plus the fraction σ squared over n equals the square root of the fraction 2 σ squared over n")[$σ_(M_(1) − M_(2)) = sqrt(frac(σ_(1)^(2), n_(1)) + frac(σ_(2)^(2), n_(2))) = sqrt(frac(σ^(2), n) + frac(σ^(2), n)) = sqrt(frac(2 σ^(2), n))$] #linebreak() In order to estimate this quantity, we estimate σ#super[2] and use that estimate in place of σ#super[2]. Since we are assuming the population variances are the same, we estimate this variance by averaging our two sample variances. Thus, our estimate of variance is computed using the following formula: #math.equation(block: true, alt: "MSE equals the fraction s sub 1 squared plus s sub 2 squared over 2")[$"MSE" = frac(s_(1)^(2) + s_(2)^(2), 2)$] where MSE is our estimate of σ#super[2]. In this example, MSE = (2.743 + 2.985)/2 = 2.864. Note that MSE stands for "mean square error" and is the mean squared deviation of each score from its group's mean. Since n (the number of scores #emph[in each condition]) is 17, #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]=#math.equation(block: false, alt: "the square root of the fraction 2 MSE over n")[$sqrt(frac(2 #h(0.167em) "MSE", n))$]=#math.equation(block: false, alt: "the square root of the fraction open parenthesis 2 close parenthesis open parenthesis 2.864 close parenthesis over 17")[$sqrt(frac(( 2 ) ( 2.864 ), 17))$] = 0.5805. The next step is to find the t to use for the confidence interval (t#sub[CL]). To calculate t#sub[CL], we need to know the #strong[degrees of freedom]. The degrees of freedom is the number of independent estimates of variance on which MSE is based. This is equal to (n#sub[1] - 1) + (n#sub[2] - 1) where n#sub[1]is the sample size of the first group and n#sub[2] is the sample size of the second group. For this example, n#sub[1]= n#sub[2] = 17. When n#sub[1]= n#sub[2], it is conventional to use "n" to refer to the sample size of each group. Therefore, the degrees of freedom is 16 + 16 = 32. Online: Calculator: Find t for confidence interval From either the above calculator or a t table, you can find that the t for a 95% confidence interval for 32 df is 2.037. We now have all the components needed to compute the confidence interval. First, we know the difference between means: M#sub[1] - M#sub[2] = 5.353 - 3.882 = 1.471 We know the standard error of the difference between means is #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$] = 0.5805 and that the t for the 95% confidence interval with 32 df is t#sub[CL = 2.037] Therefore, the 95% confidence interval is Lower Limit = 1.471 - (2.037)(0.5805) = 0.29 Upper Limit = 1.471 + (2.037)(0.5805) = 2.65 We can write the confidence interval as: 0.29 ≤ μ#sub[f] - μ#sub[m] ≤ 2.65 where μ#sub[f] is the population mean for females and μ#sub[m] is the population mean for males. This analysis provides evidence that the mean for females is higher than the mean for males, and that the difference between means in the population is likely to be between 0.29 and 2.65. === Formatting data for Computer Analysis Most computer programs that compute t tests require your data to be in a specific form. Consider the data in Table 2. Table 2. Example Data. #figure(table( columns: 2, align: left, inset: 6pt, table.header([Group 1], [Group 2]), [3], [5], [4], [6], [5], [7], )) #linebreak() Here there are two groups, each with three observations. To format these data for a computer program, you normally have to use two variables: the first specifies the group the subject is in and the second is the score itself. For the data in Table 2, the reformatted data look as follows: #linebreak() #linebreak() Table 3. Reformatted Data. #figure(table( columns: 2, align: left, inset: 6pt, table.header([G], [Y]), [1], [3], [1], [4], [1], [5], [2], [5], [2], [6], [2], [7], )) To use Analysis Lab to do the calculations, you would copy the data and then + Click the "Enter/Edit User Data" button. (You may be warned that for security reasons you must use the keyboard shortcut for pasting data.) + Paste your data. + Click "Accept Data." + Set the Dependent Variable to Y. + Set the Grouping Variable to G. + Click the t-test confidence interval button. The 95% confidence interval on the difference between means extends from -4.267 to 0.267. === Computations for Unequal Sample Sizes (optional) The calculations are somewhat more complicated when the sample sizes are not equal. One consideration is that MSE, the estimate of variance, counts the sample with the larger sample size more than the sample with the smaller sample size. Computationally this is done by computing the sum of squares error (SSE) as follows: #linebreak() #linebreak() #math.equation(block: true, alt: "SSE equals ∑ open parenthesis X minus M sub 1 close parenthesis squared plus ∑ open parenthesis X minus M sub 2 close parenthesis squared")[$"SSE" = ∑ ( X − M_(1) )^(2) + ∑ ( X − M_(2) )^(2)$] #linebreak() #linebreak() where M#sub[1] is the mean for group 1 and M#sub[2] is the mean for group 2. Consider the following small example: Table 4. Example Data. #figure(table( columns: 2, align: left, inset: 6pt, table.header([Group 1], [Group 2]), [3], [2], [4], [4], [5], [], )) M#sub[1] = 4 and M#sub[2] = 3. #linebreak() #linebreak() SSE = (3-4)#super[2] + (4-4)#super[2] + (5-4)#super[2] + (2-3)#super[2] + (4-3)#super[2] = 4 #linebreak() #linebreak() Then, MSE is computed by: MSE = SSE/df #linebreak() #linebreak() where the degrees of freedom (df) is computed as before: #linebreak() df = (n#sub[1] -1) + (n#sub[2] -1) = (3-1) + (2-1) = 3. #linebreak() MSE = SSE/df = 4/3 = 1.333. #linebreak() #linebreak() The formula #linebreak() #linebreak() #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]=#math.equation(block: false, alt: "the square root of the fraction 2 MSE over n")[$sqrt(frac(2 #h(0.167em) "MSE", n))$] #linebreak() #linebreak() is replaced by #linebreak() #linebreak() #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]=#math.equation(block: false, alt: "the square root of the fraction 2 MSE over n sub h")[$sqrt(frac(2 #h(0.167em) "MSE", n_(h)))$] #linebreak() #linebreak() where n#sub[h] is the harmonic mean of the sample sizes and is computed as follows: #linebreak() #linebreak() n#sub[h] = #math.equation(block: false, alt: "the fraction 2 over the fraction 1 over n sub 1 plus the fraction 1 over n sub 2")[$frac(2, frac(1, n_(1)) + frac(1, n_(2)))$]= #math.equation(block: false, alt: "the fraction 2 over the fraction 1 over 3 plus the fraction 1 over 2")[$frac(2, frac(1, 3) + frac(1, 2))$] = 2.4 #linebreak() and #linebreak() #linebreak() #math.equation(block: false, alt: "s sub M sub 1 minus M sub 2")[$s_(M_(1) − M_(2))$]= #math.equation(block: false, alt: "the square root of the fraction open parenthesis 2 close parenthesis open parenthesis 1.333 close parenthesis over 2.4")[$sqrt(frac(( 2 ) ( 1.333 ), 2.4))$] = 1.054. #linebreak() #linebreak() #linebreak() t#sub[CL] for 3 df and the 0.05 level = 3.182. #linebreak() #linebreak() Therefore the 95% confidence interval is Lower Limit = 1 - (3.182)(1.054)= -2.35 Upper Limit = 1 + (3.182)(1.054)= 4.35 We can write the confidence interval as: -2.35 ≤ μ#sub[1] - μ#sub[2] ≤ 4.35 #linebreak()