0% found this document useful (0 votes)
17 views4 pages

Statistics Lab Exp 9 (T Test)

Uploaded by

st
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Statistics Lab Exp 9 (T Test)

Uploaded by

st
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment # 9

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

Degrees of freedom (df): df = 𝒏𝟏 + 𝒏𝟐 − 𝟐

2. Paired Samples t-test (Dependent t-test)

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:

• The differences between the paired observations are normally distributed.

Degrees of freedom (df): df = n−1

Where n is the number of paired observations.

9.4. Commands and calculation of R:


Independent Samples t-test (Two-Sample t-test)
t.test(group_A, group_B): Conducts a t-test comparing group_A and group_B.
var.equal = TRUE: Assumes equal variances between groups. You can set var.equal = FALSE,
if variances are unequal.
Paired Samples t-test (Dependent Test)
t.test(before, after, paired = TRUE): Conducts a paired t-test comparing before and after
measurements.
paired = TRUE: Specifies that the data are paired (dependent).
Summary Table for Choosing the Right t-test

Test Type Use Case R Function Example

Independent Samples t- Test if means of two unrelated t.test(group_A, group_B,


test groups are different var.equal = TRUE)

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)

Perform independent t-test


> t_test_independent <- t.test(group_A, group_B, var.equal = TRUE)
# Use var.equal = FALSE if variances are unequal
> print(t_test_independent)
Two Sample t-test
data: group_A and group_B
t = 2.2231, df = 8, p-value = 0.0569
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.2012646 11.0012646
sample estimates:
mean of x mean of y
84.6 79.2

2. Paired Samples t-test (Dependent t-test): Example Code in R


Suppose you measured students’ test scores before and after a specific training program.

Sample data for paired measurements


> before <- c(75, 80, 85, 90, 95)
> after <- c(78, 82, 88, 92, 96)

Perform paired t-test


> t_test_paired <- t.test(before, after, paired = TRUE)
>
> # Print the result
> print(t_test_paired)

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

You might also like