INDEPENDENT T-TEST — MEDICATION A VS B

These tests evaluate whether mean headache days differ for participants prescribed Medication A or Medication B.

H0: The population mean number of headache days is equal for Medication A and Medication B (µ_A = µ_B).

H1: The population mean number of headache days differs between Medication A and Medication B (µ_A ≠ µ_B).

library(readxl)
dataset <- read_excel("A6R1.xlsx")

score <- dataset$HeadacheDays
group <- dataset$Medication

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
dataset %>%
group_by(Medication) %>%
summarise(
Mean = mean(HeadacheDays),
Median = median(HeadacheDays),
SD = sd(HeadacheDays),
N = n()
)
## # A tibble: 2 × 5
##   Medication  Mean Median    SD     N
##   <chr>      <dbl>  <dbl> <dbl> <int>
## 1 A            8.1    8    2.81    50
## 2 B           12.6   12.5  3.59    50
# Group A histogram

hist(dataset$HeadacheDays[dataset$Medication == "A"],
main = "Histogram of Medication A",
xlab = "Headache Days",
ylab = "Frequency",
col = "lightblue",
border = "black",
breaks = 20)

# Group B histogram

hist(dataset$HeadacheDays[dataset$Medication == "B"],
main = "Histogram of Medication B",
xlab = "Headache Days",
ylab = "Frequency",
col = "lightgreen",
border = "black",
breaks = 20)

shapiro.test(dataset$HeadacheDays[dataset$Medication=="A"])
## 
##  Shapiro-Wilk normality test
## 
## data:  dataset$HeadacheDays[dataset$Medication == "A"]
## W = 0.97852, p-value = 0.4913
shapiro.test(dataset$HeadacheDays[dataset$Medication=="B"])
## 
##  Shapiro-Wilk normality test
## 
## data:  dataset$HeadacheDays[dataset$Medication == "B"]
## W = 0.98758, p-value = 0.8741
# Independent t-test

t.test(score ~ group, data = dataset, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  score by group
## t = -6.9862, df = 98, p-value = 3.431e-10
## alternative hypothesis: true difference in means between group A and group B is not equal to 0
## 95 percent confidence interval:
##  -5.778247 -3.221753
## sample estimates:
## mean in group A mean in group B 
##             8.1            12.6
library(effectsize)
cohens_d(score ~ group, data = dataset, pooled_sd = TRUE)
## Cohen's d |         95% CI
## --------------------------
## -1.40     | [-1.83, -0.96]
## 
## - Estimated using pooled SD.
#Q1) What is the size of the effect?
#A Cohen’s D of -1.40 indicates that the difference between the group averages was very large.

#Q2) Which group had the higher average score?
#Group A had a mean of 8.10, and Group B had a mean of 12.60.
#Therefore, Group B had the higher average score.
An Independent t-test was conducted to compare the number of headache days between participants taking Medication A (n = 50) and Medication B (n = 50). Results showed that the difference was statistically significant, p < .001. Participants taking Medication A reported fewer headache days (M = 8.10, SD = 2.81) than those taking Medication B (M = 12.60, SD = 3.59). The test statistic indicated a strong effect, t(98) = -6.99. The effect size was very large (d = 1.40), suggesting a substantial difference between the two medications. Overall, Medication A was associated with far fewer headache days compared to Medication B.