| 1 |
#' @templateVar class muhaz |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A `muhaz` object returned by [muhaz::muhaz()]. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_tidy( |
| 8 |
#' "time", |
| 9 |
#' estimate = "Estimated hazard rate." |
| 10 |
#' ) |
| 11 |
#' |
| 12 |
#' @examplesIf rlang::is_installed(c("muhaz", "survival")) |
| 13 |
#' |
| 14 |
#' # load libraries for models and data |
| 15 |
#' library(muhaz) |
| 16 |
#' library(survival) |
| 17 |
#' |
| 18 |
#' # fit model |
| 19 |
#' x <- muhaz(ovarian$futime, ovarian$fustat) |
| 20 |
#' |
| 21 |
#' # summarize model fit with tidiers |
| 22 |
#' tidy(x) |
| 23 |
#' glance(x) |
| 24 |
#' |
| 25 |
#' @aliases muhaz_tidiers |
| 26 |
#' @export |
| 27 |
#' @seealso [tidy()], [muhaz::muhaz()] |
| 28 |
#' @family muhaz tidiers |
| 29 |
tidy.muhaz <- function(x, ...) { |
| 30 |
bind_cols(x[c("est.grid", "haz.est")]) |> |
| 31 |
rename("time" = "est.grid", "estimate" = "haz.est") |> |
| 32 |
as_tibble() |
| 33 |
} |
| 34 |
|
| 35 |
#' @templateVar class muhaz |
| 36 |
#' @template title_desc_glance |
| 37 |
#' |
| 38 |
#' @inherit tidy.muhaz params examples |
| 39 |
#' |
| 40 |
#' @evalRd return_glance( |
| 41 |
#' "nobs", |
| 42 |
#' "min.time", |
| 43 |
#' "max.time", |
| 44 |
#' "min.hazard", |
| 45 |
#' "max.hazard" |
| 46 |
#' ) |
| 47 |
#' |
| 48 |
#' @export |
| 49 |
#' @seealso [glance()], [muhaz::muhaz()] |
| 50 |
#' @family muhaz tidiers |
| 51 |
glance.muhaz <- function(x, ...) { |
| 52 |
bind_cols(x$pin[c("nobs", "min.time", "max.time")]) |> |
| 53 |
mutate( |
| 54 |
min.hazard = min(x$haz.est), |
| 55 |
max.hazard = max(x$haz.est) |
| 56 |
) |> |
| 57 |
as_tibble() |
| 58 |
} |