diff --git a/DESCRIPTION b/DESCRIPTION index a2bf90f45..f32873fbb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.22.2.9 +Version: 0.22.2.10 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NAMESPACE b/NAMESPACE index f7bbef008..ae1aca375 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -378,6 +378,7 @@ S3method(p_significance,lm) S3method(p_significance,lme) S3method(p_significance,merMod) S3method(p_significance,mixed) +S3method(p_significance,parameters_model) S3method(p_significance,rma) S3method(p_significance,svyglm) S3method(p_significance,wbm) diff --git a/R/p_significance.R b/R/p_significance.R index d22e06e7d..603e7ed5a 100644 --- a/R/p_significance.R +++ b/R/p_significance.R @@ -182,8 +182,27 @@ p_significance.lm <- function(x, threshold = "default", ci = 0.95, verbose = TRU .posterior_ci <- function(x, ci, ...) { # first, we need CIs - out <- ci(x, ci = ci, ...) - dof <- .safe(insight::get_df(x, type = "wald"), Inf) + if (inherits(x, "parameters_model")) { + # for model_parameters objects, directly extract CIs + out <- as.data.frame(x)[intersect( + c("Parameter", "CI_low", "CI_high", "Component", "Effects"), + colnames(x) + )] + ci <- attributes(x)$ci + # and extract degrees of freedom + df_column <- grep("(df|df_error)", colnames(x)) + if (length(df_column) > 0) { + dof <- unique(x[[df_column]]) + if (length(dof) > 1) { + dof <- Inf + } + } else { + dof <- Inf + } + } else { + out <- ci(x, ci = ci, ...) + dof <- .safe(insight::get_df(x, type = "wald"), Inf) + } # we now iterate all confidence intervals and create an approximate normal # distribution that covers the CI-range. posterior <- as.data.frame(lapply(seq_len(nrow(out)), function(i) { @@ -281,3 +300,6 @@ p_significance.zeroinfl <- p_significance.lm #' @export p_significance.rma <- p_significance.lm + +#' @export +p_significance.parameters_model <- p_significance.lm diff --git a/tests/testthat/test-p_significance.R b/tests/testthat/test-p_significance.R index 092abf8bf..9de21d3cc 100644 --- a/tests/testthat/test-p_significance.R +++ b/tests/testthat/test-p_significance.R @@ -10,6 +10,11 @@ test_that("p_significance", { expect_named(x, c("Parameter", "CI", "CI_low", "CI_high", "ps")) expect_snapshot(print(x)) + mp <- model_parameters(m) + set.seed(123) + x2 <- p_significance(mp) + expect_equal(x$ps, x2$ps, tolerance = 1e-4) + set.seed(123) x <- p_significance(m, ci = 0.8) expect_equal(x$ps, c(1, 0.3983, 0.9959, 0.6188, 0), tolerance = 1e-3)