File: test-group_level_total.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 (84 lines) | stat: -rw-r--r-- 2,294 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
skip_on_os("mac")
skip_on_cran()
skip_if_not_installed("glmmTMB")
skip_if_not_installed("lme4")

test_that("group_level_total", {
  data("fish", package = "insight")

  m1 <- suppressWarnings(glmmTMB::glmmTMB(
    count ~ child + camper + (1 | ID),
    data = fish,
    family = poisson()
  ))

  m2 <- suppressWarnings(glmmTMB::glmmTMB(
    count ~ child + camper + (1 + xb | persons) + (1 + zg | ID),
    ziformula = ~ child + livebait + (1 + zg + nofish | ID),
    dispformula = ~xb,
    data = fish,
    family = glmmTMB::truncated_poisson()
  ))

  m3 <- suppressWarnings(glmmTMB::glmmTMB(
    count ~ child + camper,
    ziformula = ~ child + livebait + (1 | ID),
    data = fish,
    family = glmmTMB::truncated_poisson()
  ))

  m4 <- suppressWarnings(glmmTMB::glmmTMB(
    count ~ child + camper + (1 + xb | persons),
    ziformula = ~ child + livebait,
    dispformula = ~xb,
    data = fish,
    family = glmmTMB::truncated_poisson()
  ))

  m5 <- suppressWarnings(lme4::glmer(
    count ~ child + camper + (1 | ID),
    data = fish,
    family = poisson()
  ))

  m6 <- suppressWarnings(lme4::lmer(
    Reaction ~ Days + (1 + Days | Subject),
    data = lme4::sleepstudy
  ))

  out <- model_parameters(m1, effects = "total")
  expect_identical(dim(out), c(4L, 6L))

  out <- model_parameters(m2, effects = "total")
  expect_identical(dim(out), c(28L, 6L))

  out <- model_parameters(m3, effects = "total")
  expect_identical(dim(out), c(4L, 6L))

  out <- model_parameters(m4, effects = "total")
  expect_identical(dim(out), c(8L, 6L))

  out <- model_parameters(m5, effects = "total")
  expect_identical(dim(out), c(4L, 5L))

  out <- model_parameters(m6, effects = "total")
  expect_identical(dim(out), c(36L, 5L))
})


test_that("group_level_total, brms", {
  skip_if_not_installed("curl")
  skip_if_offline()
  skip_if_not_installed("httr2")
  skip_if_not_installed("brms")

  m1 <- insight::download_model("brms_zi_4")
  m2 <- insight::download_model("brms_sigma_3")
  skip_if(is.null(m1) || is.null(m2))

  out <- model_parameters(m1, effects = "total")
  expect_identical(dim(out), c(28L, 10L))

  out <- model_parameters(m2, effects = "total")
  expect_identical(dim(out), c(12L, 10L))
})