File: test_auc.R

package info (click to toggle)
r-cran-modelmetrics 1.2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 300 kB
  • sloc: cpp: 252; sh: 10; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 964 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

context("auc Tests")

test_that("auc binary error", {

  Levs = 8
  Size = 100
  y = sample(1:Levs, Size, replace = TRUE)

  xm = matrix(runif(Levs*Size), ncol = Levs)
  xm = xm/rowSums(xm)

  expect_error(auc(y, xm)
    , "auc only works for binary outcomes at this time")

})


test_that("mauc", {

  Levs = 8
  Size = 100
  y = sample(1:Levs, Size, replace = TRUE)

  xm = matrix(runif(Levs*Size), ncol = Levs)
  xm = xm/rowSums(xm)
  # no warnings
  expect_silent(res1 <- mauc(y, xm))
  # estimated
  expect_true(!is.nan(res1$mauc))

  expect_silent(res2 <- mauc(y, as.data.frame(xm)))
  expect_true(res1$mauc == res2$mauc)
  expect_true(all(res1$auc == res2$auc))

  expect_silent(res3 <- mauc(as.character(y), as.data.frame(xm)))
  expect_true(res1$mauc == res3$mauc)
  expect_true(all(res1$auc == res3$auc))

  expect_silent(res4 <- mauc(as.factor(y), as.data.frame(xm)))
  expect_true(res1$mauc == res4$mauc)
  expect_true(all(res1$auc == res4$auc))

})