diff --git a/DESCRIPTION b/DESCRIPTION index 127eb1b45..1cba3eef8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.21.5 +Version: 0.21.5.1 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -117,6 +117,7 @@ Suggests: effectsize (>= 0.8.6), EGAnet, emmeans (>= 1.7.0), + epiR, estimatr, factoextra, FactoMineR, diff --git a/NEWS.md b/NEWS.md index 596fc3013..5a095bb43 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# parameters 0.21.6 + +## Bug fixes + +* Fixed issue with parameter names for `model_parameters()` and objects from + package *epiR*. + # parameters 0.21.5 ## Bug fixes diff --git a/R/methods_epi2x2.R b/R/methods_epi2x2.R index c6e5bb02b..a203b9b2c 100644 --- a/R/methods_epi2x2.R +++ b/R/methods_epi2x2.R @@ -25,6 +25,7 @@ model_parameters.epi.2by2 <- function(model, verbose = TRUE, ...) { # pretty names pretty_names <- params$Parameter pretty_names[pretty_names == "PR"] <- "Prevalence Ratio" + pretty_names[pretty_names == "RR"] <- "Risk Ratio" pretty_names[pretty_names == "OR"] <- "Odds Ratio" pretty_names[pretty_names == "ARisk"] <- "Attributable Risk" pretty_names[pretty_names == "PARisk"] <- "Attributable Risk in Population" diff --git a/tests/testthat/test-model_parameters.aov.R b/tests/testthat/test-model_parameters.aov.R index 42e5d2b41..09e40803a 100644 --- a/tests/testthat/test-model_parameters.aov.R +++ b/tests/testthat/test-model_parameters.aov.R @@ -9,7 +9,7 @@ test_that("model_parameters.aov", { skip_if_not_installed("effectsize", minimum_version = "0.5.0") model <- aov(Sepal.Width ~ Species, data = iris) mp <- suppressMessages(model_parameters(model, effectsize_type = c("omega", "eta", "epsilon"))) - expect_equal(mp$Parameter, c("Species", "Residuals")) + expect_identical(mp$Parameter, c("Species", "Residuals")) expect_equal(mp$Sum_Squares, c(11.34493, 16.962), tolerance = 1e-3) }) @@ -17,41 +17,41 @@ test_that("model_parameters.aov", { skip_if_not_installed("effectsize", minimum_version = "0.5.0") model <- aov(Sepal.Width ~ Species, data = iris) mp <- suppressMessages(model_parameters(model, effectsize_type = c("omega", "eta", "epsilon"))) - expect_equal(sum(mp$df), 149) - expect_equal(colnames(mp), c( + expect_identical(sum(mp$df), 149) + expect_named(mp, c( "Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p", "Omega2", "Eta2", "Epsilon2" )) model <- aov(Sepal.Length ~ Species * Cat1 * Cat2, data = iris) - expect_equal(sum(model_parameters(model, effectsize_type = c("omega", "eta", "epsilon"), verbose = FALSE)$df), 149) + expect_identical(sum(model_parameters(model, effectsize_type = c("omega", "eta", "epsilon"), verbose = FALSE)$df), 149) model <- aov(Sepal.Length ~ Species / Cat1 * Cat2, data = iris) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 149) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149) }) test_that("model_parameters.anova", { skip_if_not_installed("lme4") model <- anova(lm(Sepal.Width ~ Species, data = iris)) - expect_equal(sum(model_parameters(model)$df), 149) + expect_identical(sum(model_parameters(model)$df), 149L) model <- anova(lm(Sepal.Length ~ Species * Cat1 * Cat2, data = iris)) - expect_equal(sum(model_parameters(model)$df), 149) + expect_identical(sum(model_parameters(model)$df), 149L) model <- anova(lme4::lmer(wt ~ 1 + (1 | gear), data = mtcars)) - expect_equal(nrow(model_parameters(model)), 0) + expect_identical(nrow(model_parameters(model)), 0L) model <- anova(lme4::lmer(wt ~ cyl + (1 | gear), data = mtcars)) - expect_equal(sum(model_parameters(model)$df), 1) + expect_identical(sum(model_parameters(model)$df), 1L) model <- anova(lme4::lmer(wt ~ drat + cyl + (1 | gear), data = mtcars)) - expect_equal(sum(model_parameters(model)$df), 2) + expect_identical(sum(model_parameters(model)$df), 2L) model <- anova(lme4::lmer(wt ~ drat * cyl + (1 | gear), data = mtcars)) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 3) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 3L) model <- anova(lme4::lmer(wt ~ drat / cyl + (1 | gear), data = mtcars)) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 2) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 2L) }) @@ -61,26 +61,26 @@ test_that("model_parameters.anova", { skip_if_not_installed("httr") model <- insight::download_model("anova_3") - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 149) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149L) model <- insight::download_model("anova_4") - expect_equal(sum(model_parameters(model, verbose = FALSE)$df, na.rm = TRUE), 2) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df, na.rm = TRUE), 2) model <- insight::download_model("anova_lmerMod_5") - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 1) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 1L) model <- insight::download_model("anova_lmerMod_6") - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 12) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 12) }) test_that("model_parameters.anova", { model <- aov(wt ~ cyl + Error(gear), data = mtcars) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 31) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 31) model <- aov(Sepal.Length ~ Species * Cat1 + Error(Cat2), data = iris) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 149) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149) model <- aov(Sepal.Length ~ Species / Cat1 + Error(Cat2), data = iris) - expect_equal(sum(model_parameters(model, verbose = FALSE)$df), 149) + expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149) }) diff --git a/tests/testthat/test-model_parameters.epi2x2.R b/tests/testthat/test-model_parameters.epi2x2.R new file mode 100644 index 000000000..fd82cc690 --- /dev/null +++ b/tests/testthat/test-model_parameters.epi2x2.R @@ -0,0 +1,17 @@ +skip_on_cran() +skip_if_not_installed("epiR") + +test_that("model_parameters.epi2x2", { + data(mtcars) + tab <- xtabs(~ am + vs, data = mtcars) + out <- model_parameters(epiR::epi.2by2(tab)) + expect_identical(out$Parameter, c("RR", "OR", "ARisk", "AFRisk", "PARisk", "PAFRisk")) + expect_identical( + attributes(out)$pretty_names, + c( + RR = "Risk Ratio", OR = "Odds Ratio", ARisk = "Attributable Risk", + AFRisk = "Attributable Fraction in Exposed (%)", PARisk = "Attributable Risk in Population", + PAFRisk = "Attributable Fraction in Population (%)" + ) + ) +})