| 1 |
#' @templateVar class rlm |
| 2 |
#' @template title_desc_glance |
| 3 |
#' |
| 4 |
#' @param x An `rlm` object returned by [MASS::rlm()]. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_glance( |
| 8 |
#' "sigma", |
| 9 |
#' "converged", |
| 10 |
#' "logLik", |
| 11 |
#' "AIC", |
| 12 |
#' "BIC", |
| 13 |
#' "deviance", |
| 14 |
#' "nobs" |
| 15 |
#' ) |
| 16 |
#' |
| 17 |
#' @examplesIf rlang::is_installed("MASS") |
| 18 |
#' |
| 19 |
#' # load libraries for models and data |
| 20 |
#' library(MASS) |
| 21 |
#' |
| 22 |
#' # fit model |
| 23 |
#' r <- rlm(stack.loss ~ ., stackloss) |
| 24 |
#' |
| 25 |
#' # summarize model fit with tidiers |
| 26 |
#' tidy(r) |
| 27 |
#' augment(r) |
| 28 |
#' glance(r) |
| 29 |
#' |
| 30 |
#' @export |
| 31 |
#' @aliases rlm_tidiers |
| 32 |
#' @family rlm tidiers |
| 33 |
#' @seealso [glance()], [MASS::rlm()] |
| 34 |
glance.rlm <- function(x, ...) { |
| 35 |
s <- summary(x) |
| 36 |
tibble( |
| 37 |
sigma = s$sigma, |
| 38 |
converged = x$converged, |
| 39 |
logLik = stats::logLik(x), |
| 40 |
AIC = stats::AIC(x), |
| 41 |
BIC = stats::BIC(x), |
| 42 |
deviance = stats::deviance(x), |
| 43 |
nobs = stats::nobs(x) |
| 44 |
) |
| 45 |
} |
| 46 |
|
| 47 |
# confint.lm gets called on rlm objects. should use the default instead. |
| 48 |
#' @export |
| 49 |
confint.rlm <- confint.default |
| 50 |
|
| 51 |
#' @templateVar class rlm |
| 52 |
#' @template title_desc_tidy |
| 53 |
#' |
| 54 |
#' @param x An `rlm` object returned by [MASS::rlm()]. |
| 55 |
#' @template param_confint |
| 56 |
#' @template param_unused_dots |
| 57 |
#' |
| 58 |
#' @family rlm tidiers |
| 59 |
#' @seealso [MASS::rlm()] |
| 60 |
#' @export |
| 61 |
#' @include stats-lm.R |
| 62 |
tidy.rlm <- function(x, conf.int = FALSE, conf.level = .95, ...) { |
| 63 |
check_ellipses("exponentiate", "tidy", "rlm", ...) |
| 64 |
|
| 65 |
ret <- as_tibble(summary(x)$coefficients, rownames = "term") |
| 66 |
colnames(ret) <- c("term", "estimate", "std.error", "statistic") |
| 67 |
|
| 68 |
if (conf.int) { |
| 69 |
ci <- broom_confint_terms(x, level = conf.level) |
| 70 |
ret <- dplyr::left_join(ret, ci, by = "term") |
| 71 |
} |
| 72 |
|
| 73 |
ret |
| 74 |
} |
| 75 |
|
| 76 |
#' @templateVar class rlm |
| 77 |
#' @template title_desc_augment |
| 78 |
#' |
| 79 |
#' @param x An `rlm` object returned by [MASS::rlm()]. |
| 80 |
#' @template param_data |
| 81 |
#' @template param_newdata |
| 82 |
#' @template param_se_fit |
| 83 |
#' @template param_unused_dots |
| 84 |
#' |
| 85 |
#' @evalRd return_augment(".se.fit", ".hat", ".sigma") |
| 86 |
#' @inherit glance.rlm examples |
| 87 |
#' |
| 88 |
#' @family rlm tidiers |
| 89 |
#' @seealso [MASS::rlm()] |
| 90 |
#' @export |
| 91 |
augment.rlm <- function( |
| 92 |
x, |
| 93 |
data = model.frame(x), |
| 94 |
newdata = NULL, |
| 95 |
se_fit = FALSE, |
| 96 |
... |
| 97 |
) { |
| 98 |
df <- augment_newdata(x, data, newdata, se_fit) |
| 99 |
|
| 100 |
if (is.null(newdata)) { |
| 101 |
tryCatch( |
| 102 |
{ |
| 103 |
infl <- influence(x, do.coef = FALSE) |
| 104 |
df <- add_hat_sigma_cols(df, x, infl) |
| 105 |
}, |
| 106 |
error = data_error |
| 107 |
) |
| 108 |
} |
| 109 |
|
| 110 |
df |
| 111 |
} |