|
12 | 12 | }
|
13 | 13 |
|
14 | 14 | # Computes the win odds from the internal data.
|
15 |
| -.compute_win_odds <- function(hce_dat, arm_levels) { |
| 15 | +.compute_win_odds <- function(hce_dat, arm_levels, |
| 16 | + step_outcomes, last_outcome) { |
| 17 | + |
16 | 18 | hce_dat <- base::as.data.frame(hce_dat)
|
17 | 19 | hce_dat <- .with_ordered_column(hce_dat)
|
18 | 20 | fit <- hce::calcWO(x = hce_dat, AVAL = "ordered",
|
|
27 | 29 | ref = unname(arm_levels["control"]),
|
28 | 30 | GROUP = "outcome")
|
29 | 31 |
|
| 32 | + endpoints <- c(step_outcomes, last_outcome) |
| 33 | + hce_dat <- hce_dat %>% |
| 34 | + dplyr::mutate_at(dplyr::vars(outcome), factor, levels = c(endpoints, "X")) |
| 35 | + |
| 36 | + calcs_lst <- lapply(seq_along(endpoints), function(x) { |
| 37 | + idx <- !(hce_dat$outcome %in% endpoints[1:x]) |
| 38 | + hce_dat[idx, "outcome"] <- "X" |
| 39 | + hce_dat[idx, "ordered"] <- 1000000 |
| 40 | + wins <- hce::calcWINS(hce_dat, AVAL = "ordered", TRTP = "arm", |
| 41 | + ref = unname(arm_levels["control"]), |
| 42 | + GROUP = "outcome") |
| 43 | + wo <- hce::summaryWO(hce_dat, AVAL = "ordered", TRTP = "arm", |
| 44 | + ref = unname(arm_levels["control"]), |
| 45 | + GROUP = "outcome") |
| 46 | + list("wins" = wins, "wo" = wo) |
| 47 | + }) |
| 48 | + |
| 49 | + wins_forest <- do.call("rbind", lapply(calcs_lst, function(c_lst) { |
| 50 | + wins <- c_lst$wins |
| 51 | + nm <- c("value", "LCL", "UCL", "p value") |
| 52 | + rbind(data.frame(setNames(wins$WO, nm), "method" = "win odds"), |
| 53 | + data.frame(setNames(wins$WR1, nm), "method" = "win ratio")) |
| 54 | + })) |
| 55 | + |
| 56 | + wo_bar <- do.call("rbind", lapply(seq_along(calcs_lst), function(i) { |
| 57 | + wo <- head(calcs_lst[[i]]$wo$summary, 1) |
| 58 | + wo$outcome <- endpoints[i] |
| 59 | + wo %>% |
| 60 | + dplyr::rename(dplyr::all_of(c(wins = "WIN", losses = "LOSS", |
| 61 | + ties = "TIE"))) %>% |
| 62 | + tidyr::pivot_longer(cols = c(wins, losses, ties)) %>% |
| 63 | + dplyr::mutate_at(dplyr::vars(name), factor, |
| 64 | + levels = c("wins", "losses", "ties")) |
| 65 | + })) |
| 66 | + |
30 | 67 | return(list("win_odds" = win_odds,
|
31 |
| - "win_odds_outcome" = win_odds_outcome)) |
| 68 | + "win_odds_outcome" = win_odds_outcome, |
| 69 | + "wins_forest" = wins_forest, |
| 70 | + "wo_bar" = wo_bar)) |
32 | 71 |
|
33 | 72 | }
|
34 | 73 |
|
|
333 | 372 | x = base::sum(value, na.rm = TRUE),
|
334 | 373 | average = 100 *
|
335 | 374 | as.numeric(stats::prop.test(x, n)$estimate),
|
336 |
| - se = abs(average - (100 * |
337 |
| - as.numeric(stats::prop.test(x, n)$conf.int)[1]))) %>% |
| 375 | + se = abs(average - |
| 376 | + (100 * as.numeric( |
| 377 | + stats::prop.test(x, n)$conf.int)[1]))) %>% |
338 | 378 | dplyr::ungroup()
|
339 | 379 |
|
340 | 380 | # To create ellipsis shape and avoid overlapping between both of them,
|
|
0 commit comments