10.4: Worked Example- Calculating an Independent Samples t-Test

Statistical Methods in the Behavioral Sciences with JASP (Psych 10 at IVC) · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    10.4: Worked Example- Calculating an Independent Samples t-Test
    Example: Movies and Mood

    We are interested in whether the type of movie someone sees at the theater affects their mood when they leave. We decide to ask people about their mood as they leave one of two movies: a comedy (Group 1, \(n = 35\)) or a horror film (Group 2, \(n = 29\)). Our data are coded so that higher scores indicate a more positive mood. We have good reason to believe that people leaving the comedy will be in a better mood, so we use a one-tailed test at \(\alpha=.05\) to test our hypothesis.

    Step 1: State the Hypotheses

    As always, we start with hypotheses:

    \[\begin{aligned}
    &H_0 \text { : There is no difference in average mood between the two movie types }\\
    &\begin{gathered}
    H_0: \mu_1-\mu_2=0 \\
    \text { or } \\
    H_0: \mu_1=\mu_2
    \end{gathered}
    \end{aligned} \nonumber \]

    \[\begin{aligned}
    &H_{\mathrm{A}} \text { : The comedy film will produce a better average mood than the horror film }\\
    &\begin{gathered}
    H_{\mathrm{A}}: \mu_1-\mu_2>0 \\
    \text { or } \\
    H_{\mathrm{A}}: \mu_1>\mu_2
    \end{gathered}
    \end{aligned} \nonumber \]

    Notice that in the first formulation of the alternative hypothesis we say that the first mean minus the second mean will be greater than zero. This is based on how we code the data (higher is better), so we suspect that the mean of the first group will be higher. Thus, we will have a larger number minus a smaller number, which will be greater than zero. Be sure to pay attention to which group is which and how your data are coded (higher is almost always used as better outcomes) to make sure your hypothesis makes sense!

    Step 2: Find the Critical Values

    Just like before, we will need critical values, which come from our t table. In this example, we have a one-tailed test at \(\alpha=.05\) and expect a positive answer (because we expect the difference between the means to be greater than zero). Our degrees of freedom for our independent samples \(t\) test is just the degrees of freedom from each group added together: 35 + 29 − 2 = 62. From our \(t\) table, we find that our critical value is \(t^*=1.671\). Note that because 62 does not appear on the table, we use the next lowest value, which in this case is 60.

    Step 3: Compute the Test Statistic and Effect Size

    The data from our two groups are presented in the tables below. Table 10.1 shows the values for the Comedy group, and Table 10.2 shows the values for the Horror group. Values for both have already been placed in the sum of squares tables since we will need to use them for our further calculations. As always, the column on the left is our raw data.

    Table 10.1. Raw scores and sum of squares for Group 1 (comedy).

    \(X\)

    \(X − M\)

    \((X − M)^2\)

    39.10

    15.10

    228.01

    38.00

    14.00

    196.00

    14.90

    −9.10

    82.81

    20.70

    −3.30

    10.89

    19.50

    −4.50

    20.25

    32.20

    8.20

    67.24

    11.00

    −13.00

    169.00

    20.70

    −3.30

    10.89

    26.40

    2.40

    5.76

    35.70

    11.70

    136.89

    26.40

    2.40

    5.76

    28.80

    4.80

    23.04

    33.40

    9.40

    88.36

    13.70

    −10.30

    106.09

    46.10

    22.10

    488.41

    13.70

    −10.30

    106.09

    23.00

    −1.00

    1.00

    20.70

    −3.30

    10.89

    19.50

    −4.50

    20.25

    11.40

    −12.60

    158.76

    24.10

    0.10

    0.01

    17.20

    −6.80

    46.24

    38.00

    14.00

    196.00

    10.30

    −13.70

    187.69

    35.70

    11.70

    136.89

    41.50

    17.50

    306.25

    18.40

    −5.60

    31.36

    36.80

    12.80

    163.84

    54.10

    30.10

    906.01

    11.40

    −12.60

    158.76

    8.70

    −15.30

    234.09

    23.00

    −1.00

    1.00

    14.30

    −9.70

    94.09

    5.30

    −18.70

    349.69

    6.30

    −17.70

    313.29

    \(\Sigma = 840\)

    \(\Sigma = 0\)

    \(\Sigma = 5061.60\)

    Table 10.2. Raw scores and sum of squares for Group 2 (horror).

    \(X\)

    \(X − M\)

    \((X − M)^2\)

    24.00

    7.50

    56.25

    17.00

    0.50

    0.25

    35.80

    19.30

    372.49

    18.00

    1.50

    2.25

    −1.70

    −18.20

    331.24

    11.10

    −5.40

    29.16

    10.10

    −6.40

    40.96

    16.10

    −0.40

    0.16

    −0.70

    −17.20

    295.84

    14.10

    −2.40

    5.76

    25.90

    9.40

    88.36

    23.00

    6.50

    42.25

    20.00

    3.50

    12.25

    14.10

    −2.40

    5.76

    −1.70

    −18.20

    331.24

    19.00

    2.50

    6.25

    20.00

    3.50

    12.25

    30.90

    14.40

    207.36

    30.90

    14.40

    207.36

    22.00

    5.50

    30.25

    6.20

    −10.30

    106.09

    27.90

    11.40

    129.96

    14.10

    −2.40

    5.76

    33.80

    17.30

    299.29

    26.90

    10.40

    108.16

    5.20

    −11.30

    127.69

    13.10

    −3.40

    11.56

    19.00

    2.50

    6.25

    −15.50

    −32.00

    1024.00

    \(\Sigma = 478.6\)

    \(\Sigma = 0.10\)

    \(\Sigma = 3896.45\)

    Using the sum of the first column for each table, we can calculate the mean for each group:

    \[M_1=\dfrac{840}{35}=24.00 \nonumber \]

    \[\text {and} \nonumber \]

    \[M_2=\dfrac{478.60}{29}=16.50 \nonumber \]

    These values were used to calculate the middle rows of each table, which sum to zero as they should (the middle column for Group 2 sums to a very small value instead of zero due to rounding error—the exact mean is 16.50344827586207, but that’s far more than we need for our purposes). Squaring each of the deviation scores in the middle columns gives us the values in the third columns, which sum to our next important value: the sum of squares for each group: \(SS_1 = 5061.60\) and \(SS_2 = 3896.45\). Before we move on to the pooled variance that will allow us to calculate standard error, let’s compute our standard deviation for each group; even though we will not use them in our calculation of the test statistic, they are still important descriptors of our data:

    \[s_1=\sqrt{\dfrac{5061.60}{34}}=12.20 \nonumber \]

    \[\text {and} \nonumber \]

    \[s_2=\sqrt{\dfrac{3896.45}{28}}=11.80 \nonumber \]

    Now we can move on to our new calculation, the pooled variance, which is just the sums of squares that we calculated from our table and the degrees of freedom, which is just \(n − 1\) for each group:

    \[s_p^2=\dfrac{S S_1+S S_2}{d f_1+d f_2}=\dfrac{5061.60+3896.45}{34+28}=\dfrac{8958.05}{62}=144.48 \nonumber \]

    As you can see, if you follow the regular process of calculating standard deviation using the sum of squares table, finding the pooled variance is very easy. Now we can use that value to calculate our standard error, the last step before we can find our test statistic:

    \[s_{M_1-M_2}=\sqrt{\dfrac{s_p^2}{n_1}+\dfrac{s_p^2}{n_2}}=\sqrt{\dfrac{144.48}{35}+\dfrac{144.48}{29}}=\sqrt{4.13+4.98}=\sqrt{9.11}=3.02 \nonumber \]

    Finally, we can use our standard error and the means we calculated earlier to compute our test statistic. Because the null hypothesis value of \(\mu_1-\mu_2\) is 0.00, we will leave that portion out of the equation for simplicity:

    \[t=\dfrac{\left(M_1-M_2\right)}{s_{M_1-M_2}}=\dfrac{24.00-16.50}{3.02}=2.48 \nonumber \]

    The process of calculating our obtained test statistic \(t = 2.48\) followed the same sequence of steps as before: use raw data to compute the mean and sum of squares (this time for two groups instead of one), use the sum of squares and degrees of freedom to calculate standard error (this time using pooled variance instead of standard deviation), and use that standard error and the observed means to get \(t\).

    Effect Sizes and Confidence Intervals

    Even a statistically significant effect needs to be interpreted along with an effect size to see if it is practically meaningful. We have also seen that our sample means, as a point estimate, are not perfect and would be better represented by a range of values that we call a confidence interval. As with all other topics, this is also true of our independent samples t tests.

    Our effect size for the independent samples t test is still Cohen’s \(d\), and it is still just our observed effect divided by the standard deviation. Remember that standard deviation is just the square root of the variance, and because we work with pooled variance in our test statistic, we will use the square root of the pooled variance as our denominator in the formula for Cohen’s \(d\). This gives us:

    \[d=\dfrac{M_1-M_2}{\sqrt{s_p^2}} \nonumber \]

    For our example above, we can calculate the effect size to be:

    \[d=\dfrac{24.00-16.50}{\sqrt{144.48}}=\dfrac{7.50}{12.02}=0.62 \nonumber \]

    We interpret this using the same guidelines as before, so we would consider this a moderate or moderately large effect.

    Our confidence intervals also take on the same form and interpretation as they have in the past. The value we are interested in is the difference between the two means, so our point estimate is the value of one mean minus the other, or \(M_1-M_2\). Just like before, this is our observed effect and is the same value as the one we place in the numerator of our test statistic. We calculate this value then place the margin of error—still our critical value multiplied by our standard error—above and below it. That is:

    \[\text { Confidence interval }=\left(M_1-M_2\right) \pm t^*\left(s_{M_1-M_2}\right) \nonumber \]

    A one-tailed hypothesis test does not prevent us from calculating a confidence interval. We can report a one-sided interval corresponding to the test, or a two-sided interval if we clearly identify it. For a separate example of a two-sided interval, let’s use summary statistics on the average life satisfaction of people from two different towns.

    Our sample data are \(M_1 = 28.65, s_1 = 12.40, n_1 = 40\) and \(M_2 = 25.40, s_2 = 15.68, n_2 = 42\). At face value, it looks like the people from the first town have higher life satisfaction (28.65 vs. 25.40), but it will take a confidence interval (or complete hypothesis testing process) to see if that is true or just due to random chance. First, we want to calculate the difference between our sample means, which is 28.65 − 25.40 = 3.25. Next, we need a critical value from our \(t\) table. If we want to test at the normal 95% level of confidence, then our sample sizes will yield degrees of freedom equal to 40 + 42 − 2 = 80. From our table, that gives us a critical value of \(t^*=1.990\). Finally, we need our standard error. Recall that our standard error for an independent samples \(t\) test uses pooled variance, which requires the sum of squares and degrees of freedom. Up to this point, we have calculated the sum of squares using raw data, but in this situation, we do not have access to it. So, what are we to do?

    If we have summary data like standard deviation and sample size, it is very easy to calculate the pooled variance, and the key lies in rearranging the formulas to work backward through them. We need the sum of squares and degrees of freedom to calculate our pooled variance. Degrees of freedom is very simple: we just take the sample size minus 1.00 for each group. Getting the sum of squares is also easy: remember that variance is standard deviation squared and is the sum of squares divided by the degrees of freedom. That is:

    \[s^2=(s)^2=\dfrac{S S}{d f} \nonumber \]

    To get the sum of squares, we just multiply both sides of the above equation to get:

    \[(s)^2(d f)=S S \nonumber \]

    which is the squared standard deviation multiplied by the degrees of freedom (\(n − 1\)) equals the sum of squares.

    Using our example data:

    \[\begin{aligned}
    \left(s_1\right)^2\left(d f_1\right) & =S S_1 \\
    (12.40)^2(40-1) & =5996.64
    \end{aligned} \nonumber \]

    \[\begin{aligned}
    \left(s_2\right)^2\left(d f_2\right) & =S S_2 \\
    (15.68)^2(42-1) & =10080.36
    \end{aligned} \nonumber \]

    And thus our pooled variance equals:

    \[s_p^2=\dfrac{S S_1+S S_2}{d f_1+d f_2}=\dfrac{5996.64+10080.36}{39+41}=\dfrac{16077}{80}=200.96 \nonumber \]

    And our standard error equals:

    \[ s_{M_1-M_2} =\sqrt{\frac{s_p^2}{n_1}+\frac{s_p^2}{n_2}} =\sqrt{\frac{200.96248}{40}+\frac{200.96248}{42}} =\sqrt{9.808883} \approx 3.13 \]

    All of these steps are just slightly different ways of using the same formulas, numbers, and ideas we have worked with up to this point. Once we get out standard error, it’s time to build our confidence interval.

    \[ 95\%\text{ CI}=3.25\pm 1.990(3.1319) \]\[ \text{Upper bound}=3.25+6.23=9.48 \]\[ \text{Lower bound}=3.25-6.23=-2.98 \]\[ 95\%\text{ CI}=(-2.98,\ 9.48) \]

    Our confidence interval represents a range of plausible values for the population mean difference based on our observed data. In this instance, our interval (−2.98, 9.48) contains zero. These data therefore do not provide sufficient evidence of a difference in mean life satisfaction between the two towns.

    Now we can move on to the final step of the hypothesis-testing procedure.

    Step 4: Make the Decision

    Our test statistic has a value of \(t = 2.48\), and in Step 2 we found that the critical value is \(t^* = 1.671\). Because 2.48 > 1.671, we reject the null hypothesis:

    Reject \(H_0\). Based on our sample data from people who watched different kinds of movies, we can say that the average mood after a comedy movie (\(M_1=24.00, S D_1= 12.20\)) is better than the average mood after a horror movie (\(M_2=16.50, S D_2=11.80\)), \(t(62) = 2.48, p < .05, d = 0.62\).

    The results calculated from the Movies and Mood raw scores are shown below. The one-sided independent-samples t-test indicates that people leaving the comedy reported a more positive average mood (M = 24.00, SD = 12.20) than people leaving the horror film (M = 16.50, SD = 11.80), t(62) = 2.48, p = .008, d = .62.

    Group N Mean SD
    Comedy 35 24.000 12.201
    Horror 29 16.503 11.797

    Figure 10.1. Output from JASP for the independent-samples t test described in the Movies and Mood example. The output provides the \(t\) value (2.478), degrees of freedom (62), the exact \(p\) value (.008, which is less than .05), and Cohen’s \(d\) for effect size (0.622). Note that the means and standard deviations for both samples are also provided. Based on our sample data from people who watched different kinds of movies, we can say that the average mood after a comedy movie (\(M = 24.0, SD = 12.2\)) is better than the average mood after a horror movie (\(M = 16.5; SD = 11.8\)), \(t(62) = 2.48, p = .008, d = 0.62\). (“JASP independent-samples t test” by Rupa G. Gordon/Judy Schmitt is licensed under CC BY-NC-SA 4.0.)


    This page titled 10.4: Worked Example- Calculating an Independent Samples t-Test was last modified on Thu, 05 Nov 2026 02:13:42 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Hartrisha Kaur Uchida via source content that was edited to the style and standards of the LibreTexts platform.