| 1 |
#' @templateVar class clmm |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A `clmm` object returned from [ordinal::clmm()]. |
| 5 |
#' @template param_confint |
| 6 |
#' @template param_exponentiate |
| 7 |
#' @template param_unused_dots |
| 8 |
#' |
| 9 |
#' @examplesIf rlang::is_installed("ordinal") |
| 10 |
#' |
| 11 |
#' # load libraries for models and data |
| 12 |
#' library(ordinal) |
| 13 |
#' |
| 14 |
#' # fit model |
| 15 |
#' fit <- clmm(rating ~ temp + contact + (1 | judge), data = wine) |
| 16 |
#' |
| 17 |
#' # summarize model fit with tidiers |
| 18 |
#' tidy(fit) |
| 19 |
#' tidy(fit, conf.int = TRUE, conf.level = 0.9) |
| 20 |
#' tidy(fit, conf.int = TRUE, exponentiate = TRUE) |
| 21 |
#' |
| 22 |
#' glance(fit) |
| 23 |
#' |
| 24 |
#' # ...and again with another model specification |
| 25 |
#' fit2 <- clmm(rating ~ temp + (1 | judge), nominal = ~contact, data = wine) |
| 26 |
#' |
| 27 |
#' tidy(fit2) |
| 28 |
#' glance(fit2) |
| 29 |
#' |
| 30 |
#' @evalRd return_tidy(regression = TRUE) |
| 31 |
#' |
| 32 |
#' @note In `broom 0.7.0` the `coefficient_type` column was renamed to |
| 33 |
#' `coef.type`, and the contents were changed as well. |
| 34 |
#' |
| 35 |
#' Note that `intercept` type coefficients correspond to `alpha` |
| 36 |
#' parameters, `location` type coefficients correspond to `beta` |
| 37 |
#' parameters, and `scale` type coefficients correspond to `zeta` |
| 38 |
#' parameters. |
| 39 |
#' |
| 40 |
#' @export |
| 41 |
#' @seealso [tidy], [ordinal::clmm()], [ordinal::confint.clm()] |
| 42 |
#' @family ordinal tidiers |
| 43 |
tidy.clmm <- function( |
| 44 |
x, |
| 45 |
conf.int = FALSE, |
| 46 |
conf.level = 0.95, |
| 47 |
exponentiate = FALSE, |
| 48 |
... |
| 49 |
) { |
| 50 |
# NOTE: pretty much the same as tidy.clm() except there is no |
| 51 |
# `type` argument to confint.clmm() |
| 52 |
|
| 53 |
ret <- as_tibble(coef(summary(x)), rownames = "term") |
| 54 |
colnames(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") |
| 55 |
|
| 56 |
if (conf.int) { |
| 57 |
ci <- broom_confint_terms(x, level = conf.level) |
| 58 |
ret <- dplyr::left_join(ret, ci, by = "term") |
| 59 |
} |
| 60 |
|
| 61 |
if (exponentiate) { |
| 62 |
ret <- exponentiate(ret) |
| 63 |
} |
| 64 |
|
| 65 |
types <- c("alpha", "beta", "zeta") |
| 66 |
new_types <- c("intercept", "location", "scale") |
| 67 |
ret$coef.type <- rep(new_types, vapply(x[types], length, numeric(1))) |
| 68 |
as_tibble(ret) |
| 69 |
} |
| 70 |
|
| 71 |
#' @templateVar class clmm |
| 72 |
#' @template title_desc_glance |
| 73 |
#' |
| 74 |
#' @inherit tidy.clmm params examples |
| 75 |
#' |
| 76 |
#' @evalRd return_glance( |
| 77 |
#' "edf", |
| 78 |
#' "AIC", |
| 79 |
#' "BIC", |
| 80 |
#' "logLik", |
| 81 |
#' "nobs" |
| 82 |
#' ) |
| 83 |
#' |
| 84 |
#' @export |
| 85 |
#' @seealso [tidy], [ordinal::clmm()] |
| 86 |
#' @family ordinal tidiers |
| 87 |
glance.clmm <- function(x, ...) { |
| 88 |
as_glance_tibble( |
| 89 |
edf = x$edf, |
| 90 |
AIC = stats::AIC(x), |
| 91 |
BIC = stats::BIC(x), |
| 92 |
logLik = stats::logLik(x), |
| 93 |
nobs = stats::nobs(x), |
| 94 |
na_types = "irrri" |
| 95 |
) |
| 96 |
} |