[fb0f7e]: / tests / testthat / test-plcom2012.R

Download this file

94 lines (91 with data), 2.3 kB

 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
library(testthat)
test_output <- function() {
test_that('each condition gives the expected output', {
expect_equal(
plcom2012(
age = 62,
race = 'White',
education = 4,
bmi = 27,
copd = 0,
cancer_hist = 0,
family_hist_lung_cancer = 0,
smoking_status = 0,
smoking_intensity = 10 / 0.4021541613,
duration_smoking = 27,
smoking_quit_time = 10
)$prob
,
exp(-4.532506) / (1 + exp(-4.532506))
)
expect_equal(
plcom2012(
age = 62,
race = 'black',
education = 4,
bmi = 27,
copd = 0,
cancer_hist = 0,
family_hist_lung_cancer = 0,
smoking_status = 0,
smoking_intensity = 10 / 0.4021541613,
duration_smoking = 27,
smoking_quit_time = 10
)$prob
,
exp(-4.532506 + 0.3944778) / (1 + exp(-4.532506 + 0.3944778))
)
expect_equal(
plcom2012(
age = 62,
race = 'hispanic',
education = 4,
bmi = 27,
copd = 0,
cancer_hist = 0,
family_hist_lung_cancer = 0,
smoking_status = 0,
smoking_intensity = 10 / 0.4021541613,
duration_smoking = 27,
smoking_quit_time = 10
)$prob
,
exp(-4.532506 - 0.7434744) / (1 + exp(-4.532506 - 0.7434744))
)
expect_equal(
plcom2012(
age = 62,
race = 'asian',
education = 4,
bmi = 27,
copd = 0,
cancer_hist = 0,
family_hist_lung_cancer = 0,
smoking_status = 0,
smoking_intensity = 10 / 0.4021541613,
duration_smoking = 27,
smoking_quit_time = 10
)$prob
,
exp(-4.532506 - 0.466585) / (1 + exp(-4.532506 - 0.466585))
)
expect_equal(
plcom2012(
age = 62,
race = 'pacific islander',
education = 4,
bmi = 27,
copd = 0,
cancer_hist = 0,
family_hist_lung_cancer = 0,
smoking_status = 0,
smoking_intensity = 10 / 0.4021541613,
duration_smoking = 27,
smoking_quit_time = 10
)$prob
,
exp(-4.532506 + 1.027152) / (1 + exp(-4.532506 + 1.027152))
)
})
}
test_output()