File: test-betareg.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 (79 lines) | stat: -rw-r--r-- 1,883 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
skip_if_not_installed("betareg")
data("GasolineYield", package = "betareg")
data("FoodExpenditure", package = "betareg")

m1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield)
m2 <- betareg::betareg(I(food / income) ~ income + persons, data = FoodExpenditure)

test_that("ci", {
  expect_equal(
    ci(m1)$CI_low,
    as.vector(confint(m1)[, 1]),
    tolerance = 1e-4
  )
  expect_equal(
    ci(m2)$CI_low,
    as.vector(confint(m2)[, 1]),
    tolerance = 1e-4
  )
})

test_that("se", {
  s <- summary(m1)
  expect_equal(
    standard_error(m1)$SE,
    as.vector(c(s$coefficients$mean[, 2], s$coefficients$precision[, 2])),
    tolerance = 1e-4
  )
  s <- summary(m2)
  expect_equal(
    standard_error(m2)$SE,
    as.vector(c(s$coefficients$mean[, 2], s$coefficients$precision[, 2])),
    tolerance = 1e-4
  )
})

test_that("p_value", {
  expect_equal(
    p_value(m1)$p,
    c(0, 0, 0, 0, 0, 0, 0, 0, 1e-05, 0.00114, 0, 6e-05),
    tolerance = 1e-3
  )
  expect_equal(
    p_value(m2)$p,
    c(0.00542, 5e-05, 8e-04, 1e-05),
    tolerance = 1e-3
  )
})

# check vcov args
test_that("model_parameters", {
  expect_message({
    out <- model_parameters(m1, vcov = "vcovHAC")
  })
  expect_equal(out$SE, unname(coef(summary(m1))[[1]][, 2]), tolerance = 1e-3)
})


test_that("model_parameters", {
  expect_equal(
    model_parameters(m1)$Coefficient,
    as.vector(coef(m1))[1:11],
    tolerance = 1e-4
  )
  expect_equal(
    model_parameters(m1, component = "all")$Coefficient,
    as.vector(coef(m1)),
    tolerance = 1e-4
  )
  expect_equal(
    model_parameters(m2)$Coefficient,
    c(-0.62255, -0.0123, 0.11846),
    tolerance = 1e-4
  )
  expect_equal(
    model_parameters(m2, component = "all")$Coefficient,
    c(-0.62255, -0.0123, 0.11846, 35.60975033),
    tolerance = 1e-4
  )
})