Skip to content

Commit

Permalink
Exponentiation of clmm coefficients in the ordinal package
Browse files Browse the repository at this point in the history
Fixes #949
  • Loading branch information
strengejacke committed Mar 11, 2024
1 parent d0b74ee commit d2e14d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.5.5
Version: 0.21.5.6
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* Fixed issue with parameter names for `model_parameters()` and objects from
package *epiR*.

* Fixed issue with `exponentiate = TRUE` for `model_parameters()` with models
of class `clmm` (package *ordinal*), when model had no `component` column
(e.g., no scale or location parameters were returned).

# parameters 0.21.5

## Bug fixes
Expand Down
6 changes: 3 additions & 3 deletions R/utils_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@
if (any(columns)) {
if (inherits(model, "mvord")) {
rows <- params$Component != "correlation"
} else if (inherits(model, c("clm", "clm2", "clmm"))) {
## TODO: make sure we catch all ordinal models properly here
rows <- !tolower(params$Component) %in% c("location", "scale")
} else if (is.null(params$Component)) {
# don't exponentiate dispersion
rows <- seq_len(nrow(params))
} else if (inherits(model, c("clm", "clm2", "clmm"))) {
## TODO: make sure we catch all ordinal models properly here
rows <- !tolower(params$Component) %in% c("location", "scale")
} else {
rows <- !tolower(params$Component) %in% c("dispersion", "residual")
}
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-model_parameters_ordinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ test_that("model_parameters.clm2", {

expect_snapshot(print(mp))
})

test_that("model_parameters.clmm, exponentiate works w/o component column", {
datas(wine, package = "ordinal")
mox <- ordinal::clmm(rating ~ temp + contact + (1 | judge), data = wine)
out1 <- model_parameters(mox, exponentiate = FALSE)
out2 <- model_parameters(mox, exponentiate = TRUE)
expect_equal(out1$Coefficient, c(-1.62367, 1.51337, 4.22853, 6.08877, 3.063, 1.83488, 1.13113), tolerance = 1e-4)
expect_equal(out2$Coefficient, c(0.19717, 4.54199, 68.61606, 440.87991, 21.39156, 6.26441, 1.13113), tolerance = 1e-4)
expect_identical(attributes(out1)$coefficient_name, "Log-Odds")
expect_identical(attributes(out2)$coefficient_name, "Odds Ratio")
})

0 comments on commit d2e14d2

Please sign in to comment.