Skip to content

Commit

Permalink
add snaps for bland-altman function (#1201)
Browse files Browse the repository at this point in the history
closes #1175

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joe Zhu <joe.zhu@roche.com>
  • Loading branch information
3 people committed Mar 11, 2024
1 parent 0d4487f commit ed3b84a
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/testthat/_snaps/bland-altman.md
Original file line number Diff line number Diff line change
@@ -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

103 changes: 103 additions & 0 deletions tests/testthat/_snaps/bland-altman/g_bland_altman.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions tests/testthat/test-bland-altman.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit ed3b84a

Please sign in to comment.