Simulated trial data

Published

April 16, 2024

Modified

April 11, 2024

The following give a sense of the number of participants contributing to each treatment arm and cell. The data are simulated under the model specification with a total sample size of 2500.

Code
set.seed(1)
ll <- get_trial_data(N = 2500)

d <- copy(ll$d)

Surgical domain

Only patients in the late silo receive randomised surgical treatment (dair vs revision) with the type of revision selected by the clinician. Table 1 shows the allocation to dair vs rev for this cohort and the balance across the remaining group levels in the data.

Code
# domain B
d_tmp1 <- d[l1 == 1 & er == 1, .(er, r, ed, srp, d)]
d_tmp2 <- d_tmp1[, .N, keyby = .(r, ed, srp, d)]
d_B <- dcast(d_tmp2, ed + d + srp ~ r, value.var = "N")
d_B[, domain := "Duration"]
colnames(d_B) <- c("rand", "group", "surgery", "dair", "rev", "domain")
setcolorder(d_B, "domain")
# domain C
d_tmp1 <- d[l1 == 1 & er == 1, .(er, r, ef, srp, f)]
d_tmp2 <- d_tmp1[, .N, keyby = .(r, ef, srp, f)]
d_C <- dcast(d_tmp2, ef + f + srp ~ r, value.var = "N")
d_C[, domain := "Choice"]
colnames(d_C) <- c("rand", "group", "surgery", "dair", "rev", "domain")
setcolorder(d_C, "domain")

d_tbl <- rbind(d_B, d_C, fill = TRUE)
# d_tbl[, group := factor(group, levels = c("w12","w12p1", "w06p1", "w12p2", "d07p2", "other", "norif", "rif"))]
d_tbl <- d_tbl[order(domain, rand, surgery, group)]

d_tbl[, total := rowSums(d_tbl[, .(dair, rev)], na.rm = T)]
d_tbl[domain == "Choice" & rand == 0, group := NA]
d_tbl[domain == "Duration" & rand == 0, group := NA]

cols <- c("Domain", "Revealed", "Treatment", "Surgery recvd", "DAIR", "Revision", "Total")
names(cols) <- names(d_tbl)

gt_tbl <- d_tbl |> 
  gt(groupname_col = "domain"
  )  |>
  tab_spanner(
    label = html("Domain A (late silo)"),
    columns = c(dair, rev),
    id = "da"
  ) |>
  sub_missing(
    columns = everything(),
    missing_text = "-"
  ) |>
  cols_label(.list = cols) |> 
  summary_rows(
    columns = c("dair", "rev", "total"),
    fns = list(
      subtotal = ~ sum(., na.rm = TRUE)
    )
  )  |>
  tab_footnote(
    footnote = "Revealed indicates whether units were randomised into choice/duration domain (0: No, 1: Yes)",
    locations = cells_column_labels(columns = rand)
  ) |>
  tab_footnote(
    footnote = "Surgery recvd indicates surgery type actually perfromed (0: dair, 1: one-stage, 2: two-stage). Surgery recvd may deviate from original randomisation/plan.",
    locations = cells_column_labels(columns = surgery)
  ) |>
  tab_footnote(
    footnote = "Treatment indicates which treatment assigned within domain. For choice (0: no-rif, 1: rif). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the choice/duration domain have undefined randomised treatment status.",
    locations = cells_column_labels(columns = group)
  ) |>
  tab_footnote(
    footnote = "Only units randomised to surgery domain reported.",
    locations = cells_column_spanners(spanners = "da")
  )

gt_tbl
Revealed2 Treatment3 Surgery recvd4 Domain A (late silo)1 Total
DAIR Revision
Choice
0 - 0 253 - 253
0 - 1 - 77 77
0 - 2 - 178 178
1 0 0 198 - 198
1 1 0 182 - 182
1 0 1 - 68 68
1 1 1 - 56 56
1 0 2 - 121 121
1 1 2 - 142 142
subtotal 633 642 1275
Duration
0 - 0 633 - 633
1 0 1 - 91 91
1 1 1 - 110 110
1 0 2 - 224 224
1 1 2 - 217 217
subtotal 633 642 1275
1 Only units randomised to surgery domain reported.
2 Revealed indicates whether units were randomised into choice/duration domain (0: No, 1: Yes)
3 Treatment indicates which treatment assigned within domain. For choice (0: no-rif, 1: rif). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the choice/duration domain have undefined randomised treatment status.
4 Surgery recvd indicates surgery type actually perfromed (0: dair, 1: one-stage, 2: two-stage). Surgery recvd may deviate from original randomisation/plan.
Table 1: Simulated trial data for (late silo) surgical domain - covariate balance across other groups

