| 1 |
#' @templateVar class aareg |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x An `aareg` object returned from [survival::aareg()]. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_tidy( |
| 8 |
#' "term", |
| 9 |
#' "estimate", |
| 10 |
#' "statistic", |
| 11 |
#' "std.error", |
| 12 |
#' "robust.se", |
| 13 |
#' "z", |
| 14 |
#' "p.value" |
| 15 |
#' ) |
| 16 |
#' |
| 17 |
#' @details `robust.se` is only present when `x` was created with |
| 18 |
#' `dfbeta = TRUE`. |
| 19 |
#' |
| 20 |
#' @examplesIf rlang::is_installed("survival") |
| 21 |
#' |
| 22 |
#' # load libraries for models and data |
| 23 |
#' library(survival) |
| 24 |
#' |
| 25 |
#' # fit model |
| 26 |
#' afit <- aareg( |
| 27 |
#' Surv(time, status) ~ age + sex + ph.ecog, |
| 28 |
#' data = lung, |
| 29 |
#' dfbeta = TRUE |
| 30 |
#' ) |
| 31 |
#' |
| 32 |
#' # summarize model fit with tidiers |
| 33 |
#' tidy(afit) |
| 34 |
#' |
| 35 |
#' @aliases aareg_tidiers |
| 36 |
#' @export |
| 37 |
#' @seealso [tidy()], [survival::aareg()] |
| 38 |
#' @family aareg tidiers |
| 39 |
#' @family survival tidiers |
| 40 |
#' |
| 41 |
tidy.aareg <- function(x, ...) { |
| 42 |
if (is.null(x$dfbeta)) { |
| 43 |
nn <- c("estimate", "statistic", "std.error", "statistic.z", "p.value") |
| 44 |
} else { |
| 45 |
nn <- c( |
| 46 |
"estimate", |
| 47 |
"statistic", |
| 48 |
"std.error", |
| 49 |
"robust.se", |
| 50 |
"statistic.z", |
| 51 |
"p.value" |
| 52 |
) |
| 53 |
} |
| 54 |
|
| 55 |
as_tidy_tibble( |
| 56 |
summary(x)$table, |
| 57 |
new_names = nn |
| 58 |
) |
| 59 |
} |
| 60 |
|
| 61 |
#' @templateVar class aareg |
| 62 |
#' @template title_desc_glance |
| 63 |
#' |
| 64 |
#' @inherit tidy.aareg params examples |
| 65 |
#' |
| 66 |
#' @evalRd return_glance("statistic", "p.value", "df", "nobs") |
| 67 |
#' |
| 68 |
#' @export |
| 69 |
#' @seealso [glance()], [survival::aareg()] |
| 70 |
#' @family aareg tidiers |
| 71 |
#' @family survival tidiers |
| 72 |
glance.aareg <- function(x, ...) { |
| 73 |
s <- summary(x) |
| 74 |
chi <- as.numeric(s$chisq) |
| 75 |
df <- length(s$test.statistic) - 1 |
| 76 |
|
| 77 |
as_glance_tibble( |
| 78 |
statistic = chi, |
| 79 |
p.value = as.numeric(1 - stats::pchisq(chi, df)), |
| 80 |
df = df, |
| 81 |
nobs = stats::nobs(x), |
| 82 |
na_types = "rrii" |
| 83 |
) |
| 84 |
} |