File: test-weightit.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 (44 lines) | stat: -rw-r--r-- 1,309 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
skip_on_os("mac")
skip_if_not_installed("WeightIt", minimum_version = "1.2.0")
skip_if_not_installed("cobalt")
skip_if_not_installed("insight", minimum_version = "0.20.4")

test_that("weightit, multinom", {
  data("lalonde", package = "cobalt")
  set.seed(1234)
  # Logistic regression ATT weights
  w.out <- WeightIt::weightit(
    treat ~ age + educ + married + re74,
    data = lalonde,
    method = "glm",
    estimand = "ATT"
  )
  lalonde$re78_3 <- factor(findInterval(lalonde$re78, c(0, 5e3, 1e4)))

  fit4 <- WeightIt::multinom_weightit(
    re78_3 ~ treat + age + educ,
    data = lalonde,
    weightit = w.out
  )
  expect_snapshot(print(model_parameters(fit4, exponentiate = TRUE), zap_small = TRUE))
})

test_that("weightit, ordinal", {
  data("lalonde", package = "cobalt")
  set.seed(1234)
  # Logistic regression ATT weights
  w.out <- WeightIt::weightit(
    treat ~ age + educ + married + re74,
    data = lalonde,
    method = "glm",
    estimand = "ATT"
  )
  lalonde$re78_3 <- factor(findInterval(lalonde$re78, c(0, 5e3, 1e4)))

  fit5 <- WeightIt::ordinal_weightit(
    ordered(re78_3) ~ treat + age + educ,
    data = lalonde,
    weightit = w.out
  )
  expect_snapshot(print(model_parameters(fit5, exponentiate = TRUE), zap_small = TRUE))
})