Click to show/hide R Code
#Final STROBE flowchart
patients_fc_matched%>%
fc_draw()%>%
fc_export("figures/flowchart.svg",
width=20,
height=10)The code in this script generates figures for the manuscript.
The full R script is available at:
This R script file is itself reliant on the following helper files:
The following code uses the flowchart package to create a STROBE flowchart for the study.
#Final STROBE flowchart
patients_fc_matched%>%
fc_draw()%>%
fc_export("figures/flowchart.svg",
width=20,
height=10)The following code uses the ggbeeswarm add-on to ggplot2 to compare cases and controls in terms of total inflated costs post-index. No attempt is made to adjust for censoring or death.
#GGplot that is beeswarm of adjusted total costs
cost_inflated%>%
mutate(IN_CLM_365d_cost_adjusted_total=ifelse(IN_CLM_365d_cost_adjusted_total==0, 1, IN_CLM_365d_cost_adjusted_total))%>%
ggplot()+
geom_quasirandom(mapping=aes(x=patient_type, y=IN_CLM_365d_cost_adjusted_total), alpha=0.1)+
scale_y_log10()+
theme_classic()In order to plot monthly costs predicted from the longitudinal models generated in the R/models.R script, we use the plot_mean_monthly_costs() function from the R/functions.R script to create the ggplot objects, and then save as .svg files.
#Loop that plots the different outcomes longitudinally
for (outcome in c("grand_total_cost_month", "IN_CLM_month_total", "PS_REV_month_total", "IN_CLM_month_groupedHomeHealth",
"IN_CLM_month_groupedHospice","IN_CLM_month_groupedNonclaimauxiliary","IN_CLM_month_groupedDialysis",
"IN_CLM_month_groupedOutpatient","IN_CLM_month_groupedInpatient","IN_CLM_month_groupedSkilledNursingFacility")){
plot_mean_monthly_costs(fit[[outcome]][["glmmTMB"]][["tweedie"]])
ggsave(filename = paste0("figures/Longitudinal ", outcome," glmmTMB", " ", "tweedie.svg"),
width=14,
height=7
)
plot_mean_monthly_costs(fit[[outcome]][["glmmTMB"]][["linear"]])
ggsave(filename = paste0("figures/Longitudinal ", outcome," glmmTMB", " ", "linear.svg"),
width=14,
height=7
)
plot_mean_monthly_costs(fit[[outcome]][["gee"]][["linear"]])
ggsave(filename = paste0("figures/Longitudinal ", outcome," gee", " ", "linear.svg"),
width=14,
height=7
)
plot_mean_monthly_costs(fit[[outcome]][["glmmTMB"]][["log"]])
ggsave(filename = paste0("figures/Longitudinal ", outcome," glmmTMB", " ", "log.svg"),
width=14,
height=7
)
plot_mean_monthly_costs(fit[[outcome]][["gee"]][["log"]])
ggsave(filename = paste0("figures/Longitudinal ", outcome," gee", " ", "log.svg"),
width=14,
height=7
)
}