Duration domain

Table 2 shows the allocation to the duration domain conditional on surgery type actually received and the balance across the remaining group levels in the data. Only units randomised within the duration domain are reported.

Code
# domain B
d_tmp1 <- d[ed == 1, .(ed, d, er, r, srp)]
d_tmp2 <- d_tmp1[, .N, keyby = .(d, er, r,srp)]
# d_tmp2[, b := factor(b, levels = c("w12", "w06p1", "w12p1", "d07p2", "w12p2"))]
d_B <- dcast(d_tmp2, er + r ~ srp + d, value.var = "N")
d_B[, domain := "Surgery"]
colnames(d_B) <- c("rand", "group", c("long_1", "short_1", "long_2", "short_2"), "domain")
setcolorder(d_B, "domain")
# domain C
d_tmp1 <- d[ed == 1, .(ed, d, ef, f, srp)]
d_tmp2 <- d_tmp1[, .N, keyby = .(d, ef, f, srp)]
# d_tmp2[, b := factor(b, levels = c("w12", "w06p1", "w12p1", "d07p2", "w12p2"))]
d_C <- dcast(d_tmp2, ef + f ~ srp + d, value.var = "N")
d_C[, domain := "Choice"]
colnames(d_C) <- c("rand", "group", c("long_1", "short_1", "long_2", "short_2"), "domain")
setcolorder(d_C, "domain")

d_tbl <- rbind(d_B, d_C, fill = T)

d_tbl[, total := rowSums(d_tbl[, .(long_1, short_1, long_2, short_2)], na.rm = T)]
d_tbl[domain == "Surgery" & rand == 0, group := NA]
d_tbl[domain == "Choice" & rand == 0, group := NA]

cols <- c("Domain", "Revealed", "Treatment", c("long", "short", "long", "short"), "Total")
names(cols) <- names(d_tbl)

gt_tbl <- d_tbl |> 
  gt(groupname_col = "domain"
  ) |> 
  summary_rows(
    columns = c("long_1", "short_1", "long_2", "short_2", "total"),
    fns = list(
      subtotal = ~ sum(., na.rm = TRUE)
    )
  )   |>
  tab_spanner(
    label = html("AB Duration <br>(one-stage)"),
    columns = c("long_1", "short_1"),
    id = "d1"
  ) |>
  tab_spanner(
    label = html("AB Duration <br>(two-stage)"),
    columns = c("long_2", "short_2"),
    id = "d2"
  ) |>
  sub_missing(
    columns = everything(),
    missing_text = "-"
  ) |>
  cols_label(.list = cols)  |>
  tab_footnote(
    footnote = "Revealed indicates whether units were randomised into surgery/duration domain (0: No, 1: Yes)",
    locations = cells_column_labels(columns = rand)
  ) |>
  tab_footnote(
    footnote = "Treatment indicates which treatment assigned within domain. For choice (0: no-rif, 1: rif). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the surgery/choice domain have undefined randomised treatment status.",
    locations = cells_column_labels(columns = group)
  ) |>
  tab_footnote(
    footnote = "Only units randomised to interventions in the surgery domain reported. One-stage/two-stage is by clinician selection",
    locations = cells_column_spanners(spanners = c("d1", "d2"))
  )



gt_tbl
Revealed2 Treatment3 AB Duration
(one-stage)1
AB Duration
(two-stage)1
Total
long short long short
Surgery
0 - 88 88 159 147 482
1 1 91 110 224 217 642
subtotal 179 198 383 364 1124
Choice
0 - 71 83 151 151 456
1 0 56 60 100 105 321
1 1 52 55 132 108 347
subtotal 179 198 383 364 1124
1 Only units randomised to interventions in the surgery domain reported. One-stage/two-stage is by clinician selection
2 Revealed indicates whether units were randomised into surgery/duration domain (0: No, 1: Yes)
3 Treatment indicates which treatment assigned within domain. For choice (0: no-rif, 1: rif). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the surgery/choice domain have undefined randomised treatment status.
Table 2: Simulated trial data for AB duration domain - covariate balance across other groups

