Skip to content

Commit

Permalink
minimise output km curves
Browse files Browse the repository at this point in the history
  • Loading branch information
Linda Nab committed Nov 26, 2023
1 parent 4b2e5f8 commit 5dd0cf4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
33 changes: 19 additions & 14 deletions analysis/km.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ args <- commandArgs(trailingOnly=TRUE)

if(length(args)==0){
# use for interactive testing
df_input <- "output/data/data_long_all.feather"
dir_output <- "output/figures/km_estimates/"
df_input <- "output/plr/data/data_long_all_plr.feather"
dir_output <- "output/plr/figures/km_estimates/"
period <- "ba1"
contrast <- "all"
exposure <- c("arm")
Expand Down Expand Up @@ -274,7 +274,9 @@ for (subgroup_i in subgroups) {
.subgroup_var = subgroup_i,
.subgroup,
!!exposure_sym,
time, lagtime, interval,
tstart = lagtime,
tend = time,
interval_length = interval,
#cml.event, cml.censor,
N,
n.risk, n.risk.r,
Expand All @@ -297,12 +299,16 @@ for (subgroup_i in subgroups) {

data_surv_rounded_red <-
data_surv_rounded %>%
select(-c(n.risk, n.event, cml.event,
select(-c(N, n.risk, n.event, cml.event,
n.censor, cml.censor, estimate,
std.error, conf.high, conf.low,
surv.se, surv.low, surv.high,
risk.se, risk.low, risk.high))
write_csv(data_surv_rounded_red, fs::path(dir_output, paste0(file_name, "_red.csv")))
data_surv_rounded_red2 <-
data_surv_rounded_red %>%
select(-c(n.censor.r, cml.censor.r, surv, surv.se.approx, surv.low.approx, surv.high.approx, risk.se.approx))
write_csv(data_surv_rounded_red2, fs::path(dir_output, paste0(file_name, "_red2.csv")))

if(plot){

Expand All @@ -311,18 +317,17 @@ for (subgroup_i in subgroups) {
group_modify(
~ add_row(
.x,
time = 0, # assumes time origin is zero
lagtime = 0,
tstart = 0, # assumes time origin is zero
tend = 0,
estimate = 1,
conf.low = 1,
conf.high = 1,
.before = 0
)
) %>%
ggplot(aes(group = !!exposure_sym, colour = !!exposure_sym, fill = !!exposure_sym)) +
geom_step(aes(x = time, y = {1 - estimate}), direction = "vh") +
geom_step(aes(x = time, y = {1 - estimate}), direction = "vh", linetype = "dashed", alpha = 0.5) +
geom_rect(aes(xmin = lagtime, xmax = time, ymin = {1 - conf.high}, ymax = {1 - conf.low}), alpha = 0.1, colour = "transparent") +
geom_step(aes(x = tend, y = {1 - estimate}), direction = "hv") +
geom_rect(aes(xmin = tstart, xmax = tend, ymin = {1 - conf.high}, ymax = {1 - conf.low}), alpha = 0.1, colour = "transparent") +
facet_grid(rows = vars(.subgroup)) +
scale_color_brewer(type = "qual", palette = "Set1", na.value = "grey") +
scale_fill_brewer(type = "qual", palette = "Set1", guide = "none", na.value = "grey") +
Expand All @@ -348,8 +353,8 @@ for (subgroup_i in subgroups) {
group_modify(
~ add_row(
.x,
time = 0, # assumes time origin is zero
lagtime = 0,
tstart = 0, # assumes time origin is zero
tend = 0,
surv = 1,
risk = 0,
risk.low.approx = 0,
Expand All @@ -358,9 +363,9 @@ for (subgroup_i in subgroups) {
)
) %>%
ggplot(aes(group = !!exposure_sym, colour = !!exposure_sym, fill = !!exposure_sym)) +
geom_step(aes(x = time, y = risk), direction = "vh") +
geom_step(aes(x = time, y = risk), direction = "vh", linetype = "dashed", alpha = 0.5) +
geom_rect(aes(xmin = lagtime, xmax = time, ymin = risk.low.approx, ymax = risk.high.approx), alpha = 0.1, colour = "transparent") +
geom_step(aes(x = tend, y = risk), direction = "vh") +
geom_step(aes(x = tend, y = risk), direction = "vh", linetype = "dashed", alpha = 0.5) +
geom_rect(aes(xmin = tstart, xmax = tend, ymin = risk.low.approx, ymax = risk.high.approx), alpha = 0.1, colour = "transparent") +
facet_grid(rows = vars(.subgroup)) +
scale_color_brewer(type = "qual", palette = "Set1", na.value = "grey") +
scale_fill_brewer(type = "qual", palette = "Set1", guide = "none", na.value = "grey") +
Expand Down
12 changes: 6 additions & 6 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,7 @@ actions:
feather: output/plr/figures/km_estimates/km_estimates.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/km_estimates.csv
csv2: output/plr/figures/km_estimates/km_estimates_red.csv
csv2: output/plr/figures/km_estimates/km_estimates_red*.csv
plot1: output/plr/figures/km_estimates/km_estimates.png
plot2: output/plr/figures/km_estimates/km_estimates_red.png

Expand All @@ -2868,7 +2868,7 @@ actions:
feather: output/plr/figures/km_estimates/km_estimates_molnupiravir.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/km_estimates_molnupiravir.csv
csv2: output/plr/figures/km_estimates/km_estimates_molnupiravir_red.csv
csv2: output/plr/figures/km_estimates/km_estimates_molnupiravir_red*.csv
plot1: output/plr/figures/km_estimates/km_estimates_molnupiravir.png
plot2: output/plr/figures/km_estimates/km_estimates_molnupiravir_red.png

Expand All @@ -2884,7 +2884,7 @@ actions:
feather: output/plr/figures/km_estimates/km_estimates_sotrovimab.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/km_estimates_sotrovimab.csv
csv2: output/plr/figures/km_estimates/km_estimates_sotrovimab_red.csv
csv2: output/plr/figures/km_estimates/km_estimates_sotrovimab_red*.csv
plot1: output/plr/figures/km_estimates/km_estimates_sotrovimab.png
plot2: output/plr/figures/km_estimates/km_estimates_sotrovimab_red.png

Expand All @@ -2900,7 +2900,7 @@ actions:
feather: output/plr/figures/km_estimates/ba2_km_estimates.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/ba2_km_estimates.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_red.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_red*.csv
plot1: output/plr/figures/km_estimates/ba2_km_estimates.png
plot2: output/plr/figures/km_estimates/ba2_km_estimates_red.png

Expand All @@ -2917,7 +2917,7 @@ actions:
feather: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir_red.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir_red*.csv
plot1: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir.png
plot2: output/plr/figures/km_estimates/ba2_km_estimates_molnupiravir_red.png

Expand All @@ -2934,7 +2934,7 @@ actions:
feather: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab.feather
moderately_sensitive:
csv1: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab_red.csv
csv2: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab_red*.csv
plot1: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab.png
plot2: output/plr/figures/km_estimates/ba2_km_estimates_sotrovimab_red.png

Expand Down

0 comments on commit 5dd0cf4

Please sign in to comment.