Skip to content

Commit

Permalink
Fix row name for the prevalence ratio in methods_epi2x2.R (#944)
Browse files Browse the repository at this point in the history
* Fix row name for the prevalence ratio in methods_epi2x2.R

insight::get_parameters() returns something named "RR" and not "PR".

* fix

* typo

* typo

* fixes

---------

Co-authored-by: Daniel <[email protected]>
  • Loading branch information
snhansen and strengejacke authored Feb 7, 2024
1 parent 1bd2884 commit 3649723
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
3 changes: 2 additions & 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
Version: 0.21.5.1
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -117,6 +117,7 @@ Suggests:
effectsize (>= 0.8.6),
EGAnet,
emmeans (>= 1.7.0),
epiR,
estimatr,
factoextra,
FactoMineR,
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions R/methods_epi2x2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 19 additions & 19 deletions tests/testthat/test-model_parameters.aov.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ 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)
})

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)
})


Expand All @@ -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)
})
17 changes: 17 additions & 0 deletions tests/testthat/test-model_parameters.epi2x2.R
Original file line number Diff line number Diff line change
@@ -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 (%)"
)
)
})

0 comments on commit 3649723

Please sign in to comment.