Replace “Your Name” with your actual name.
In this lab assignment, you will apply your understanding of hypothesis testing by conducting various tests and interpreting their results. You’ll work with different datasets to perform t-tests, calculate confidence intervals, and analyze the results. Once you have completed the exercises, knit this document to HTML and publish it to RPubs. Make sure your YAML header includes a title, your name, and the date.
Run the below chunk to create the
apa_theme()
# Load ggplot2
library(ggplot2)
apa_theme <- theme_classic() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom",
text = element_text(family = "serif", size = 12),
axis.title = element_text(size = 12),
plot.title = element_text(size = 14, hjust = 0.5)
)
Scenario: You are studying the effect of two different teaching methods on student performance. You collect test scores from two groups of students who were taught using different methods. The data is as follows:
c(78, 82, 85, 88, 91, 77, 85, 89, 90, 92)
c(70, 75, 80, 82, 84, 76, 78, 81, 83, 85)
Tasks:
1. Conduct an independent samples t-test to compare the means of the two groups using R.
2. Create a, APA Boxplot graph using ggplot and geom_boxplot()
3. Interpret the t-value, degrees of freedom, and p-value from the output.
# Sample data
# Define the data for each group
group_A <- c(78, 82, 85, 88, 91, 77, 85, 89, 90, 92)
group_B <- c(70, 75, 80, 82, 84, 76, 78, 81, 83, 85)
# Create a data frame with group and performance variables
performance_data <- data.frame(
group = factor(rep(c("A", "B"), each = 10)),
performance = c(group_A, group_B)
)
# Conduct the independent samples t-test
t_test_result <- t.test(performance ~ group, data = performance_data, var.equal = TRUE)
t_test_result
##
## Two Sample t-test
##
## data: performance by group
## t = 2.8222, df = 18, p-value = 0.01129
## alternative hypothesis: true difference in means between group A and group B is not equal to 0
## 95 percent confidence interval:
## 1.610032 10.989968
## sample estimates:
## mean in group A mean in group B
## 85.7 79.4
#create a boxplot using geom_boxplot(). Add apa_theme to it
# Load necessary package
library(ggplot2)
ggplot(performance_data, aes(x = group, y = performance, fill = group)) +
geom_boxplot(color = "black", width = 0.5) +
scale_fill_manual(values = c("lightblue", "lightpink")) +
theme_minimal(base_size = 14) +
theme(
legend.position = "none",
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text(hjust = 0.5)
) +
labs(
title = "Comparison of Student Performance by Teaching Method",
x = "Group (Teaching Method)",
y = "Test Scores"
)
Scenario: You want to calculate a 95% confidence interval for the difference between the means of the two groups (Group A and Group B) from Exercise 1.
Tasks:
1. Calculate the 95% confidence interval for the difference between the means of Group A and Group B using the t-test results.
2. Interpret the confidence interval and discuss what it suggests about the difference between the two teaching methods.
## [1] 1.610032 10.989968
## attr(,"conf.level")
## [1] 0.95
Scenario: You collect data on the anxiety levels of participants before and after they complete a stress management program. The data is as follows:
c(60, 62, 65, 68, 70, 72, 74, 76, 78, 80)
c(55, 58, 60, 62, 63, 65, 66, 68, 70, 72)
Tasks:
1. Conduct a paired samples t-test to determine if there is a significant difference in anxiety levels before and after the program.
2. Create an APA Boxplot graph using ggplot and geom_boxplot()
3. Interpret the t-value, degrees of freedom, and p-value from the output.
# Sample data
# Define the data for anxiety levels before and after
anxiety_before <- c(60, 62, 65, 68, 70, 72, 74, 76, 78, 80)
anxiety_after <- c(55, 58, 60, 62, 63, 65, 66, 68, 70, 72)
Run the below chunk before making your graph.
# Create a subject identifier (assumes 10 subjects)
subject <- 1:10
# Create data frame for Before measurements
anxiety_data_before <- data.frame(
subject = subject,
time = "before",
anxiety = anxiety_before)
# Create data frame for After measurements
anxiety_data_after <- data.frame(
subject = subject,
time = "after",
anxiety = anxiety_after
)
# Combine the two data frames into one long format data frame
anxiety_data <- rbind(anxiety_data_before, anxiety_data_after)
#create a boxplot using geom_boxplot(). Add apa_theme to it
#use the new anxiety_data created in the previous chunk.
Degrees of Freedom: 18 The degrees of freedom (df) is calculated as the sum of the sample sizes of both groups minus 2: df=(n1(2−2)=(10+10−2)=18df=(n1+n2−2)=(10+10−2)=18.
p-Value: 0.014 The p-value of 0.014 is less than the conventional alpha level of 0.05, indicating that the difference in means between Group A and Group B is statistically significant.
Scenario: You conduct a study comparing the effectiveness of two diets on weight loss. The independent samples t-test yields a p-value of 0.03 and a Cohen’s d of 0.5.
Tasks:
1. Discuss whether the result is statistically significant and what the p-value indicates.
2. Interpret the effect size (Cohen’s d = 0.5) and its practical significance in the context of the study’s findings.
The p-value of 0.03 means the result is statistically significant, indicating a real difference between the two diets.
A Cohen’s d of 0.5 shows a medium effect size, suggesting a moderate, meaningful difference in weight loss.
Thus, the difference is both statistically and practically significant, and could be relevant for real-world diet decisions.
Submission Instructions:
Ensure to knit your document to PDF format, checking that all content is correctly displayed before submission. Submit this PDF to Canvas Assignments.