1
- test_that(" growthcleanr works as expected on synthetic data" , {
1
+ test_that(" growthcleanr works as expected on pediatric synthetic data" , {
2
2
3
3
# Run cleangrowth() on syngrowth data
4
4
data <- as.data.table(syngrowth )
@@ -89,11 +89,98 @@ test_that("growthcleanr works as expected on synthetic data", {
89
89
90
90
})
91
91
92
+ test_that(" growthcleanr works as expected on adult synthetic data" , {
93
+
94
+ # Run cleangrowth() on syngrowth data
95
+ data <- as.data.table(syngrowth )
96
+
97
+ # syngrowth hasn't changed in length
98
+ expect_equal(77721 , data [, .N ])
99
+ setkey(data , subjid , param , agedays )
100
+
101
+ # subset to adult data
102
+ data_adult <- copy(data [agedays > = 18 * 365.25 , ])
103
+
104
+ # Create small sample
105
+ d500 <- as.data.table(data_adult )[subjid %in% unique(data_adult [, subjid ])[1 : 500 ], ]
106
+ expect_equal(12447 , d500 [, .N ])
107
+
108
+ # Clean sample
109
+ cd500 <-
110
+ d500 [, gcr_result : = cleangrowth(
111
+ subjid ,
112
+ param ,
113
+ agedays ,
114
+ sex ,
115
+ measurement
116
+ )]
117
+
118
+ # Clean again with lower cutpoint
119
+ cd500cp <-
120
+ copy(d500 )[, gcr_result : = cleangrowth(
121
+ subjid ,
122
+ param ,
123
+ agedays ,
124
+ sex ,
125
+ measurement ,
126
+ adult_cutpoint = 18
127
+ )]
128
+
129
+
130
+ # Spot check individual results
131
+ gcr_result <- function (dt , rowid ) {
132
+ return (as.character(dt [id == rowid ]$ gcr_result ))
133
+ }
134
+
135
+ # These results should not change with cutpoint
136
+ expect_equal(" Include" , gcr_result(cd500 , 27166 ))
137
+ expect_equal(" Include" , gcr_result(cd500cp , 27166 ))
138
+
139
+ expect_equal(" Exclude-Adult-Identical-Same-Day" , gcr_result(cd500 , 47596 ))
140
+ expect_equal(" Exclude-Adult-Identical-Same-Day" , gcr_result(cd500cp , 47596 ))
141
+
142
+ expect_equal(" Exclude-Adult-BIV" , gcr_result(cd500 , 41872 ))
143
+ expect_equal(" Exclude-Adult-BIV" , gcr_result(cd500cp , 41872 ))
144
+
145
+ # Results for these records should change due to younger cutpoint
146
+ expect_equal(" Exclude-Extraneous-Same-Day" , gcr_result(cd500 , 38722 ))
147
+ expect_equal(" Exclude-Adult-Extraneous-Same-Day" , gcr_result(cd500cp , 38722 ))
148
+
149
+ expect_equal(" Exclude-Carried-Forward" , gcr_result(cd500 , 12923 ))
150
+ expect_equal(" Include" , gcr_result(cd500cp , 12923 ))
151
+
152
+ expect_equal(" Exclude-Extraneous-Same-Day" , gcr_result(cd500 , 25259 ))
153
+ expect_equal(" Exclude-Adult-Distinct-3-Or-More" , gcr_result(cd500cp , 25259 ))
154
+
155
+ # Check counts of exclusions by category
156
+ catcount <- function (df , category ) {
157
+ return (as.numeric(df %> % filter(gcr_result == category ) %> % select(n )))
158
+ }
159
+
160
+ d500_exclusions <-
161
+ cd500 %> % group_by(gcr_result ) %> % tally(sort = TRUE )
162
+ expect_equal(9745 , catcount(d500_exclusions , " Include" ))
163
+ expect_equal(2090 , catcount(d500_exclusions , " Exclude-Adult-Extraneous-Same-Day" ))
164
+ expect_equal(59 , catcount(d500_exclusions , " Exclude-Adult-Distinct-3-Or-More" ))
165
+ expect_equal(43 , catcount(d500_exclusions , " Exclude-Carried-Forward" ))
166
+ expect_equal(2 , catcount(d500_exclusions , " Exclude-Adult-Transpositions" ))
167
+
168
+ d500cp_exclusions <-
169
+ cd500cp %> % group_by(gcr_result ) %> % tally(sort = TRUE )
170
+ expect_equal(9774 , catcount(d500cp_exclusions , " Include" ))
171
+ expect_equal(2200 , catcount(d500cp_exclusions , " Exclude-Adult-Extraneous-Same-Day" ))
172
+ expect_equal(62 , catcount(d500cp_exclusions , " Exclude-Adult-Distinct-3-Or-More" ))
173
+ expect_true(is.na(catcount(d500cp_exclusions , " Exclude-Carried-Forward" )))
174
+ expect_equal(2 , catcount(d500cp_exclusions , " Exclude-Adult-Transpositions" ))
175
+
176
+ })
177
+
92
178
test_that(" growthcleanr works without either adult or pediatric data" , {
93
179
# creating small only adult and only pediatric data
94
180
# using default cutpoint -- 20
95
181
only_peds <- syngrowth [syngrowth $ agedays < 20 * 365.25 ,][1 : 50 ,]
96
182
only_adult <- syngrowth [syngrowth $ agedays > = 20 * 365.25 ,][1 : 50 ,]
183
+ nobody <- syngrowth [syngrowth $ agedays > 120 * 365.25 ,]
97
184
98
185
# testing cleangrowth works without adult data
99
186
peds_res <- cleangrowth(
@@ -102,7 +189,7 @@ test_that("growthcleanr works without either adult or pediatric data", {
102
189
only_peds $ agedays ,
103
190
only_peds $ sex ,
104
191
only_peds $ measurement ,
105
- quietly = T
192
+ quietly = TRUE
106
193
)
107
194
108
195
expect_equal(length(peds_res ), nrow(only_peds ))
@@ -114,9 +201,21 @@ test_that("growthcleanr works without either adult or pediatric data", {
114
201
only_adult $ agedays ,
115
202
only_adult $ sex ,
116
203
only_adult $ measurement ,
117
- quietly = T
204
+ quietly = TRUE
118
205
)
119
206
120
207
expect_equal(length(adult_res ), nrow(only_adult ))
121
208
122
- })
209
+ # testing cleangrowth works with no data
210
+ no_res <- cleangrowth(
211
+ nobody $ subjid ,
212
+ nobody $ param ,
213
+ nobody $ agedays ,
214
+ nobody $ sex ,
215
+ nobody $ measurement ,
216
+ quietly = TRUE
217
+ )
218
+
219
+ expect_equal(length(no_res ), nrow(nobody ))
220
+
221
+ })
0 commit comments