Skip to content

Commit

Permalink
update survival time calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
emprestige committed Mar 13, 2024
1 parent 8c00de3 commit 5b384f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
Binary file modified .RData
Binary file not shown.
68 changes: 41 additions & 27 deletions analysis/data_processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,47 @@ df_input <- df_input %>%
#define seasons for covid
covid_season_min = as.Date("2019-09-01", format = "%Y-%m-%d")

#create variable for survival time
df_input$end_time_mild <- study_end_date
df_input$end_time_severe <- study_end_date

#calculate follow-up end date for mild outcomes
df_input <- df_input %>%
rowwise() %>%
mutate(end_time_mild = case_when(
study_start_date >= covid_season_min & covid_primary ~ covid_primary_date,
rsv_primary ~ rsv_primary_date,
flu_primary ~ flu_primary_date,
TRUE ~ study_end_date
))

#calculate follow-up end date for severe outcomes
df_input <- df_input %>%
rowwise() %>%
mutate(end_time_severe = case_when(
study_start_date >= covid_season_min & covid_secondary ~ covid_secondary_date,
rsv_secondary ~ rsv_secondary_date,
flu_secondary ~ flu_secondary_date,
TRUE ~ study_end_date
))

#calculate survival time for both outcomes (in weeks)
df_input$time_mild <- difftime(df_input$end_time_mild, study_start_date, df_input, "weeks")
df_input$time_severe <- difftime(df_input$end_time_severe, study_start_date, df_input, "weeks")
# #create variable for survival time
# df_input$end_time_mild <- study_end_date
# df_input$end_time_severe <- study_end_date
#
# #calculate follow-up end date for mild outcomes
# df_input <- df_input %>%
# rowwise() %>%
# mutate(end_time_mild = case_when(
# study_start_date >= covid_season_min & covid_primary ~ covid_primary_date,
# rsv_primary ~ rsv_primary_date,
# flu_primary ~ flu_primary_date,
# TRUE ~ study_end_date
# ))
#
# #calculate follow-up end date for severe outcomes
# df_input <- df_input %>%
# rowwise() %>%
# mutate(end_time_severe = case_when(
# study_start_date >= covid_season_min & covid_secondary ~ covid_secondary_date,
# rsv_secondary ~ rsv_secondary_date,
# flu_secondary ~ flu_secondary_date,
# TRUE ~ study_end_date
# ))

#calculate survival time for both outcomes (in years)
# df_input$time_mild <- as.numeric(difftime(df_input$end_time_mild,
# study_start_date, df_input, "weeks"))/52.25
# df_input$time_severe <- as.numeric(difftime(df_input$end_time_severe,
# study_start_date, df_input, "weeks"))/52.25
df_input$time_rsv_primary <- as.numeric(difftime(df_input$rsv_primary_date,
study_start_date, df_input, "weeks"))/52.25
df_input$time_rsv_secondary <- as.numeric(difftime(df_input$rsv_secondary_date,
study_start_date, df_input, "weeks"))/52.25
df_input$time_flu_primary <- as.numeric(difftime(df_input$flu_primary_date,
study_start_date, df_input, "weeks"))/52.25
df_input$time_flu_secondary <- as.numeric(difftime(df_input$flu_secondary_date,
study_start_date, df_input, "weeks"))/52.25
df_input$time_covid_primary <- as.numeric(difftime(df_input$covid_primary_date,
study_start_date, df_input, "weeks"))/52.25
df_input$time_covid_secondary <- as.numeric(difftime(df_input$covid_secondary_date,
study_start_date, df_input, "weeks"))/52.25

## create output directories ----
fs::dir_create(here("output", "data"))
Expand Down
6 changes: 5 additions & 1 deletion analysis/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ library(arrow)
library(ggplot2)
library(data.table)
library(gtsummary)
library(survival)

## create output directories ----
fs::dir_create(here("analysis"))

#import redaction functions
source(here("analysis", "functions", "redaction.R"))
#source(here("analysis", "functions", "redaction.R"))

#define study start date and study end date
source(here("analysis", "design", "design.R"))
Expand Down Expand Up @@ -54,3 +55,6 @@ ggsave(
"_", year(study_end_date), "_", codelist_type, "_",
investigation_type,".png"), path = here::here("output", "models"),
)

#py <- pyears(time_mild ~ )

0 comments on commit 5b384f8

Please sign in to comment.