File: test-simulate_parameters.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 (42 lines) | stat: -rw-r--r-- 1,504 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
skip_on_os(c("mac", "linux", "solaris"))
skip_if_not(getRversion() >= "4.0.0")
skip_if_not_installed("sandwich")

mod <- lm(mpg ~ wt + cyl, data = mtcars)

test_that("simulate_parameters, lm", {
  set.seed(123)
  s1 <- simulate_parameters(mod)
  set.seed(123)
  s2 <- simulate_parameters(mod, vcov = "HC1")
  expect_equal(dim(s1), c(3L, 5L))
  expect_equal(dim(s2), c(3L, 5L))
  expect_false(isTRUE(all.equal(s1$Coefficient, s2$Coefficient, tolerance = 1e-5)))
  expect_false(isTRUE(all.equal(s1$Coefficient, s2$CI_low, tolerance = 1e-5)))
})

skip_on_cran()
skip_if_not_installed("glmmTMB")
data(fish)
mod <- suppressWarnings(glmmTMB::glmmTMB(
  count ~ child + camper + (1 | persons),
  ziformula = ~ child + camper + (1 | persons),
  data = fish,
  family = glmmTMB::truncated_poisson()
))

test_that("simulate_parameters, glmmTMB", {
  set.seed(123)
  s <- simulate_parameters(mod)
  expect_equal(dim(s), c(6L, 6L))
  expect_equal(s$Coefficient, c(1.26979, -1.14433, 0.73637, -0.39618, 2.05839, -1.01957), tolerance = 1e-1)
  expect_equal(s$CI_low, c(0.33767, -1.33193, 0.55914, -1.65328, 1.44539, -1.65345), tolerance = 1e-1)
})

test_that("simulate_parameters, glmmTMB, conditional only", {
  set.seed(123)
  s <- simulate_parameters(mod, component = "conditional")
  expect_equal(dim(s), c(3L, 5L))
  expect_equal(s$Coefficient, c(1.26979, -1.14433, 0.73637), tolerance = 1e-1)
  expect_equal(s$CI_low, c(0.33767, -1.33193, 0.55914), tolerance = 1e-1)
})