a b/tests/testthat/test-plcom2012.R
1
library(testthat)
2
3
test_output <- function() {
4
  test_that('each condition gives the expected output', {
5
    expect_equal(
6
      plcom2012(
7
        age = 62,
8
        race = 'White',
9
        education = 4,
10
        bmi = 27,
11
        copd = 0,
12
        cancer_hist = 0,
13
        family_hist_lung_cancer = 0,
14
        smoking_status = 0,
15
        smoking_intensity = 10 / 0.4021541613,
16
        duration_smoking = 27,
17
        smoking_quit_time = 10
18
      )$prob
19
      ,
20
      exp(-4.532506) / (1 + exp(-4.532506))
21
    )
22
    expect_equal(
23
      plcom2012(
24
        age = 62,
25
        race = 'black',
26
        education = 4,
27
        bmi = 27,
28
        copd = 0,
29
        cancer_hist = 0,
30
        family_hist_lung_cancer = 0,
31
        smoking_status = 0,
32
        smoking_intensity = 10 / 0.4021541613,
33
        duration_smoking = 27,
34
        smoking_quit_time = 10
35
      )$prob
36
      ,
37
      exp(-4.532506 + 0.3944778) / (1 + exp(-4.532506 + 0.3944778))
38
    )
39
    expect_equal(
40
      plcom2012(
41
        age = 62,
42
        race = 'hispanic',
43
        education = 4,
44
        bmi = 27,
45
        copd = 0,
46
        cancer_hist = 0,
47
        family_hist_lung_cancer = 0,
48
        smoking_status = 0,
49
        smoking_intensity = 10 / 0.4021541613,
50
        duration_smoking = 27,
51
        smoking_quit_time = 10
52
      )$prob
53
      ,
54
      exp(-4.532506 - 0.7434744) / (1 + exp(-4.532506 - 0.7434744))
55
    )
56
    expect_equal(
57
      plcom2012(
58
        age = 62,
59
        race = 'asian',
60
        education = 4,
61
        bmi = 27,
62
        copd = 0,
63
        cancer_hist = 0,
64
        family_hist_lung_cancer = 0,
65
        smoking_status = 0,
66
        smoking_intensity = 10 / 0.4021541613,
67
        duration_smoking = 27,
68
        smoking_quit_time = 10
69
      )$prob
70
      ,
71
      exp(-4.532506 - 0.466585) / (1 + exp(-4.532506 - 0.466585))
72
    )
73
    expect_equal(
74
      plcom2012(
75
        age = 62,
76
        race = 'pacific islander',
77
        education = 4,
78
        bmi = 27,
79
        copd = 0,
80
        cancer_hist = 0,
81
        family_hist_lung_cancer = 0,
82
        smoking_status = 0,
83
        smoking_intensity = 10 / 0.4021541613,
84
        duration_smoking = 27,
85
        smoking_quit_time = 10
86
      )$prob
87
      ,
88
      exp(-4.532506 + 1.027152) / (1 + exp(-4.532506 + 1.027152))
89
    )
90
  })
91
}
92
93
test_output()