Skip to content

Commit db72de8

Browse files
committed
add tests
[skip]
1 parent bb29c5d commit db72de8

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Imports:
7575
insight (>= 1.3.0),
7676
parameters (>= 0.26.0),
7777
performance (>= 0.14.0),
78-
datawizard (>= 1.2.0),
78+
datawizard (>= 1.1.0),
7979
stats,
8080
utils
8181
Suggests:

tests/testthat/test-effectsize.R

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
# htest -------------------------------------------------------------------
3+
24
test_that("t-test", {
35
x <<- 1:10
46
y <<- c(1, 1:9)
@@ -319,6 +321,7 @@ test_that("htest | Get args from htest", {
319321

320322

321323
# aov ---------------------------------------------------------------------
324+
322325
test_that("aov", {
323326
data <- iris
324327
data$Cat1 <- rep(c("A", "B"), length.out = nrow(data))
@@ -329,6 +332,7 @@ test_that("aov", {
329332

330333

331334
# BayesFactor -------------------------------------------------------------
335+
332336
test_that("BayesFactor", {
333337
skip_if_not_installed("BayesFactor")
334338
skip_on_cran()
@@ -353,6 +357,77 @@ test_that("BayesFactor", {
353357
expect_equal(effectsize(bf4)[[1]], 0.3911, tolerance = 0.03)
354358
})
355359

360+
361+
# datawizard::data_tabulate() ---------------------------------------------
362+
363+
test_that("effectsize | datawizard crosstabs", {
364+
skip_if_not_installed("datawizard", minimum_version = "1.2.0")
365+
366+
data("mtcars")
367+
xtabs1 <- datawizard::data_tabulate(mtcars, select = "cyl", by = "am")
368+
xtab1 <- xtabs1[[1]]
369+
370+
expect_equal(
371+
effectsize(xtabs1),
372+
cramers_v(mtcars$cyl, mtcars$am)
373+
)
374+
expect_equal(
375+
effectsize(xtabs1),
376+
effectsize(xtab1)
377+
)
378+
expect_equal(
379+
effectsize(xtabs1, type = "c"),
380+
pearsons_c(mtcars$cyl, mtcars$am)
381+
)
382+
expect_equal(
383+
effectsize(xtab1, type = "c"),
384+
pearsons_c(mtcars$cyl, mtcars$am)
385+
)
386+
387+
388+
xtabs2 <- datawizard::data_tabulate(mtcars, select = c("cyl", "gear"), by = "am")
389+
xtabs3 <- datawizard::data_tabulate(datawizard::data_group(mtcars, select = c("carb")),
390+
select = c("cyl", "gear"), by = "am"
391+
)
392+
expect_error(effectsize(xtabs2), regexp = "Multilpe tables")
393+
expect_error(effectsize(xtabs3), regexp = "Multilpe tables")
394+
})
395+
396+
test_that("effectsize | datawizard tables", {
397+
skip_if_not_installed("datawizard", minimum_version = "1.2.0")
398+
399+
data("mtcars")
400+
tabs1 <- datawizard::data_tabulate(mtcars, select = "cyl")
401+
tab1 <- tabs1[[1]]
402+
403+
expect_equal(
404+
effectsize(tabs1),
405+
fei(table(mtcars$cyl))
406+
)
407+
expect_equal(
408+
effectsize(tabs1),
409+
effectsize(tab1)
410+
)
411+
expect_equal(
412+
effectsize(tabs1, type = "c"),
413+
pearsons_c(table(mtcars$cyl))
414+
)
415+
expect_equal(
416+
effectsize(tab1, type = "c"),
417+
pearsons_c(table(mtcars$cyl))
418+
)
419+
420+
421+
xtabs2 <- datawizard::data_tabulate(mtcars, select = c("cyl", "gear"))
422+
xtabs3 <- datawizard::data_tabulate(datawizard::data_group(mtcars, select = c("carb")),
423+
select = c("cyl", "gear"))
424+
expect_error(effectsize(xtabs2), regexp = "Multilpe tables")
425+
expect_error(effectsize(xtabs3), regexp = "Multilpe tables")
426+
})
427+
428+
429+
# Other ----------------------------------------
430+
356431
test_that("effectsize | easycorrelation", {
357432
skip_if_not_installed("correlation")
358433
r <- correlation::correlation(mtcars)

0 commit comments

Comments
 (0)