Skip to content

Commit

Permalink
describe trt outc same day
Browse files Browse the repository at this point in the history
  • Loading branch information
Linda Nab committed Nov 12, 2023
1 parent b4af6f3 commit 9fcf3c4
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
71 changes: 71 additions & 0 deletions analysis/data_properties/describe_trt_outcm_same_day.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
################################################################################
#
# Number of people treated and experiencing an outcome on same day
#
# This script can be run via an action in project.yaml using one argument
# - 'period' /in {ba1, ba2} --> period
#
# Depending on 'period' the output of this script is:
# empty file ./output/data_properties/trt_outcm_same_day.csv
################################################################################

################################################################################
# 0.0 Import libraries + functions
################################################################################
library(readr)
library(dplyr)
library(fs)
library(here)
library(purrr)

################################################################################
# 0.1 Create directories for output
################################################################################
output_dir <- here("output", "data_properties")
fs::dir_create(output_dir)

################################################################################
# 0.2 Import command-line arguments
################################################################################

################################################################################
# 0.3 Import data
################################################################################
file_names <- paste0(c("", "ba2_"), "data_processed.rds")
data <-
map(.x = fs::path(here("output", "data"), file_names),
.f = ~ read_rds(.x))
names(data) <- c("ba1", "ba2")

################################################################################
# Number of pt treated + outcome on same day
################################################################################
out <-
imap(.x = data,
.f = ~
.x %>%
filter(status_primary %in% c("covid_hosp_death", "noncovid_death", "dereg") &
treatment == "Treated" &
treatment_date == min_date_all) %>%
group_by(status_primary, .drop = "FALSE") %>%
summarise(n = n()) %>%
filter(status_primary != "none") %>%
mutate(period = .y, .before = status_primary)
) %>% bind_rows()
# Set rounding and redaction thresholds
rounding_threshold = 6
redaction_threshold = 8
out_red <-
out %>%
mutate(n = if_else(n > 0 & n <= redaction_threshold,
"[REDACTED]",
plyr::round_any(n, rounding_threshold) %>% as.character()
)
)
################################################################################
# Save output
################################################################################
write_csv(out,
path(output_dir, "trt_outcm_same_day.csv"))
write_csv(out_red,
path(output_dir, "trt_outcm_same_day_red.csv"))
8 changes: 8 additions & 0 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ actions:
moderately_sensitive:
csv: output/data_properties/ba2_sense_checks.txt

describe_trt_outcm_same_day:
run: r:latest analysis/data_properties/describe_trt_outcm_same_day.R
needs: [data_process, data_process_ba2]
outputs:
moderately_sensitive:
csv1: output/data_properties/trt_outcm_same_day.csv
csv2: output/data_properties/trt_outcm_same_day_red.csv

## # # # # # # # # # # # # # # # # # # #
## # # # # # # # # # # # # # # # # # # #
## 1 MAIN ANALYSIS - COX
Expand Down

0 comments on commit 9fcf3c4

Please sign in to comment.