Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Apr 25, 2024
1 parent ab52dc8 commit 9a3ce4b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
29 changes: 16 additions & 13 deletions R/ard_survival_survfit_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#'
#' @param x (`survift`)\cr
#' object of class `'survfit'` typically created with [`survival::survfit()`]
#' @param conf.level (scalar `numeric`)\cr
#' confidence level for confidence interval. Default is `0.95`.
#' @inheritParams ard_survival_survfit
#'
#' @return an ARD data frame of class 'card'
Expand All @@ -31,7 +33,7 @@ ard_survival_survfit_diff <- function(x, times, conf.level = 0.95) {
}
check_range(conf.level, range = c(0, 1))
check_length(
as.list(sf$call)[["formula"]] |> as.formula() |> stats::terms() |> attr("term.labels"),
as.list(x$call)[["formula"]] |> stats::as.formula() |> stats::terms() |> attr("term.labels"),
length = 1L,
message = "The {.cls survift} object passed in argument {.arg x} must be stratified by a single variable."
)
Expand All @@ -46,20 +48,22 @@ 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"
)} |>
{
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"
)
} |>
dplyr::mutate(
difference = .data$estimate0 - .data$estimate,
difference.std.error = sqrt(.data$std.error0^2 + .data$std.error^2),
statistic = difference / difference.std.error,
conf.low = difference - difference.std.error * stats::qnorm(1 - (1 - .env$conf.level) / 2),
conf.high = difference + difference.std.error * stats::qnorm(1 - (1 - .env$conf.level) / 2),
p.value = 2 * (1 - stats::pnorm(abs(statistic)))
statistic = .data$difference / .data$difference.std.error,
conf.low = .data$difference - .data$difference.std.error * stats::qnorm(1 - (1 - .env$conf.level) / 2),
conf.high = .data$difference + .data$difference.std.error * stats::qnorm(1 - (1 - .env$conf.level) / 2),
p.value = 2 * (1 - stats::pnorm(abs(.data$statistic)))
) |>
dplyr::select(
"strata", "reference", "time",
Expand Down Expand Up @@ -112,4 +116,3 @@ tidy_summary.survfit <- function(x) {
conf.high = x$upper
)
}

2 changes: 1 addition & 1 deletion R/construction_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' Note that this list may contain non-standard evaluation components.
#' If you are wrapping this function in other functions, the argument
#' must be passed in a way that does not evaluate the list, e.g.
#' using rlang's embrace opoerator `{{ . }}`.
#' using rlang's embrace operator `{{ . }}`.
#' @param package (`string`)\cr
#' string of package name that will be temporarily loaded when function
#' specified in `method` is executed.
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jeffreys
pearson
pre
quosures
rlang's
sd
strat
vif
Expand Down
2 changes: 1 addition & 1 deletion man/ard_emmeans_mean_difference.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ard_stats_anova.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/ard_survival_survfit_diff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/construction_helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a3ce4b

Please sign in to comment.