File: test-model_parameters.vgam.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 (45 lines) | stat: -rw-r--r-- 1,753 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
skip_if_not_installed("VGAM")

skip_on_cran()

data("pneumo", package = "VGAM")
data("hunua", package = "VGAM")

set.seed(123)
pneumo <- transform(pneumo, let = log(exposure.time))

m1 <- suppressWarnings(VGAM::vgam(
  cbind(normal, mild, severe) ~ VGAM::s(let) + exposure.time,
  VGAM::cumulative(parallel = TRUE),
  data = pneumo,
  trace = FALSE
))

set.seed(123)
hunua$x <- rnorm(nrow(hunua))
m2 <- VGAM::vgam(
  agaaus ~ VGAM::s(altitude, df = 2) + VGAM::s(x) + beitaw + corlae, VGAM::binomialff,
  data = hunua
)

test_that("model_parameters.vgam", {
  skip("TODO: model_parameters doesn't work with 'VGAM::' in the formula")
  params <- suppressWarnings(model_parameters(m1))
  expect_equal(params$Coefficient, as.vector(m1@coefficients[params$Parameter]), tolerance = 1e-3)
  expect_identical(params$Parameter, c("(Intercept):1", "(Intercept):2", "exposure.time", "s(let)"))
  expect_equal(params$df, c(NA, NA, NA, 2.6501), tolerance = 1e-3)
  expect_equal(as.vector(na.omit(params$df)), as.vector(m1@nl.df), tolerance = 1e-3)
})

test_that("model_parameters.vgam", {
  skip("TODO: model_parameters doesn't work with 'VGAM::' in the formula")
  params <- suppressWarnings(model_parameters(m2))
  expect_equal(params$Coefficient, as.vector(m2@coefficients[params$Parameter]), tolerance = 1e-3)
  expect_identical(params$Parameter, c("(Intercept)", "beitaw", "corlae", "s(altitude, df = 2)", "s(x)"))
  expect_equal(params$df, c(NA, NA, NA, 0.82686, 2.8054), tolerance = 1e-3)
  expect_equal(as.vector(na.omit(params$df)), as.vector(m2@nl.df), tolerance = 1e-3)
  expect_named(params, c(
    "Parameter", "Coefficient", "SE", "CI", "CI_low", "CI_high", "Chi2",
    "df_error", "p", "Component"
  ))
})