Debian Codegraph @

tests/testthat/test-ergm.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 skip_if_not_installed("ergm")
7 suppressPackageStartupMessages(library(ergm))
8
9 data(florentine)
10 data(faux.mesa.high)
11
12 # cut down on elapsed time at the expense of model performance
13 ctrl <- control.ergm(MCMLE.maxit = 2)
14
15 gest <- ergm(flomarriage ~ edges + absdiff("wealth"))
16 gest2 <- ergm(flomarriage ~ edges + absdiff("wealth"), family = "gaussian")
17 suppressWarnings({
18 gest3 <- ergm(faux.mesa.high ~ edges + degree(1:3), control = ctrl)
19 })
20
21 test_that("ergm tidier arguments", {
22 check_arguments(tidy.ergm)
23 check_arguments(glance.ergm)
24 })
25
26 test_that("tidy.ergm", {
27 expect_snapshot({
28 tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE)
29 })
30
31 check_tidy_output(tde)
32
33 # regression test for #688
34 expect_true("term" %in% colnames(tde))
35
36 # number of columns in output varies with ergm version
37 # so this test is temporarily deactivated
38 # check_dims(tde, 2, 7)
39
40 # tidy.ergm warns when exponentiating w/o link
41 expect_snapshot(td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE))
42
43 check_tidy_output(td2)
44
45 # see comment above:
46 # check_dims(td2, 2, 7)
47 })
48
49 test_that("glance.ergm", {
50 gl <- glance(gest, deviance = TRUE)
51 gl2 <- glance(gest3, deviance = TRUE, mcmc = TRUE)
52 expect_snapshot(gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE))
53
54 check_glance_outputs(gl)
55 check_dims(gl, expected_cols = 9)
56 check_dims(gl2, expected_cols = 12)
57 check_dims(gl, expected_cols = 9)
58 })