| 1 |
#' @templateVar class survexp |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x An `survexp` object returned from [survival::survexp()]. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_tidy("time", "n.risk", |
| 8 |
#' estimate = "Estimate survival" |
| 9 |
#' ) |
| 10 |
#' |
| 11 |
#' @examplesIf rlang::is_installed("survival") |
| 12 |
#' |
| 13 |
#' # load libraries for models and data |
| 14 |
#' library(survival) |
| 15 |
#' |
| 16 |
#' # fit model |
| 17 |
#' sexpfit <- survexp( |
| 18 |
#' futime ~ 1, |
| 19 |
#' rmap = list( |
| 20 |
#' sex = "male", |
| 21 |
#' year = accept.dt, |
| 22 |
#' age = (accept.dt - birth.dt) |
| 23 |
#' ), |
| 24 |
#' method = "conditional", |
| 25 |
#' data = jasa |
| 26 |
#' ) |
| 27 |
#' |
| 28 |
#' # summarize model fit with tidiers |
| 29 |
#' tidy(sexpfit) |
| 30 |
#' glance(sexpfit) |
| 31 |
#' |
| 32 |
#' @aliases sexpfit_tidiers survexp_tidiers |
| 33 |
#' @export |
| 34 |
#' @seealso [tidy()], [survival::survexp()] |
| 35 |
#' @family survexp tidiers |
| 36 |
#' @family survival tidiers |
| 37 |
tidy.survexp <- function(x, ...) { |
| 38 |
ret <- as_tibble(summary(x)[c("time", "surv", "n.risk")]) |
| 39 |
rename(ret, "estimate" = "surv") |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
#' @templateVar class survexp |
| 44 |
#' @template title_desc_glance |
| 45 |
#' |
| 46 |
#' @inherit tidy.survexp params examples |
| 47 |
#' |
| 48 |
#' @evalRd return_glance("n.max", "n.start", "timepoints") |
| 49 |
#' |
| 50 |
#' @export |
| 51 |
#' @seealso [glance()], [survival::survexp()] |
| 52 |
#' @family survexp tidiers |
| 53 |
#' @family survival tidiers |
| 54 |
glance.survexp <- function(x, ...) { |
| 55 |
as_glance_tibble( |
| 56 |
n.max = max(x$n.risk), |
| 57 |
n.start = x$n.risk[1], |
| 58 |
timepoints = length(x$n.risk), |
| 59 |
na_types = "iii" |
| 60 |
) |
| 61 |
} |