File: test-mean_sd.R

package info (click to toggle)
r-cran-datawizard 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,300 kB
  • sloc: sh: 13; makefile: 2
file content (17 lines) | stat: -rw-r--r-- 711 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
test_that("mean_sd", {
  x <- c(-1, 0, 1)
  msd <- mean_sd(x)
  expect_identical(unname(msd), x)
  expect_named(msd, c("-SD", "Mean", "+SD"))

  msd <- mean_sd(mtcars[["mpg"]])
  mmad <- median_mad(mtcars[["mpg"]])
  expect_identical(unname(msd), mean(mtcars[["mpg"]]) + c(-1, 0, 1) * sd(mtcars[["mpg"]]))
  expect_identical(unname(mmad), median(mtcars[["mpg"]]) + c(-1, 0, 1) * mad(mtcars[["mpg"]]))

  msd2 <- mean_sd(mtcars[["mpg"]], times = 3L)
  expect_length(msd2, n = 3 * 2 + 1)
  expect_identical(unname(msd2[3:5]), unname(msd))
  expect_equal(unname(diff(msd2)), rep(sd(mtcars[["mpg"]]), 6), tolerance = 0.00001)
  expect_named(msd2, c("-3 SD", "-2 SD", "-1 SD", "Mean", "+1 SD", "+2 SD", "+3 SD"))
})