Final Project

Author

Natalie Field

Acupuncture for Chronic Headache in Primary Care

Load the Libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.0     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(openintro)
Loading required package: airports
Loading required package: cherryblossom
Loading required package: usdata

Access the Data

acupuncture <- read.csv("acupuncture.csv")

Introduction

Incorporate background research here.

Initial Summary Graphs

Create side-by-side box plots of sex and chronicity. Chronicity is defined as the number of years of headache disorder.

# Box plots
acupuncture1 <- acupuncture %>% 
  mutate(sex = if_else(sex > 0, "female", "male")) %>% 
  na.exclude()
ggplot(data = acupuncture1, aes(sex, chronicity, fill = sex)) + geom_boxplot()

# The central line in a box plot represents the median value of the data. Since the medians of the two box plots are equal, it suggests that, on average, the values in the two sex groups are comparable. Hence, this model conveys that the number of years of headache disorder is similar between the two groups.

Create a scatter plot of Age and Chronicity to explore whether patient age predicts the number of years the patient has had chronic headaches. Add a linear regression line to the plot.

ggplot(acupuncture, aes(x=age, y=chronicity)) + geom_point() + geom_smooth(method = "lm") + theme_bw() + labs(x="Age", y="Number of Years Having 
Headache Disorder", title=" Scatter Plot of Age to Number of Years Having 
                      Headache Disorder")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).

# By looking at this model, we can estimate the relationship between the two quantitative variables (age and chronicity). Since the data points are following a gradual pattern up from left to right, we can see a positive association. However, we must also take into consideration how close the data points are to the line of best fit on the scatter plot. Since the majority of data points lie far away from the regression line, we can also assume a weak relationship between the two variables. Thus, we can say that this is a weak positive model, and that age slightly predicts the chronicity of the condition. Older patients seem to struggle with chronic headaches for a longer amount of time. 

Create side-by-side box plots of group type and “pk5,” which is the headache severity score after 1 year.

# Box plots
acupuncture2 <- acupuncture %>% 
  mutate(group = if_else(group > 0, "treatment", "control")) %>%
  na.exclude()
ggplot(data = acupuncture2, aes(group, pk5, fill = group)) + geom_boxplot()

# The reason I chose to analyze the effect of the treatment on "pk5" is because the primary outcome of this trial was the patients' headache score at the one-year follow up. Since the median of the treatment group is notably lower than that of the control group, it suggests that the treatment (acupuncture) may be an effective and safe therapy for migraine. In addition, the box plot for the treatment group is lower than that of the control group, which tells us that acupuncture therapy is helpful in reducing headache severity (as most of the values in the treatment group are lower than those in the control group). Lower values mean lower headache severity scores, which suggests that the acupuncture treatment is effective.

Create a bar chart to show the number of patients in the treatment and control groups.

acupuncture3 <- acupuncture %>% 
  mutate(group = if_else(group > 0, "treatment", "control")) %>%
  na.exclude()
ggplot(acupuncture3, aes(x = group)) +
  geom_bar() +
  labs(
    x = "Type of Treatment Group", y = "Count",
    title = "Number of Patients in Each Treatment Group")