Replace “Your Name” with your actual name.
Please complete this exam on your own. Include your R code, interpretations, and answers within this document.
set.seed(123)
n <- 50
data <- data.frame(
participant_id = 1:n,
reaction_time = rnorm(n, mean = 300, sd = 50),
accuracy = rnorm(n, mean = 85, sd = 10),
gender = sample(c("Male", "Female"), n, replace = TRUE),
condition = sample(c("Control", "Experimental"), n, replace = TRUE),
anxiety_pre = rnorm(n, mean = 25, sd = 8),
anxiety_post = NA
)
data$anxiety_post <- ifelse(
data$condition == "Experimental",
data$anxiety_pre - rnorm(n, mean = 8, sd = 3),
data$anxiety_pre - rnorm(n, mean = 3, sd = 2)
)
data$anxiety_post <- pmax(data$anxiety_post, 0)
data$reaction_time[sample(1:n, 3)] <- NA
data$accuracy[sample(1:n, 2)] <- NA
head(data)
## participant_id reaction_time accuracy gender condition anxiety_pre
## 1 1 271.9762 87.53319 Female Control 31.30191
## 2 2 288.4911 84.71453 Female Experimental 31.15234
## 3 3 377.9354 84.57130 Female Experimental 27.65762
## 4 4 303.5254 98.68602 Male Control 16.93299
## 5 5 306.4644 82.74229 Female Control 24.04438
## 6 6 385.7532 100.16471 Female Control 22.75684
## anxiety_post
## 1 29.05312
## 2 19.21510
## 3 20.45306
## 4 13.75199
## 5 17.84736
## 6 19.93397
data %>%
group_by(condition) %>%
summarise(
Mean_Reaction = mean(reaction_time, na.rm = TRUE),
SD_Reaction = sd(reaction_time, na.rm = TRUE),
Mean_Accuracy = mean(accuracy, na.rm = TRUE),
SD_Accuracy = sd(accuracy, na.rm = TRUE)
)
## # A tibble: 2 × 5
## condition Mean_Reaction SD_Reaction Mean_Accuracy SD_Accuracy
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Control 301. 48.5 85.5 9.86
## 2 Experimental 296. 38.4 88.1 8.20
data <- data %>% mutate(anxiety_change = anxiety_pre - anxiety_post)
data %>% group_by(condition) %>% summarise(Mean_Anxiety_Change = mean(anxiety_change, na.rm = TRUE))
## # A tibble: 2 × 2
## condition Mean_Anxiety_Change
## <chr> <dbl>
## 1 Control 3.79
## 2 Experimental 8.64
clean_data <- clean_data %>% mutate(performance_category = case_when(
accuracy >= 90 ~ "High",
accuracy >= 70 & accuracy < 90 ~ "Medium",
accuracy < 70 ~ "Low"
))
filtered_data <- clean_data %>% filter(condition == "Experimental" & reaction_time < mean(reaction_time, na.rm = TRUE))
par(mar = c(5, 5, 4, 2) + 0.1) # Increase margins
numeric_data <- clean_data %>% select(reaction_time, accuracy, anxiety_pre, anxiety_post, anxiety_change)
corPlot(numeric_data)
Research Question: I am interested in studying the impact of mindfulness meditation on test anxiety. I would collect pre- and post-test anxiety scores, reaction times, and performance metrics. I would use paired t-tests to compare pre- and post-anxiety scores and ANOVA to analyze differences between groups. Measurement errors such as participant stress levels and environmental distractions would need to be controlled.
Learning R for Data Analysis:
Knit to HTML and submit the RPubs link.