Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Apr 26, 2024
1 parent 9a3ce4b commit f16c3d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 4 additions & 1 deletion R/ard_survival_survfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) {
dplyr::vars("conf.high", "conf.low"),
~ ifelse(is.na(.) & .data$std.error == 0, .data$estimate, .)
) %>%
dplyr::select(dplyr::any_of(c("time", "estimate", "conf.high", "conf.low", "strata"))) %>%
dplyr::select(dplyr::any_of(c(
"time", "estimate", "std.error", "conf.high", "conf.low",
"strata", "n.risk"
))) %>%
# add data for time 0
dplyr::bind_rows(
dplyr::group_by_at(., dplyr::vars(dplyr::any_of("strata"))) %>%
Expand Down
25 changes: 13 additions & 12 deletions R/ard_survival_survfit_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ ard_survival_survfit_diff <- function(x, times, conf.level = 0.95) {
summary(x, times = times) |>
tidy_summary.survfit() |>
dplyr::select(any_of(c("strata", "time", "estimate", "std.error"))) %>%
{
dplyr::left_join(
dplyr::filter(., .data$strata != .data$strata[1]) |> dplyr::mutate(reference = .$strata[1]),
dplyr::filter(., .data$strata == .data$strata[1]) |>
dplyr::select(-"strata") |>
dplyr::rename_with(.fn = ~ paste0(., "0"), .cols = -"time"),
by = "time"
)
} |>
# styler: off
{dplyr::left_join(
dplyr::filter(., .data$strata != .data$strata[1]) |>
dplyr::mutate(contrast = paste(.$strata[1], "-", .data$strata)),
dplyr::filter(., .data$strata == .data$strata[1]) |>
dplyr::select(-"strata") |>
dplyr::rename_with(.fn = ~ paste0(., "0"), .cols = -"time"),
by = "time"
)} |>
# styler: on
dplyr::mutate(
difference = .data$estimate0 - .data$estimate,
difference.std.error = sqrt(.data$std.error0^2 + .data$std.error^2),
Expand All @@ -66,12 +67,13 @@ ard_survival_survfit_diff <- function(x, times, conf.level = 0.95) {
p.value = 2 * (1 - stats::pnorm(abs(.data$statistic)))
) |>
dplyr::select(
"strata", "reference", "time",
"strata", "contrast", "time",
estimate = "difference",
std.error = "difference.std.error",
"statistic", "conf.low", "conf.high", "p.value"
) |>
tidyr::separate_wider_delim("strata", "=", names = c("group1", "group1_level")) |>
extract_multi_strata(x = x, df_stat = _)
tidyr::separate_wider_delim("strata", "=", names = c("group1", "group1_level")) |>
dplyr::mutate(
across(-cards::all_ard_groups("names"), as.list)
) |>
Expand All @@ -88,7 +90,6 @@ ard_survival_survfit_diff <- function(x, times, conf.level = 0.95) {
fmt_fn = list(1L),
stat_label =
dplyr::case_when(
.data$stat_name %in% "reference" ~ "Reference Group (ref - est)",
.data$stat_name %in% "estimate" ~ "Survival Difference",
.data$stat_name %in% "std.error" ~ "Survival Difference Standard Error",
.data$stat_name %in% "conf.low" ~ "CI Lower Bound",
Expand Down

0 comments on commit f16c3d5

Please sign in to comment.