Choice domain

Table 3 shows the allocation to the choice domain and the balance across the remaining group levels in the data. Only units randomised within the antibiotic choice domain are reported.

Code
# domain 
d_tmp1 <- d[ef == 1, .(f, er, r, srp)]
d_tmp2 <- d_tmp1[, .N, keyby = .(f, er, r, srp)]
# d_tmp2[, a := factor(a, levels = c("dair", "rev", "one", "two"))]
# d_tmp2[, qa := factor(qa, levels = c("dair", "one", "two"))]
# d_tmp2[, c := factor(c, levels = c("other", "norif", "rif"))]
d_A <- dcast(d_tmp2, er + srp + r ~ f, value.var = "N")
d_A[, domain := "Surgery"]
colnames(d_A) <- c("rand", "surgery","group",  c("norif", "rif"), "domain")
setcolorder(d_A, "domain")
# domain
d_tmp1 <- d[ef == 1, .(f, ed, d, srp)]
d_tmp2 <- d_tmp1[, .N, keyby = .(f, ed, d, srp)]
# d_tmp2[, b := factor(b, levels = c("w12", "w06p1", "w12p1", "d07p2", "w12p2"))]
# d_tmp2[, c := factor(c, levels = c("other", "norif", "rif"))]
d_B <- dcast(d_tmp2, ed + srp + d ~ f, value.var = "N")
d_B[, domain := "Duration"]
colnames(d_B) <- c("rand", "surgery", "group", c("norif", "rif"), "domain")
setcolorder(d_B, "domain")

d_tbl <- rbind(d_A, d_B, fill = T)

d_tbl[, total := rowSums(d_tbl[, .(norif, rif)], na.rm = T)]

d_tbl[domain == "Surgery" & rand == 0, group := NA]
d_tbl[domain == "Duration" & rand == 0, group := NA]



cols <- c("Domain", "Revealed", "Surgery recvd", "Treatment", c("norif", "rif"), "Total")
names(cols) <- names(d_tbl)

gt_tbl <- d_tbl |> 
  gt(groupname_col = "domain"
  ) |> 
  summary_rows(
    columns = c("norif", "rif", "total"),
    fns = list(
      subtotal = ~ sum(., na.rm = TRUE)
    )
  ) |>
  tab_spanner(
    label = html("AB Choice"),
    columns = c("norif", "rif"),
    id = "c1"
  ) |>
  sub_missing(
    columns = everything(),
    missing_text = "-"
  ) |>
  cols_label(.list = cols)|>
  tab_footnote(
    footnote = "Revealed indicates whether units were randomised into surgery/choice domain (0: No, 1: Yes)",
    locations = cells_column_labels(columns = rand)
  ) |>
  tab_footnote(
    footnote = "Treatment indicates which treatment assigned within domain. For surgery (0: dair, 1: rev). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the surgery/duration domain have undefined randomised treatment status.",
    locations = cells_column_labels(columns = group)
  ) |>
  tab_footnote(
    footnote = "Only units randomised to interventions in the antibiotic choice domain reported.",
    locations = cells_column_spanners(spanners = c("c1"))
  )

gt_tbl
Revealed2 Surgery recvd Treatment3 AB Choice1 Total
norif rif
Surgery
0 0 - 229 232 461
0 1 - 48 51 99
0 2 - 84 98 182
1 0 0 198 182 380
1 1 1 68 56 124
1 2 1 121 142 263
subtotal 748 761 1509
Duration
0 0 - 427 414 841
1 1 0 56 52 108
1 1 1 60 55 115
1 2 0 100 132 232
1 2 1 105 108 213
subtotal 748 761 1509
1 Only units randomised to interventions in the antibiotic choice domain reported.
2 Revealed indicates whether units were randomised into surgery/choice domain (0: No, 1: Yes)
3 Treatment indicates which treatment assigned within domain. For surgery (0: dair, 1: rev). For duration is specific to surgery type received (0: long, 1: short). Units that were not randomised within the surgery/duration domain have undefined randomised treatment status.
Table 3: Simulated trial data for AB choice domain - covariate balance across other groups