Replace “Your Name” with your actual name.

Objective:

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)
  )

Exercise 1: Conducting an Independent Samples t-Test

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:

  • Group A Scores: c(78, 82, 85, 88, 91, 77, 85, 89, 90, 92)
  • Group B Scores: 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(performance ~ group, performance_data)
## 
##  Welch Two Sample t-test
## 
## data:  performance by group
## t = 2.8222, df = 17.727, p-value = 0.01141
## alternative hypothesis: true difference in means between group A and group B is not equal to 0
## 95 percent confidence interval:
##   1.604841 10.995159
## 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
ggplot(performance_data, aes(x = group, y = performance, color = group)) + 
  geom_boxplot() + 
  apa_theme

  • t-Value: 2.82
  • Degrees of Freedom: 18
  • p-Value: 0.01
  • Interpretation: The p-value is less than 0.05. This means that there is a significant difference in how teaching methods impact test performance such that group A’s method had significantly higher test scores.

Exercise 2: Calculating Confidence Intervals

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.

# Confidence interval from t-test result
mod.1 <- t.test(performance ~ group, performance_data)
mod.1$conf.int
## [1]  1.604841 10.995159
## attr(,"conf.level")
## [1] 0.95
  • 95% Confidence Interval: 95% CI [1.60-11 ]
  • Interpretation: We are 95% certain that the true difference between Group A and Group B is between 1.6 and 11.

Exercise 3: Conducting a Paired Samples t-Test

Scenario: You collect data on the anxiety levels of participants before and after they complete a stress management program. The data is as follows:

  • Anxiety Levels Before: c(60, 62, 65, 68, 70, 72, 74, 76, 78, 80)
  • Anxiety Levels After: 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)  
# Conduct the paired samples t-test
t.test(anxiety_before, anxiety_after, paired = TRUE)
## 
##  Paired t-test
## 
## data:  anxiety_before and anxiety_after
## t = 13.863, df = 9, p-value = 2.233e-07
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  5.522998 7.677002
## sample estimates:
## mean difference 
##             6.6

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.
ggplot(anxiety_data, aes(x = time, y = anxiety, color = time)) + 
  geom_boxplot() + 
  apa_theme

  • t-Value: 13.863
  • Degrees of Freedom: 9
  • p-Value: < 0.0001
  • Interpretation: There is a significant improvement in anxiety reduction, such that the “post” anxiety score were significantly lower than the “pre” anxiety score.

Exercise 4: Understanding Significance and Effect Size

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. - The result is statistically significant because the p-value is below 0.05. This means there is like a real difference in weight loss between the two diets.

2. Interpret the effect size (Cohen’s d = 0.5) and its practical significance in the context of the study’s findings. - A Cohen’s d of 0.5 shows a moderate effect, meaning one diet led to noticeably more weight loss than the other.

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.