A medical research team created a new medication to reduce headaches (Medication A). They want to determine if Medication A is more effective at reducing headaches than the current medication on the market (Medication B). A group of participants were randomly assigned to either take Medication A or Medication B. Data was collected for 30 days through an app and participants reported each day if they did or did not have a headache. Was there a difference in the number of headaches between the groups?
Null Hypothesis (H0): There is no difference in the number of headacheDays between participants taking Medication A and those taking Medication B.
Alternate Hypothesis (H1): There is a difference in the number of headacheDays between participants taking Medication A and those taking Medication B.
# Install .packages("readxl")
# Load required packages
library(readxl)
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
#Import the excel file
A6R1 <- read_excel("C:/Users/sravz/Downloads/A6R1.xlsx")
DESCRIPTIVE STATISTICS
# calculate descriptive statistics
A6R1 %>%
group_by(Medication) %>%
summarise(
Mean = mean(HeadacheDays, na.rm = TRUE),
Median = median(HeadacheDays, na.rm = TRUE),
SD = sd(HeadacheDays, na.rm = TRUE),
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
HISTOGRAMS
hist(A6R1$HeadacheDays[A6R1$Medication == "A"],
main = "Histogram for Medication A",
xlab = "Value",
ylab = "Frequency",
col = "lightpink",
border = "black",
breaks = 20)
hist(A6R1$HeadacheDays[A6R1$Medication == "B"],
main = "Histogram for Medication B",
xlab = "Value",
ylab = "Frequency",
col = "orange",
border = "black",
breaks = 20)
QUESTIONS
Q1) Check the SKEWNESS of the VARIABLE 1 histogram. In your opinion, does the histogram look symmetrical, positively skewed, or negatively skewed?
The histogram for Medication A appears to be slightly positively skewed.
Q2) Check the KURTOSIS of the VARIABLE 1 histogram. In your opinion, does the histogram look too flat, too tall, or does it have a proper bell curve?
The histogram for Medication A appears to have a proper bell curve shape, or perhaps is slightly too tall.
Q3) Check the SKEWNESS of the VARIABLE 2 histogram. In your opinion, does the histogram look symmetrical, positively skewed, or negatively skewed?
The histogram for Medication B is slightly positively skewed.
Q4) Check the KUROTSIS of the VARIABLE 2 histogram. In your opinion, does the histogram look too flat, too tall, or does it have a proper bell curve?
It looks slightly tall, meaning mildly leptokurtic, but still close to normal.
SHAPIRO-WILK TEST
shapiro.test(A6R1$HeadacheDays[A6R1$Medication == "A"])
##
## Shapiro-Wilk normality test
##
## data: A6R1$HeadacheDays[A6R1$Medication == "A"]
## W = 0.97852, p-value = 0.4913
shapiro.test(A6R1$HeadacheDays[A6R1$Medication == "B"])
##
## Shapiro-Wilk normality test
##
## data: A6R1$HeadacheDays[A6R1$Medication == "B"]
## W = 0.98758, p-value = 0.8741
QUESTIONs
Was the data normally distributed for Variable 1?
Data is normally distributed.
Was the data normally distributed for Variable 2?
Data is normally distributed.
library(ggplot2)
library(ggpubr)
BOXPLOT
ggboxplot(A6R1, x = "Medication", y = "HeadacheDays",
color = "Medication",
palette = "jco",
add = "jitter")
QUESTION
Q1) Were there any dots outside of the boxplot? Are these dots close to the whiskers of the boxplot or are they very far away?
Medication A: maybe 1 small outlier, near whisker
Medication B: maybe 1–2 small outliers, but close to whiskers
INDEPENDENT T-TEST
t.test(HeadacheDays ~ Medication, data = A6R1, var.equal = TRUE)
##
## Two Sample t-test
##
## data: HeadacheDays by Medication
## 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)
Cohen’s D
cohens_d_result <- cohens_d(HeadacheDays ~ Medication, data = A6R1, pooled_sd = TRUE)
print(cohens_d_result)
## Cohen's d | 95% CI
## --------------------------
## -1.40 | [-1.83, -0.96]
##
## - Estimated using pooled SD.
QUESTIONS
Q1) What is the size of the effect?
Cohen’s d = - 1.40, which is a VERY LARGE effect size.
Q2) Which group had the higher average rank?
Medication B had the higher average score (Mean = 12.6).
An independent samples t-test was conducted to compare the number of headache days between participants taking Medication A and participants taking Medication B. Participants taking Medication A (M = 8.10, SD = 2.81, n = 50) reported significantly fewer headache days over the 30-day period than participants taking Medication B (M = 12.60, SD = 3.59, n = 50), t = –6.99, p < .001. The effect size was very large (Cohen’s d = -1.40), indicating that Medication A substantially reduced headache frequency compared to Medication B.