Here we generate the FHS,
f2=readRDS("output/statinuse.rds")
statin_summary <- f2 %>%
group_by(AGE1) %>%
summarize(
on_statin = sum(ever_on_statin),
total = n(),
percent_on_statin = round((sum(ever_on_statin) / n()) * 100,2)
)
# Print the summary table
print(statin_summary)
## # A tibble: 61 × 4
## AGE1 on_statin total percent_on_statin
## <int> <int> <int> <dbl>
## 1 5 0 1 0
## 2 9 1 3 33.3
## 3 10 0 2 0
## 4 11 2 6 33.3
## 5 12 1 6 16.7
## 6 13 6 13 46.2
## 7 14 1 9 11.1
## 8 15 4 19 21.0
## 9 16 8 22 36.4
## 10 17 6 29 20.7
## # ℹ 51 more rows
# Plot the summary
ggplot(statin_summary[statin_summary$AGE1%in%c(18:57),], aes(x = AGE1, y = percent_on_statin))+geom_smooth()+labs(title = "Percentage of Individuals Ever on Statin by Age of Enrollment",x = "Age of Enrollment",y = "Percentage Ever on Statin") +theme_classic()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
library(DT)
DT::datatable(statin_summary)