#set document(title: "12.3 Difference between 2 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")) == 12.3#h(0.6em)Difference between 2 Means #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Prerequisites] Sampling Distribution of Difference between Means, Confidence Intervals, Confidence Interval on the Difference between Means, #link("https://onlinestatbook.com/2/logic_of_hypothesis_testing/logic_hypothesis.html")[Logic of Hypothesis Testing], Testing a Single Mean #linebreak() #linebreak() ] #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Learning Objectives] + State the assumptions for testing the difference between two means + Estimate the population variance assuming homogeneity of variance + Compute the standard error of the difference between means + Compute t and p for 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. This section covers how to test for differences between means from two separate groups of subjects. A later section describes how to test for differences between the means of two conditions in designs where only one group of subjects is used and each subject is tested in each condition. 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([Group], [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 whether there is a difference in the #strong[population] means. In order to test whether there is a difference between population means, 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. This assumption requires that each subject provide only one value. If a subject provides two scores, then the scores are not independent. The analysis of data with two scores per subject is shown in the section on the correlated t test later in this chapter. #linebreak() The consequences of violating the first two assumptions are investigated in the simulation in the next section. For now, suffice it to say that small-to-moderate violations of assumptions 1 and 2 do not make much difference. It is important not to violate assumption 3. We saw the following general formula for significance testing in the section on testing a single mean: #math.equation(block: true, alt: "t equals the fraction statistic minus hypothesized value over estimated standard error of the statistic")[$t = frac("statistic" − "hypothesized value", "estimated standard error of the statistic")$] In this case, our statistic is the difference between sample means and our hypothesized value is 0. The hypothesized value is the null hypothesis that the difference between population means is 0. We continue to use the data from the "Animal Research" case study and will compute a significance test on the difference between the mean score of the females and the mean score of the males. For this calculation, we will make the three assumptions specified above. The first step is to compute the statistic, which is simply the difference between means. M#sub[1] - M#sub[2] = 5.3529 - 3.8824 = 1.4705 Since the hypothesized value is 0, we do not need to subtract it from the statistic. The next step is to compute the estimate of the standard error of the statistic. In this case, the statistic is the difference between means, so the estimated standard error of the statistic is (#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 between means 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 two 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. Since n (the number of scores #emph[in each group]) 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 compute t by plugging these values into the formula: t = 1.4705/.5805 = 2.533. Finally, we compute the probability of getting a t as large or larger than 2.533 or as small or smaller than -2.533. To do this, 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. Once we have the degrees of freedom, we can use the #link("https://onlinestatbook.com/2/calculators/t_dist.html")[t distribution calculator] to find the probability. Figure 1 shows that the probability value for a two-tailed test is 0.0164. The two-tailed test is used when the null hypothesis can be rejected regardless of the direction of the effect. As shown in Figure 1, it is the probability of a t \< -2.533 or a t \> 2.533. #figure(figph[t distribution calculator screenshot headed "t distribution with df = 32", with t = 2.533 and Two-tailed test selected. Both tails beyond -2.533 and 2.533 are shaded, giving Shaded area: 0.0164.], alt: "t distribution calculator screenshot headed \"t distribution with df = 32\", with t = 2.533 and Two-tailed test selected. Both tails beyond -2.533 and 2.533 are shaded, giving Shaded area: 0.0164.", caption: [Figure 1. The two-tailed probability.]) The results of a one-tailed test are shown in Figure 2. As you can see, the probability value of 0.0082 is half the value for the two-tailed test. #figure(figph[The same t distribution calculator with df = 32 and t = 2.533, but with One-tailed test selected: only the upper tail beyond 2.533 is shaded, giving Shaded area: 0.0082 — half the two-tailed value.], alt: "The same t distribution calculator with df = 32 and t = 2.533, but with One-tailed test selected: only the upper tail beyond 2.533 is shaded, giving Shaded area: 0.0082 — half the two-tailed value.", caption: [Figure 2. The one-tailed probability.]) #link("https://onlinestatbook.com/2/calculators/t_dist.html")[Online Calculator: t distribution] === 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], [2], [4], [6], [5], [8], )) 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. The reformatted version of the data in Table 2 is shown in Table 3. Table 3. Reformatted Data. #figure(table( columns: 2, align: left, inset: 6pt, table.header([G], [Y]), [1], [3], [1], [4], [1], [5], [2], [2], [2], [6], [2], [8], )) To use Analysis Lab to do the calculations, you would copy the data and then + Click the "Enter/Edit 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. #linebreak() The t value is -0.718, the df = 4, and p = 0.512. === 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 group with the larger sample size more than the group 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. Unequal n. #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() Therefore, t = (4-3)/1.054 = 0.949 #linebreak() and the two-tailed p = 0.413.