| 1 |
#' @templateVar class lmrob |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A `lmrob` object returned from [robustbase::lmrob()]. |
| 5 |
#' @template param_confint |
| 6 |
#' @template param_unused_dots |
| 7 |
#' |
| 8 |
#' @details For tidiers for robust models from the \pkg{MASS} package see |
| 9 |
#' [tidy.rlm()]. |
| 10 |
#' |
| 11 |
#' @examples |
| 12 |
#' |
| 13 |
#' if (requireNamespace("robustbase", quietly = TRUE)) { |
| 14 |
#' # load libraries for models and data |
| 15 |
#' library(robustbase) |
| 16 |
#' |
| 17 |
#' data(coleman) |
| 18 |
#' set.seed(0) |
| 19 |
#' |
| 20 |
#' m <- lmrob(Y ~ ., data = coleman) |
| 21 |
#' tidy(m) |
| 22 |
#' augment(m) |
| 23 |
#' glance(m) |
| 24 |
#' |
| 25 |
#' data(carrots) |
| 26 |
#' |
| 27 |
#' Rfit <- glmrob(cbind(success, total - success) ~ logdose + block, |
| 28 |
#' family = binomial, data = carrots, method = "Mqle", |
| 29 |
#' control = glmrobMqle.control(tcc = 1.2) |
| 30 |
#' ) |
| 31 |
#' |
| 32 |
#' tidy(Rfit) |
| 33 |
#' augment(Rfit) |
| 34 |
#' } |
| 35 |
#' @aliases robustbase_tidiers |
| 36 |
#' @export |
| 37 |
#' @family robustbase tidiers |
| 38 |
#' @rdname tidy.robustbase.lmrob |
| 39 |
#' @seealso [robustbase::lmrob()] |
| 40 |
tidy.lmrob <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { |
| 41 |
check_ellipses("exponentiate", "tidy", "lmrob", ...) |
| 42 |
|
| 43 |
ret <- coef(summary(x)) |> |
| 44 |
as_tibble(rownames = "term") |
| 45 |
names(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") |
| 46 |
|
| 47 |
if (conf.int) { |
| 48 |
ci <- stats::confint.default(x, level = conf.level) |> |
| 49 |
as_tibble() |
| 50 |
|
| 51 |
names(ci) <- c("conf.low", "conf.high") |
| 52 |
|
| 53 |
ret <- ret |> |
| 54 |
cbind(ci) |
| 55 |
} |
| 56 |
|
| 57 |
ret |
| 58 |
} |
| 59 |
|
| 60 |
#' @templateVar class lmrob |
| 61 |
#' @template title_desc_augment |
| 62 |
#' |
| 63 |
#' @inherit tidy.lmrob params examples |
| 64 |
#' @template param_data |
| 65 |
#' @template param_newdata |
| 66 |
#' @template param_se_fit |
| 67 |
#' @template param_unused_dots |
| 68 |
#' |
| 69 |
#' @evalRd return_augment() |
| 70 |
#' @details For tidiers for robust models from the \pkg{MASS} package see |
| 71 |
#' [tidy.rlm()]. |
| 72 |
#' |
| 73 |
#' @export |
| 74 |
#' @rdname augment.robustbase.lmrob |
| 75 |
#' @family robustbase tidiers |
| 76 |
#' @seealso [robustbase::lmrob()] |
| 77 |
augment.lmrob <- function( |
| 78 |
x, |
| 79 |
data = model.frame(x), |
| 80 |
newdata = NULL, |
| 81 |
se_fit = FALSE, |
| 82 |
... |
| 83 |
) { |
| 84 |
augment_newdata( |
| 85 |
x, |
| 86 |
data, |
| 87 |
newdata, |
| 88 |
.se_fit = se_fit |
| 89 |
) |
| 90 |
} |
| 91 |
|
| 92 |
#' @templateVar class lmrob |
| 93 |
#' @template title_desc_glance |
| 94 |
#' |
| 95 |
#' @inherit tidy.lmrob params examples |
| 96 |
#' @template param_unused_dots |
| 97 |
#' |
| 98 |
#' @details For tidiers for robust models from the \pkg{MASS} package see |
| 99 |
#' [tidy.rlm()]. |
| 100 |
#' |
| 101 |
#' @evalRd return_glance( |
| 102 |
#' "r.squared", |
| 103 |
#' "sigma", |
| 104 |
#' "df.residual" |
| 105 |
#' ) |
| 106 |
#' |
| 107 |
#' @export |
| 108 |
#' @family robustbase tidiers |
| 109 |
#' @rdname glance.robustbase.lmrob |
| 110 |
#' @seealso [robustbase::lmrob()] |
| 111 |
glance.lmrob <- function(x, ...) { |
| 112 |
s <- summary(x) |
| 113 |
|
| 114 |
as_glance_tibble( |
| 115 |
r.squared = s$r.squared, |
| 116 |
sigma = s$sigma, |
| 117 |
df.residual = x$df.residual, |
| 118 |
na_types = "rri" |
| 119 |
) |
| 120 |
} |