File: test-bracl.R

package info (click to toggle)
r-cran-parameters 0.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,852 kB
  • sloc: sh: 16; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download
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
46
47
48
49
50
51
52
53
skip_if_not_installed("brglm2")

data("stemcell", package = "brglm2")
levels(stemcell$research) <- c("definitly", "alterly", "probably not", "definitely not")
m1 <- brglm2::bracl(research ~ as.numeric(religion) + gender, weights = frequency, data = stemcell, type = "ML")

test_that("model_parameters", {
  params <- model_parameters(m1, verbose = FALSE)
  expect_identical(
    params$Response,
    c(
      "definitly",
      "alterly",
      "probably not",
      "definitly",
      "alterly",
      "probably not",
      "definitly",
      "alterly",
      "probably not"
    )
  )
  expect_identical(
    params$Parameter,
    c(
      "definitly:(Intercept)", "alterly:(Intercept)", "probably not:(Intercept)",
      "definitly:as.numeric(religion)", "alterly:as.numeric(religion)",
      "probably not:as.numeric(religion)", "definitly:genderfemale",
      "alterly:genderfemale", "probably not:genderfemale"
    )
  )
  expect_equal(
    params$Coefficient,
    c(-1.24836, 0.47098, 0.42741, 0.4382, 0.25962, 0.01192, -0.13683, 0.18707, -0.16093),
    tolerance = 1e-3
  )
})

# check vcov args
test_that("model_parameters", {
  expect_message({
    out <- model_parameters(m1, vcov = "vcovHAC")
  })
  expect_equal(out$SE, unname(coef(summary(m1))[, 2]), tolerance = 1e-3)
})

# check order of response levels
test_that("print model_parameters", {
  out <- suppressMessages(utils::capture.output(print(model_parameters(m1, verbose = FALSE))))
  expect_identical(out[1], "# Response level: definitly")
  expect_identical(out[9], "# Response level: alterly")
  expect_identical(out[17], "# Response level: probably not")
})