File: test-p_function.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 (94 lines) | stat: -rw-r--r-- 2,272 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
data(iris)
model <- lm(Sepal.Length ~ Species, data = iris)

test_that("p_function ci-levels", {
  out <- p_function(model)
  expect_equal(
    out$CI_low,
    c(
      4.982759, 0.897132, 1.549132, 4.956774, 0.860384, 1.512384,
      4.92192, 0.811093, 1.463093, 4.862126, 0.726531, 1.378531
    ),
    tolerance = 1e-4
  )

  expect_identical(dim(out), c(12L, 5L))

  expect_equal(
    out$CI,
    c(0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.75, 0.75, 0.75, 0.95, 0.95, 0.95),
    tolerance = 1e-4
  )

  ref <- ci(model)
  expect_equal(
    out$CI_low[out$CI == 0.95],
    ref$CI_low,
    tolerance = 1e-4
  )

  ref <- ci(model, ci = 0.5)
  expect_equal(
    out$CI_low[out$CI == 0.5],
    ref$CI_low,
    tolerance = 1e-4
  )

  out <- p_function(model, ci_levels = c(0.3, 0.6, 0.9))
  expect_equal(
    out$CI,
    c(0.3, 0.3, 0.3, 0.6, 0.6, 0.6, 0.9, 0.9, 0.9),
    tolerance = 1e-4
  )

  skip_if_not_installed("sandwich")
  out <- p_function(model, vcov = "HC3")
  expect_equal(
    out$CI_low,
    c(
      4.989925, 0.901495, 1.548843, 4.971951, 0.869624, 1.511772,
      4.947844, 0.826875, 1.462047, 4.906485, 0.753538, 1.376742
    ),
    tolerance = 1e-4
  )
})


test_that("p_function keep-drop", {
  out <- p_function(model, keep = "Speciesversicolor")

  expect_identical(dim(out), c(4L, 5L))

  expect_equal(
    out$CI,
    c(0.25, 0.5, 0.75, 0.95),
    tolerance = 1e-4
  )

  expect_identical(
    out$Parameter,
    c(
      "Speciesversicolor", "Speciesversicolor", "Speciesversicolor",
      "Speciesversicolor"
    )
  )
})


test_that("p_function print", {
  out <- p_function(model)
  ref <- capture.output(print(out))

  expect_identical(
    ref,
    c(
      "Consonance Function",
      "",
      "Parameter            |       25% CI |       50% CI |       75% CI |       95% CI",
      "--------------------------------------------------------------------------------",
      "(Intercept)          | [4.98, 5.03] | [4.96, 5.06] | [4.92, 5.09] | [4.86, 5.15]",
      "Species [versicolor] | [0.90, 0.96] | [0.86, 1.00] | [0.81, 1.05] | [0.73, 1.13]",
      "Species [virginica]  | [1.55, 1.61] | [1.51, 1.65] | [1.46, 1.70] | [1.38, 1.79]"
    )
  )
})