Statistics Lab Exp 9 (T Test)
Statistics Lab Exp 9 (T Test)
9.1. Aim: Applying the t-test for independent and dependent samples.
9.2. Description: The t-test is a statistical test used to determine if there is a significant
difference between the means of two groups. It’s commonly used in hypothesis testing and
comes in several forms, each with specific applications.
Types of t-test:
1. Independent Samples t-test (Two-Sample t-test): Compares the means of two
unrelated groups to see if they differ significantly.
2. Paired Samples t-test (Dependent t-test): Compares means from the same group at
two different times or two matched groups to see if there’s a significant change.
Hypotheses in a t-test
For each type, we set up null (H0) and alternative (H1) hypotheses:
• Null Hypothesis (H0): There is no significant difference between the means.
• Alternative Hypothesis (H1): There is a significant difference between the means.
9.3. Formula:
1. Independent Samples t-test (Two-Sample t-test)
The independent samples t-test compares the means of two independent groups. The formula
for the t-statistic in the independent t-test is:
(𝒙𝟏 − ̅̅̅̅̅
𝒙𝟐 )
𝒕=
𝟐 𝟐
√𝒔𝟏 + 𝒔𝟐
𝒏𝟏 𝒏𝟐
Where: 𝒙𝟏 , 𝒙𝟐 = Sample means of Group 1 and Group 2
𝒔𝟏 𝟐 , 𝒔𝟐 𝟐 = Sample variances of Group 1 and Group 2
𝒏𝟏 , 𝒏𝟐 = Sample sizes of Group 1 and Group 2
The paired samples t-test is used when the samples are dependent, such as before-and-after
measurements. The formula for the t-statistic in the paired t-test is:
𝑑̅
𝑡=
𝑠
( 𝑑)
√𝑛
Where:
𝑑̅ = Mean of the differences between paired observations (after - before)
𝑠𝑑 = Standard deviation of the differences between the paired observations
n = Number of pairs
Assumptions:
Paired Samples t-test Test if means of two related t.test(before, after, paired =
(Dependent Test) groups differ TRUE)
9.5. Code in R
Suppose you have test scores from two groups of students who studied under different methods,
and you want to test if their mean scores are significantly different.
1. Sample data for two independent groups
> group_A <- c(85, 88, 90, 78, 82)
> group_B <- c(78, 80, 83, 76, 79)
Paired t-test
data: before and after
t = -5.8797, df = 4, p-value = 0.004181
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-3.238851 -1.161149
sample estimates:
mean difference
-2.2
Interpreting t-test Results in R
For each t-test, the output includes:
• t-value: Indicates the size of the difference relative to the variation in the data.
• p-value: A p-value < 0.05 (or your chosen significance level) indicates a statistically
significant difference.
• Confidence Interval (CI): Shows the range within which the true mean difference
likely lies.
• Mean Difference: The estimated difference between means (relevant for paired and
two-sample t-tests).
9.6. Problems:
Problem 1: Suppose you are testing the effectiveness of two teaching methods on student
performance. You have two groups of students, each taught with a different method. Test
whether there is a significant difference between the two groups' average scores.
Method1: 78, 82, 84, 88, 90, 85, 87, 89, 90, 80
Method2: 75, 79, 81, 83, 78, 80, 82, 84, 85, 77
Problem 2: You want to check the effectiveness of a new learning app by measuring the same
students' scores before and after using it. Test if there is a significant improvement in scores
after using the app.
Before: 65, 68, 70, 72, 66, 75, 67, 69, 71, 68
After: 70, 72, 75, 78, 70, 80, 73, 75, 78, 74