From 8fdbfad67a82be3de5e39498032cf8ce50aea210 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Wed, 8 Nov 2023 20:36:57 +0200 Subject: [PATCH] fix nnt bug --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/xtab_diff.R | 2 +- tests/testthat/test-xtab.R | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5c10ce47..904a59c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: effectsize Title: Indices of Effect Size -Version: 0.8.6.2 +Version: 0.8.6.3 Authors@R: c(person(given = "Mattan S.", family = "Ben-Shachar", diff --git a/NEWS.md b/NEWS.md index 05d6febf..bfd8f3f0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,10 @@ - `repeated_measures_d()` to compute standardized mean differences (SMD) for repeated measures data. - Also supported in `effectsize()` + +## Bug fixes + +- `nnt()` now properly accepts the `y` argument. # effectsize 0.8.7 diff --git a/R/xtab_diff.R b/R/xtab_diff.R index a80f6455..2346f85d 100644 --- a/R/xtab_diff.R +++ b/R/xtab_diff.R @@ -304,7 +304,7 @@ nnt <- function(x, y = NULL, ci = 0.95, alternative = "two.sided", ...) { return(effectsize(x, type = "nnt", ci = ci, ...)) } - out <- arr(x, y = t, ci = ci, alternative = alternative2, ...) + out <- arr(x, y = y, ci = ci, alternative = alternative2, ...) out[[1]] <- 1 / out[[1]] colnames(out)[1] <- "NNT" diff --git a/tests/testthat/test-xtab.R b/tests/testthat/test-xtab.R index aaa9bbb6..667127cb 100644 --- a/tests/testthat/test-xtab.R +++ b/tests/testthat/test-xtab.R @@ -200,6 +200,14 @@ test_that("oddsratio & riskratio", { expect_equal(ARR[[1]], -0.4891775, tolerance = 0.001) expect_equal(ARR$CI_low, -0.8092576, tolerance = 0.001) expect_equal(ARR$CI_high, -0.1690974, tolerance = 0.001) + + # fix + set.seed(111) + x <- rbinom(10, 1, 0.5) + y <- rbinom(10, 1, 0.5) + + expect_no_error(NNT <- nnt(x, y)) + expect_equal(NNT[[1]], arr_to_nnt(arr(x, y)[[1]])) })