inst/abcdmetrics/www/data.R

# Twenty years of time points
study_timepoints <- tibble(
  what = c("Baseline", paste(1:20, "years"), paste(6 + 0:19*12, "months")),
  order = c(0, 2*(1:20), 2*(1:20)-1)) |> 
  arrange(order) |> 
  filter(order <= 12)  # take a subset


# Mock study sites
study_sites <- tibble(L = LETTERS[1:21]) |> 
  mutate(site = paste0(L, L, L)) |> 
  pull(site)


# Visit status
visit_status <- tribble(
  ~status,              ~category, ~ description,
  "Not Due Yet",         "okay", "",
  "Done early",          "okay", "Participants with visits finished before the due period",
  "Done",                "okay", "Participants with visits finished on time",
  "Done late",           "okay", "",
  "Extended",            "warning", "",
  "Disposition pending", "warning", "",
  "Due Now",             "warning", "",
  "Overdue",             "ko", "",
  "Never done",          "ko", "") |> 
  mutate(category = factor(category, levels = c("okay", "warning", "ko")))

# > library(RColorBrewer)
# > brewer.pal(4, "Greens")
# [1] "#EDF8E9" "#BAE4B3" "#74C476" "#238B45"
# > brewer.pal(4, "Oranges")
# [1] "#FEEDDE" "#FDBE85" "#FD8D3C" "#D94701"
# > brewer.pal(3, "Reds")
# [1] "#FEE0D2" "#FC9272" "#DE2D26"
visit_status$color_status <- c("#EDF8E9", "#BAE4B3", "#74C476", "#238B45", "#FEEDDE", "#FDBE85", "#FD8D3C", "#D94701", "#FC9272")
# visit_status$color_category <- c(rep("#BAE4B3", 4), rep("#FDBE85", 4), "#FC9272")
color_category <- c("#BAE4B3", "#FDBE85", "#FC9272")


# Generation of mock data
set.seed(19860509)
mock_data <- expand.grid(study_sites, study_timepoints$what, visit_status$status, stringsAsFactors = FALSE) |> 
  as_tibble() |> 
  rename(site = Var1, timepoint = Var2, status = Var3) |> 
  mutate(n = round(runif(n(), 1, 100))) |> 
  mutate(timepoint = factor(timepoint, levels = study_timepoints$what))

mock_data_all <- mock_data |> 
  group_by(timepoint, status) |> 
  summarise(n = sum(n), .groups = "drop") |>
  mutate(site = "_ALL SITES_")

mock_data <- bind_rows(mock_data, mock_data_all)

mock_data <- left_join(mock_data, visit_status, by = "status")
ucsd-dsm/abcd-metrics documentation built on April 27, 2022, 12:06 a.m.