diff --git a/tests/testthat/_snaps/bland-altman.md b/tests/testthat/_snaps/bland-altman.md new file mode 100644 index 0000000000..c964320b7c --- /dev/null +++ b/tests/testthat/_snaps/bland-altman.md @@ -0,0 +1,62 @@ +# s_bland_altman works with default settings + + Code + res + Output + $df + average difference + 1 0.14626178 -1.5454312 + 2 0.48288981 -0.5984930 + 3 -0.38053181 -0.9101936 + 4 -0.19703545 3.5846325 + 5 0.47466676 -0.2903180 + 6 -0.43829856 -0.7643396 + 7 0.16581677 0.6432246 + 8 -0.36621383 2.2090771 + 9 0.04881564 1.0539314 + 10 0.05627658 -0.7233299 + 11 1.43523036 0.1531016 + 12 0.14352775 0.4926310 + 13 -0.11678449 -1.0089122 + 14 -1.13425246 -2.1608949 + 15 -0.12606432 2.5019905 + 16 -0.22996409 0.3700609 + 17 -0.20524011 0.3780997 + 18 0.44226140 1.0031496 + 19 0.96062329 -0.2788042 + 20 0.67853853 -0.1692744 + + $difference_mean + [1] 0.1969954 + + $ci_mean + [1] -0.3414723 0.7354631 + + $difference_sd + [1] 1.392664 + + $difference_se + [1] 0.3114091 + + $upper_agreement_limit + [1] 2.487724 + + $lower_agreement_limit + [1] -2.093733 + + $agreement_limit_se + [1] 0.5393764 + + $upper_agreement_limit_ci + [1] 1.555070 3.420377 + + $lower_agreement_limit_ci + [1] -3.026386 -1.161079 + + $t_value + [1] 1.729133 + + $n + [1] 20 + + diff --git a/tests/testthat/_snaps/bland-altman/g_bland_altman.svg b/tests/testthat/_snaps/bland-altman/g_bland_altman.svg new file mode 100644 index 0000000000..3daf0fe688 --- /dev/null +++ b/tests/testthat/_snaps/bland-altman/g_bland_altman.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +lower limits of agreement +upper limits of agreement +mean of difference between two measures +-2.09 +2.49 + + +-2 +0 +2 + + + + + + + + + +-1.0 +-0.5 +0.0 +0.5 +1.0 +1.5 +Average of two measures +Difference between two measures + + diff --git a/tests/testthat/test-bland-altman.R b/tests/testthat/test-bland-altman.R index 18cdb856bf..7bd15e0fcd 100644 --- a/tests/testthat/test-bland-altman.R +++ b/tests/testthat/test-bland-altman.R @@ -59,3 +59,47 @@ testthat::test_that("s_bland_altman works with two vectors with NA element in ei ) expect_identical(res, expect, tolerance = 1e-5) }) + + +testthat::test_that("s_bland_altman works with default settings", { + x <- c( + -0.62645381, 0.18364332, -0.83562861, 1.59528080, 0.32950777, -0.82046838, + 0.48742905, 0.73832471, 0.57578135, -0.30538839, 1.51178117, 0.38984324, + -0.62124058, -2.21469989, 1.12493092, -0.04493361, -0.01619026, 0.94383621, + 0.82122120, 0.59390132 + ) + y <- c( + 0.91897737, 0.78213630, 0.07456498, -1.98935170, 0.61982575, -0.05612874, + -0.15579551, -1.47075238, -0.47815006, 0.41794156, 1.35867955, -0.10278773, + 0.38767161, -0.05380504, -1.37705956, -0.41499456, -0.39428995, -0.05931340, + 1.10002537, 0.76317575 + ) + result <- s_bland_altman(x, y, 0.9) + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + + +testthat::test_that("g_bland_altman works with default settings", { + x <- c( + -0.62645381, 0.18364332, -0.83562861, 1.59528080, 0.32950777, -0.82046838, + 0.48742905, 0.73832471, 0.57578135, -0.30538839, 1.51178117, 0.38984324, + -0.62124058, -2.21469989, 1.12493092, -0.04493361, -0.01619026, 0.94383621, + 0.82122120, 0.59390132 + ) + y <- c( + 0.91897737, 0.78213630, 0.07456498, -1.98935170, 0.61982575, -0.05612874, + -0.15579551, -1.47075238, -0.47815006, 0.41794156, 1.35867955, -0.10278773, + 0.38767161, -0.05380504, -1.37705956, -0.41499456, -0.39428995, -0.05931340, + 1.10002537, 0.76317575 + ) + conf_level <- 0.9 + testthat::skip_if_not_installed("vdiffr") + + withr::with_options( + opts_partial_match_old, + g_bland_altman <- g_bland_altman(x, y, conf_level = conf_level) + ) + + expect_snapshot_ggplot(title = "g_bland_altman", fig = g_bland_altman, width = 10, height = 8) +})