File: test-Hmisc.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 (43 lines) | stat: -rw-r--r-- 1,072 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
test_that("issue 697", {
  skip_if_not_installed("Hmisc")
  skip_if_not_installed("rms")

  # for some reason, Hmisc::transcan() doesn't find na.retain (which is an internal
  # function in Hmisc)
  na.retain <<- Hmisc:::na.retain

  set.seed(1)
  n <- 100
  df <- data.frame(
    y = round(runif(n), 2),
    x1 = sample(c(-1, 0, 1), n, TRUE),
    x2 = sample(c(-1, 0, 1), n, TRUE)
  )
  df$x1[c(0, 1, 2)] <- NA
  imputer <- suppressWarnings(Hmisc::transcan(
    ~ x1 + x2,
    data = df,
    imputed = TRUE,
    n.impute = 2,
    pr = FALSE,
    pl = FALSE
  ))

  suppressWarnings(
    mod <- Hmisc::fit.mult.impute(
      y ~ x1 + x2,
      fitter = rms::orm,
      xtrans = imputer,
      data = df,
      pr = FALSE
    )
  )

  expect_s3_class(parameters(mod), "parameters_model")
  expect_s3_class(standard_error(mod), "data.frame")
  expect_s3_class(p_value(mod), "data.frame")

  expect_identical(nrow(parameters(mod)), 3L)
  expect_identical(nrow(standard_error(mod)), 3L)
  expect_identical(nrow(p_value(mod)), 3L)
})