Debian Codegraph @

R/robust-glmrob.R

raw
1 #' @templateVar class glmRob
2 #' @template title_desc_tidy
3 #'
4 #' @param x A `glmRob` object returned from [robust::glmRob()].
5 #' @template param_unused_dots
6 #'
7 #' @details For tidiers for robust models from the \pkg{MASS} package see
8 #' [tidy.rlm()].
9 #'
10 #' @examplesIf rlang::is_installed("robust")
11 #'
12 #' # load libraries for models and data
13 #' library(robust)
14 #'
15 #' # fit model
16 #' gm <- glmRob(am ~ wt, data = mtcars, family = "binomial")
17 #'
18 #' # summarize model fit with tidiers
19 #' tidy(gm)
20 #' glance(gm)
21 #'
22 #' @export
23 #' @family robust tidiers
24 #' @seealso [robust::glmRob()]
25 tidy.glmRob <- function(x, ...) {
26 co <- stats::coef(summary(x))
27 ret <- as_tibble(co, rownames = "term")
28 names(ret) <- c("term", "estimate", "std.error", "statistic", "p.value")
29 ret
30 }
31
32 #' @templateVar class glmRob
33 #' @template title_desc_augment
34 #'
35 #' @param x Unused.
36 #' @param ... Unused.
37 #'
38 #' @export
39 augment.glmRob <- function(x, ...) {
40 cli::cli_abort(c(
41 "{.fn augment.glmRob} has been deprecated as the {.pkg robust} package
42 doesn't provide the functionality necessary to implement
43 an augment method.",
44 "i" = "Please see the augment method for {.cls glmrob} objects from
45 {.pkg robustbase}."
46 ))
47 invisible(TRUE)
48 }
49
50 #' @templateVar class glmRob
51 #' @template title_desc_glance
52 #'
53 #' @inherit tidy.glmRob params examples
54 #' @template param_unused_dots
55 #'
56 #' @evalRd return_glance(
57 #' "deviance",
58 #' "sigma",
59 #' "null.deviance",
60 #' "df.residual",
61 #' "nobs"
62 #' )
63 #'
64 #' @export
65 #' @family robust tidiers
66 #' @seealso [robust::glmRob()]
67 #'
68 glance.glmRob <- function(x, ...) {
69 as_glance_tibble(
70 deviance = x$deviance,
71 sigma = stats::sigma(x),
72 null.deviance = x$null.deviance,
73 df.residual = stats::df.residual(x),
74 nobs = stats::nobs(x),
75 na_types = "rrrii"
76 )
77 }