This document contains the hazard ratio plots of the surivival models, using time since baseline as the metric of interest and neuroticism by conscientiousness as the predictor of interest.
The following packages were used to generate this table:
library(papaja)
library(tidyverse)
library(knitr)
library(kableExtra)
library(here)
The files needed for this table are available at osf.io/mzfu9 in the Individual Study Output folder.
First we load the individual study analysis objects.
study.names = c("EAS", "HRS", "LBC", "LBLS", "MAP", "MAS", "MIDUS", "NAS", "OATS", "ROS", "SLS", "WLS")
lapply(here(paste0("mortality/study output/", study.names, "_survival_output.Rdata")), load, .GlobalEnv)
Next we extract the predicted values from each object.
plottime = lapply(paste0(study.names, "_survival_output"),
FUN = function(x) get(x)$plotdata$time) %>%
map2_df(., study.names, ~ mutate(.x, study = .y))
plot_n = data.frame(study = study.names,
n = sapply(paste0(study.names, "_survival_output"),
FUN = function(x) get(x)$time$model2$ntotal))
plottime = plottime %>%
full_join(plot_n)
Finally, we plot individual values, as well as the overall weighted line.
plottime %>%
mutate(study = gsub("LBC", "LBC1936", study)) %>%
ggplot(aes(x = z.neur, y = fit)) +
geom_line(aes(color = study), linetype = "dashed") +
stat_smooth(aes(weight = n),
method = "lm",
formula = y ~ x,
se = TRUE,
size = 1, color = "black") +
scale_x_continuous("Neuroticism (standardized within study)") +
scale_y_continuous("Hazard ratio") +
facet_wrap(~z.con) +
theme_bw() +
theme(legend.position = "bottom")
ggsave(file = "mortalityplot.pdf", width = 6, height = 4)