# Generate the synthetic edge table used by the trial-participant Sankey recipe.
script_dir <- local({
arg <- grep("^--file=", commandArgs(trailingOnly = FALSE), value = TRUE)
path <- if (length(arg)) sub("^--file=", "", arg[[1L]]) else sys.frame(1)$ofile
dirname(normalizePath(path, mustWork = TRUE))
})
out_csv <- file.path(script_dir, "..", "csv", "trial_participant_flow.csv")
dir.create(dirname(out_csv), recursive = TRUE, showWarnings = FALSE)
trial_participant_flow <- data.frame(
source = c(
"Assessed", "Assessed",
"Excluded", "Excluded", "Excluded",
"Randomized", "Randomized",
"Intervention", "Intervention", "Control", "Control",
"Treated", "Treated", "Treated",
"Received control", "Received control", "Received control",
"Intervention follow-up", "Intervention follow-up",
"Control follow-up", "Control follow-up"
),
target = c(
"Randomized", "Excluded",
"Ineligible", "Declined", "Other reasons",
"Intervention", "Control",
"Treated", "Not treated", "Received control", "No control",
"Intervention follow-up", "Intervention lost", "Intervention stopped",
"Control follow-up", "Control lost", "Control stopped",
"Intervention analyzed", "Intervention excluded",
"Control analyzed", "Control excluded"
),
n = c(
900, 300, 180, 90, 30, 450, 450, 430, 20, 425, 25,
375, 35, 20, 370, 40, 15, 372, 3, 366, 4
),
stage = c(
rep("Screening", 5), rep("Allocation", 6),
rep("Follow-up", 6), rep("Analysis", 4)
),
stringsAsFactors = FALSE
)
internal_nodes <- intersect(trial_participant_flow$source, trial_participant_flow$target)
for (node in internal_nodes) {
stopifnot(
sum(trial_participant_flow$n[trial_participant_flow$target == node]) ==
sum(trial_participant_flow$n[trial_participant_flow$source == node])
)
}
write.csv(trial_participant_flow, out_csv, row.names = FALSE)