From ac2eb02b396de746755ad172d975fcd3389ce876 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Dec 2024 18:57:17 +0100 Subject: [PATCH] Test on latest datawizard (#1050) * Prepare CRAN release (#1047) * Prepare CRAN release * update deps * Update DESCRIPTION * fix * submit * fix docs ref * trigger CI * use explicit arguments * fix * desc * fixes * fix --- DESCRIPTION | 5 +- R/dominance_analysis.R | 78 +++++++++++------------- R/extract_random_variances.R | 2 +- R/methods_glmmTMB.R | 2 +- R/methods_mice.R | 11 ++-- R/p_function.R | 2 +- tests/testthat/test-dominance_analysis.R | 1 + tests/testthat/test-pool_parameters.R | 4 +- 8 files changed, 51 insertions(+), 54 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f6a55d14d..5d6fff562 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.24.0 +Version: 0.24.0.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -167,7 +167,7 @@ Suggests: metafor, mfx, mgcv, - mice, + mice (>= 3.17.0), mmrm, multcomp, MuMIn, @@ -224,3 +224,4 @@ Config/testthat/edition: 3 Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true +Remotes: easystats/datawizard diff --git a/R/dominance_analysis.R b/R/dominance_analysis.R index efeb46e59..be6542a50 100644 --- a/R/dominance_analysis.R +++ b/R/dominance_analysis.R @@ -529,58 +529,54 @@ dominance_analysis <- function(model, sets = NULL, all = NULL, datawizard::data_relocate(da_df_res, "subset", after = "ranks") if (conditional) { - da_df_cdl <- - .data_frame(Subset = names(domir_res$General_Dominance)) - - da_df_cdl <- - datawizard::data_merge( - da_df_cdl, - .data_frame( - Subset = names(domir_res$General_Dominance), - domir_res$Conditional_Dominance - ) - ) + da_df_cdl <- .data_frame(Subset = names(domir_res$General_Dominance)) - da_df_cdl <- - datawizard::data_rename( - da_df_cdl, - names(da_df_cdl)[2:length(da_df_cdl)], - colnames(domir_res$Conditional_Dominance) + da_df_cdl <- datawizard::data_merge( + da_df_cdl, + .data_frame( + Subset = names(domir_res$General_Dominance), + domir_res$Conditional_Dominance ) + ) + + cols_to_select <- colnames(da_df_cdl)[2:length(da_df_cdl)] + da_df_cdl <- datawizard::data_rename( + da_df_cdl, + select = cols_to_select, + replacement = colnames(domir_res$Conditional_Dominance) + ) } else { da_df_cdl <- NULL } if (complete) { - da_df_cpt <- - .data_frame(Subset = names(domir_res$General_Dominance)) - - da_df_cpt <- - datawizard::data_merge( - da_df_cpt, - .data_frame( - Subset = names(domir_res$General_Dominance), - domir_res$Complete_Dominance - ) - ) + da_df_cpt <- .data_frame(Subset = names(domir_res$General_Dominance)) - da_df_cpt <- - datawizard::data_rename( - da_df_cpt, - names(da_df_cpt)[2:length(da_df_cpt)], - colnames(domir_res$Complete_Dominance) + da_df_cpt <- datawizard::data_merge( + da_df_cpt, + .data_frame( + Subset = names(domir_res$General_Dominance), + domir_res$Complete_Dominance ) + ) + + cols_to_select <- colnames(da_df_cpt)[2:length(da_df_cpt)] + da_df_cpt <- datawizard::data_rename( + da_df_cpt, + select = cols_to_select, + replacement = colnames(domir_res$Complete_Dominance) + ) } else { da_df_cpt <- NULL } - da_df_res <- - datawizard::data_rename(da_df_res, - replacement = c( - "Parameter", "General_Dominance", - "Percent", "Ranks", "Subset" - ) + da_df_res <- datawizard::data_rename( + da_df_res, + replacement = c( + "Parameter", "General_Dominance", + "Percent", "Ranks", "Subset" ) + ) da_list <- list( General = da_df_res, @@ -615,7 +611,7 @@ print.parameters_da <- function(x, digits = 3, ...) { printed_x <- x printed_x$General <- datawizard::data_rename(x$General, - pattern = "General_Dominance", + select = "General_Dominance", replacement = "General Dominance" ) @@ -628,7 +624,7 @@ print.parameters_da <- function(x, digits = 3, ...) { printed_x$Conditional <- datawizard::data_rename(x$Conditional, - pattern = cdl_names, + select = cdl_names, replacement = cdl_names_rep ) } @@ -644,7 +640,7 @@ print.parameters_da <- function(x, digits = 3, ...) { printed_x$Complete <- datawizard::data_rename(x$Complete, - pattern = cpt_names, + select = cpt_names, replacement = cpt_names_rep ) } diff --git a/R/extract_random_variances.R b/R/extract_random_variances.R index ddc159155..c54f76ce1 100644 --- a/R/extract_random_variances.R +++ b/R/extract_random_variances.R @@ -206,7 +206,7 @@ # rename columns out <- datawizard::data_rename( out, - pattern = c("grp", "sdcor"), + select = c("grp", "sdcor"), replacement = c("Group", "Coefficient") ) diff --git a/R/methods_glmmTMB.R b/R/methods_glmmTMB.R index 694e2740e..d948310ac 100644 --- a/R/methods_glmmTMB.R +++ b/R/methods_glmmTMB.R @@ -426,7 +426,7 @@ ci.glmmTMB <- function(x, method <- tolower(method) method <- insight::validate_argument( method, - c("wald", "normal", "ml1", "betwithin", "profile", "uniroot", "robust") + c("wald", "normal", "ml1", "betwithin", "profile", "uniroot", "robust", "residual") ) component <- insight::validate_argument( component, diff --git a/R/methods_mice.R b/R/methods_mice.R index c9e67b741..f0078b08f 100644 --- a/R/methods_mice.R +++ b/R/methods_mice.R @@ -21,8 +21,8 @@ p_value.mipo <- function(model, ...) { p = as.vector(s$p.value) ) # check for ordinal-alike models - if ("y.level" %in% colnames(s)) { - out$Response <- as.vector(s$y.level) + if (!is.null(model$pooled) && "y.level" %in% colnames(model$pooled)) { + out$Response <- as.vector(model$pooled$y.level) } out } @@ -45,8 +45,8 @@ standard_error.mipo <- function(model, ...) { SE = as.vector(s$std.error) ) # check for ordinal-alike models - if ("y.level" %in% colnames(s)) { - out$Response <- as.vector(s$y.level) + if (!is.null(model$pooled) && "y.level" %in% colnames(model$pooled)) { + out$Response <- as.vector(model$pooled$y.level) } out } @@ -85,8 +85,7 @@ model_parameters.mipo <- function(model, ) # check if we have ordinal/categorical response - s <- summary(model) - if ("y.level" %in% colnames(s)) { + if (!is.null(model$pooled) && "y.level" %in% colnames(model$pooled)) { merge_by <- c("Parameter", "Response") } else { merge_by <- "Parameter" diff --git a/R/p_function.R b/R/p_function.R index c704fe39f..2d004c8cb 100644 --- a/R/p_function.R +++ b/R/p_function.R @@ -379,7 +379,7 @@ format.parameters_p_function <- function(x, ci <- as.character(i$CI)[1] out <- datawizard::data_rename( i, - pattern = c("CI_low", "CI_high"), + select = c("CI_low", "CI_high"), replacement = c(sprintf("CI_low_%s", ci), sprintf("CI_high_%s", ci)) ) out$CI <- NULL diff --git a/tests/testthat/test-dominance_analysis.R b/tests/testthat/test-dominance_analysis.R index 542b6df4d..cdfd6edb2 100644 --- a/tests/testthat/test-dominance_analysis.R +++ b/tests/testthat/test-dominance_analysis.R @@ -1,5 +1,6 @@ skip_if_not_installed("performance") skip_if_not_installed("domir") +skip_if_not_installed("datawizard") DA_test_model <- lm(mpg ~ vs + cyl + carb, data = mtcars) diff --git a/tests/testthat/test-pool_parameters.R b/tests/testthat/test-pool_parameters.R index b4f2dcd45..1818c588e 100644 --- a/tests/testthat/test-pool_parameters.R +++ b/tests/testthat/test-pool_parameters.R @@ -74,7 +74,7 @@ test_that("pooled parameters, glmmTMB, components", { ) expect_equal(out$Coefficient, c(187.280225, -87.838969), tolerance = 1e-3) - out <- pool_parameters(models, component = "all", effects = "all") + out <- suppressMessages(pool_parameters(models, component = "all", effects = "all")) expect_named( out, c( @@ -123,7 +123,7 @@ test_that("pooled parameters, glmmTMB, zero-inflated", { ) }) - out <- pool_parameters(models) + out <- pool_parameters(models, ci_method = "residual") expect_named( out, c(