From d2e14d2eff4948e64d406467e607f64811d5f08d Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Mar 2024 09:15:28 +0100 Subject: [PATCH 1/5] Exponentiation of clmm coefficients in the ordinal package Fixes #949 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/utils_model_parameters.R | 6 +++--- tests/testthat/test-model_parameters_ordinal.R | 11 +++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e69fc44e8..f34136fd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index 72ec96a38..970877c72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/utils_model_parameters.R b/R/utils_model_parameters.R index 9022dcd9d..6301f3e66 100644 --- a/R/utils_model_parameters.R +++ b/R/utils_model_parameters.R @@ -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") } diff --git a/tests/testthat/test-model_parameters_ordinal.R b/tests/testthat/test-model_parameters_ordinal.R index 39d03eca7..c27a92b0e 100644 --- a/tests/testthat/test-model_parameters_ordinal.R +++ b/tests/testthat/test-model_parameters_ordinal.R @@ -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") +}) From 456569a255f4ed4f0e1def2fc538a00c948ad2a9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Mar 2024 09:41:33 +0100 Subject: [PATCH 2/5] typo --- tests/testthat/test-model_parameters_ordinal.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-model_parameters_ordinal.R b/tests/testthat/test-model_parameters_ordinal.R index c27a92b0e..834fe6e22 100644 --- a/tests/testthat/test-model_parameters_ordinal.R +++ b/tests/testthat/test-model_parameters_ordinal.R @@ -93,7 +93,7 @@ test_that("model_parameters.clm2", { }) test_that("model_parameters.clmm, exponentiate works w/o component column", { - datas(wine, package = "ordinal") + data(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) From fc85f4b76b957d6125e7d48f4feef4b1991c056d Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Mar 2024 10:17:54 +0100 Subject: [PATCH 3/5] tests work on new insight --- tests/testthat/test-marginaleffects.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-marginaleffects.R b/tests/testthat/test-marginaleffects.R index a3de7ba47..87b9cf69a 100644 --- a/tests/testthat/test-marginaleffects.R +++ b/tests/testthat/test-marginaleffects.R @@ -1,4 +1,5 @@ skip_if_not_installed("marginaleffects", minimum_version = "0.18.0") +skip_if_not_installed("insight", minimum_version = "0.19.8.8") skip_if_not_installed("rstanarm") test_that("marginaleffects()", { @@ -9,7 +10,7 @@ test_that("marginaleffects()", { expect_identical(nrow(out), 1L) expect_named(out, c( "Parameter", "Coefficient", "SE", "Statistic", - "p", "s.value", "CI", "CI_low", "CI_high" + "p", "S", "CI", "CI_low", "CI_high" )) out <- model_parameters(model, exponentiate = TRUE) expect_equal(out$Coefficient, 1.394, tolerance = 1e-3) @@ -36,7 +37,7 @@ test_that("predictions()", { expect_identical(nrow(out), 3L) expect_named(out, c( "Predicted", "SE", "CI", "CI_low", "CI_high", "Statistic", - "p", "Species", "s.value" + "p", "Species", "S" )) out <- parameters(p, exponentiate = TRUE) expect_equal(out$Predicted, c(30.81495, 15.95863, 19.57004), tolerance = 1e-4) From 1b6cf3aaf120fb3eaadb843c755bc131c1cc5fa3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Mar 2024 10:42:20 +0100 Subject: [PATCH 4/5] update test --- tests/testthat/test-marginaleffects.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-marginaleffects.R b/tests/testthat/test-marginaleffects.R index 87b9cf69a..e52db9613 100644 --- a/tests/testthat/test-marginaleffects.R +++ b/tests/testthat/test-marginaleffects.R @@ -36,8 +36,8 @@ test_that("predictions()", { out <- parameters(p) expect_identical(nrow(out), 3L) expect_named(out, c( - "Predicted", "SE", "CI", "CI_low", "CI_high", "Statistic", - "p", "Species", "S" + "Predicted", "SE", "CI", "CI_low", "CI_high", "S", "Statistic", + "p", "Species" )) out <- parameters(p, exponentiate = TRUE) expect_equal(out$Predicted, c(30.81495, 15.95863, 19.57004), tolerance = 1e-4) @@ -72,7 +72,6 @@ test_that("comparisons()", { }) - test_that("hypotheses()", { data(mtcars) x <- lm(mpg ~ hp + wt, data = mtcars) From e4738176ec8120c8f1d4c2ab221dbaad2ac55485 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Mar 2024 11:07:13 +0100 Subject: [PATCH 5/5] docs --- R/p_function.R | 30 +++++++++++++++++++++--------- man/p_function.Rd | 29 +++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/R/p_function.R b/R/p_function.R index 440378f83..d60afed34 100644 --- a/R/p_function.R +++ b/R/p_function.R @@ -92,6 +92,17 @@ #' (which is in line with the "unconditional" interpretation in the sense of #' Rafi and Greenland). #' +#' Ascribing a probabilistic interpretation to one realized confidence interval +#' is possible without repeated sampling of the specific experiment. Important +#' is the assumption that a _sampling distribution_ is a good description of the +#' variability of the parameter (_Vos and Holbert 2022_). At the core, the +#' interpretation of a confidence interval is "I assume that this sampling +#' distribution is a good description of the uncertainty of the parameter. If +#' that's a good assumption, then the values in this interval are the most +#' plausible or compatible with the data". The source of confidence in +#' probability statements is the assumption that the selected sampling +#' distribution is appropriate. +#' #' "The realized confidence distribution is clearly an epistemic probability #' distribution" (_Schweder 2018_). In Bayesian words, compatibility intervals #' (or confidence distributons, or consonance curves) are "posteriors without @@ -156,20 +167,21 @@ #' - Schweder T, Hjort NL. Confidence, Likelihood, Probability: Statistical #' inference with confidence distributions. Cambridge University Press, 2016. #' -#' @examples +#' - Vos P, Holbert D. Frequentist statistical inference without repeated sampling. +#' Synthese 200, 89 (2022). \doi{10.1007/s11229-022-03560-x} +#' +#' @examplesIf requireNamespace("see") #' model <- lm(Sepal.Length ~ Species, data = iris) #' p_function(model) #' -#' if (requireNamespace("see") && packageVersion("see") > "0.7.3") { -#' model <- lm(mpg ~ wt + as.factor(gear) + am, data = mtcars) -#' result <- p_function(model) +#' model <- lm(mpg ~ wt + as.factor(gear) + am, data = mtcars) +#' result <- p_function(model) #' -#' # single panels -#' plot(result, n_columns = 2) +#' # single panels +#' plot(result, n_columns = 2) #' -#' # integrated plot, the default -#' plot(result) -#' } +#' # integrated plot, the default +#' plot(result) #' @export p_function <- function(model, ci_levels = c(0.25, 0.5, 0.75, emph = 0.95), diff --git a/man/p_function.Rd b/man/p_function.Rd index c84e61246..0adbccc17 100644 --- a/man/p_function.Rd +++ b/man/p_function.Rd @@ -194,6 +194,17 @@ compatibility intervals is "conditional" - on the data \emph{and} model assumpti (which is in line with the "unconditional" interpretation in the sense of Rafi and Greenland). +Ascribing a probabilistic interpretation to one realized confidence interval +is possible without repeated sampling of the specific experiment. Important +is the assumption that a \emph{sampling distribution} is a good description of the +variability of the parameter (\emph{Vos and Holbert 2022}). At the core, the +interpretation of a confidence interval is "I assume that this sampling +distribution is a good description of the uncertainty of the parameter. If +that's a good assumption, then the values in this interval are the most +plausible or compatible with the data". The source of confidence in +probability statements is the assumption that the selected sampling +distribution is appropriate. + "The realized confidence distribution is clearly an epistemic probability distribution" (\emph{Schweder 2018}). In Bayesian words, compatibility intervals (or confidence distributons, or consonance curves) are "posteriors without @@ -229,19 +240,19 @@ For certain models (like mixed models), profiled intervals may be more accurate, however, this is currently not supported. } \examples{ +\dontshow{if (requireNamespace("see")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} model <- lm(Sepal.Length ~ Species, data = iris) p_function(model) -if (requireNamespace("see") && packageVersion("see") > "0.7.3") { - model <- lm(mpg ~ wt + as.factor(gear) + am, data = mtcars) - result <- p_function(model) +model <- lm(mpg ~ wt + as.factor(gear) + am, data = mtcars) +result <- p_function(model) - # single panels - plot(result, n_columns = 2) +# single panels +plot(result, n_columns = 2) - # integrated plot, the default - plot(result) -} +# integrated plot, the default +plot(result) +\dontshow{\}) # examplesIf} } \references{ \itemize{ @@ -270,5 +281,7 @@ Data Confrontation in Economics, pp. 285-217. Princeton University Press, Princeton, NJ, 2003 \item Schweder T, Hjort NL. Confidence, Likelihood, Probability: Statistical inference with confidence distributions. Cambridge University Press, 2016. +\item Vos P, Holbert D. Frequentist statistical inference without repeated sampling. +Synthese 200, 89 (2022). \doi{10.1007/s11229-022-03560-x} } }