R/survival-survexp-tidiers.R

Defines functions glance.survexp tidy.survexp

Documented in glance.survexp tidy.survexp

#' @templateVar class survexp
#' @template title_desc_tidy
#'
#' @param x An `survexp` object returned from [survival::survexp()].
#' @template param_unused_dots
#'
#' @evalRd return_tidy("time", "n.risk",
#'   estimate = "Estimate survival"
#' )
#'
#' @examplesIf rlang::is_installed("survival")
#'
#' # load libraries for models and data
#' library(survival)
#' 
#' # fit model
#' sexpfit <- survexp(
#'   futime ~ 1,
#'   rmap = list(
#'     sex = "male",
#'     year = accept.dt,
#'     age = (accept.dt - birth.dt)
#'   ),
#'   method = "conditional",
#'   data = jasa
#' )
#'
#' # summarize model fit with tidiers
#' tidy(sexpfit)
#' glance(sexpfit)
#' 
#' @aliases sexpfit_tidiers survexp_tidiers
#' @export
#' @seealso [tidy()], [survival::survexp()]
#' @family survexp tidiers
#' @family survival tidiers
tidy.survexp <- function(x, ...) {
  ret <- as_tibble(summary(x)[c("time", "surv", "n.risk")])
  rename(ret, "estimate" = "surv")
}


#' @templateVar class survexp
#' @template title_desc_glance
#'
#' @inherit tidy.survexp params examples
#'
#' @evalRd return_glance("n.max", "n.start", "timepoints")
#'
#' @export
#' @seealso [glance()], [survival::survexp()]
#' @family survexp tidiers
#' @family survival tidiers
glance.survexp <- function(x, ...) {
  as_glance_tibble(
    n.max = max(x$n.risk),
    n.start = x$n.risk[1],
    timepoints = length(x$n.risk),
    na_types = "iii"
  )
}

Try the broom package in your browser

Any scripts or data that you put into this service are public.

broom documentation built on Aug. 30, 2022, 1:07 a.m.