Skip to content

Commit d3977c4

Browse files
authored
Update tests (#183)
* Changes for #180 * other test updates
1 parent 4dab76f commit d3977c4

File tree

6 files changed

+323
-47
lines changed

6 files changed

+323
-47
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Imports:
2525
dplyr (>= 1.1.0),
2626
furrr,
2727
generics (>= 0.1.3),
28-
ggplot2,
28+
ggplot2 (>= 3.5.2),
2929
hardhat,
3030
pillar,
3131
purrr,

tests/testthat/_snaps/cal-estimate.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@
123123
`.pred_class_1` ==> class_1
124124
`.pred_class_2` ==> class_2
125125

126+
# Logistic spline switches to linear if too few unique
127+
128+
Code
129+
sl_gam <- cal_estimate_logistic(segment_logistic, Class, smooth = TRUE)
130+
Condition
131+
Warning:
132+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
133+
134+
---
135+
136+
Code
137+
sl_gam <- cal_estimate_logistic(segment_logistic, Class, .by = id, smooth = TRUE)
138+
Condition
139+
Warning:
140+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
141+
Warning:
142+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
143+
126144
# Isotonic estimates work - data.frame
127145

128146
Code
@@ -523,6 +541,41 @@
523541
Warning:
524542
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
525543

544+
---
545+
546+
Code
547+
sl_gam <- cal_estimate_linear(boosting_predictions_oob, outcome, smooth = TRUE)
548+
Condition
549+
Warning:
550+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
551+
552+
---
553+
554+
Code
555+
sl_gam <- cal_estimate_linear(boosting_predictions_oob, outcome, .by = id,
556+
smooth = TRUE)
557+
Condition
558+
Warning:
559+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
560+
Warning:
561+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
562+
Warning:
563+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
564+
Warning:
565+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
566+
Warning:
567+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
568+
Warning:
569+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
570+
Warning:
571+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
572+
Warning:
573+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
574+
Warning:
575+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
576+
Warning:
577+
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
578+
526579
# Multinomial spline switches to linear if too few unique
527580

528581
Code

tests/testthat/_snaps/cal-plot.md

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# Binary breaks functions work with group argument
22

3+
Code
4+
get_labs(res)
5+
Output
6+
$colour
7+
[1] "id"
8+
9+
$fill
10+
[1] "id"
11+
12+
$x.sec
13+
NULL
14+
15+
$x
16+
[1] "Bin Midpoint"
17+
18+
$y
19+
[1] "Event Rate"
20+
21+
$y.sec
22+
NULL
23+
24+
$intercept
25+
[1] "intercept"
26+
27+
$slope
28+
[1] "slope"
29+
30+
$ymin
31+
[1] "lower"
32+
33+
$ymax
34+
[1] "upper"
35+
36+
$alt
37+
[1] ""
38+
39+
40+
---
41+
342
x `.by` cannot select more than one column.
443
i The following 2 columns were selected:
544
i group1 and group2
@@ -11,6 +50,45 @@
1150

1251
# Binary logistic functions work with group argument
1352

53+
Code
54+
get_labs(res)
55+
Output
56+
$colour
57+
[1] "id"
58+
59+
$fill
60+
[1] "id"
61+
62+
$x.sec
63+
NULL
64+
65+
$x
66+
[1] "Probability"
67+
68+
$y
69+
[1] "Predicted Event Rate"
70+
71+
$y.sec
72+
NULL
73+
74+
$intercept
75+
[1] "intercept"
76+
77+
$slope
78+
[1] "slope"
79+
80+
$ymin
81+
[1] "lower"
82+
83+
$ymax
84+
[1] "upper"
85+
86+
$alt
87+
[1] ""
88+
89+
90+
---
91+
1492
x `.by` cannot select more than one column.
1593
i The following 2 columns were selected:
1694
i group1 and group2
@@ -33,6 +111,171 @@
33111
Caused by error:
34112
! Invalid `event_level` entry: invalid. Valid entries are "first", "second", or "auto".
35113

114+
# regression functions work
115+
116+
Code
117+
get_labs(res)
118+
Output
119+
$x.sec
120+
NULL
121+
122+
$x
123+
[1] "Observed"
124+
125+
$y
126+
[1] "Predicted"
127+
128+
$y.sec
129+
NULL
130+
131+
$intercept
132+
[1] "intercept"
133+
134+
$slope
135+
[1] "slope"
136+
137+
$colour
138+
[1] "colour"
139+
140+
$fill
141+
[1] "fill"
142+
143+
$alt
144+
[1] ""
145+
146+
147+
---
148+
149+
Code
150+
get_labs(res)
151+
Output
152+
$x.sec
153+
NULL
154+
155+
$x
156+
[1] "Observed"
157+
158+
$y
159+
[1] "Predicted"
160+
161+
$y.sec
162+
NULL
163+
164+
$intercept
165+
[1] "intercept"
166+
167+
$slope
168+
[1] "slope"
169+
170+
$colour
171+
[1] "colour"
172+
173+
$fill
174+
[1] "fill"
175+
176+
$alt
177+
[1] ""
178+
179+
180+
---
181+
182+
Code
183+
get_labs(res)
184+
Output
185+
$x.sec
186+
NULL
187+
188+
$x
189+
[1] "Observed"
190+
191+
$y
192+
[1] "Predicted"
193+
194+
$y.sec
195+
NULL
196+
197+
$intercept
198+
[1] "intercept"
199+
200+
$slope
201+
[1] "slope"
202+
203+
$colour
204+
[1] "colour"
205+
206+
$fill
207+
[1] "fill"
208+
209+
$alt
210+
[1] ""
211+
212+
213+
---
214+
215+
Code
216+
get_labs(res)
217+
Output
218+
$x.sec
219+
NULL
220+
221+
$x
222+
[1] "Observed"
223+
224+
$y
225+
[1] "Predicted"
226+
227+
$y.sec
228+
NULL
229+
230+
$intercept
231+
[1] "intercept"
232+
233+
$slope
234+
[1] "slope"
235+
236+
$colour
237+
[1] "colour"
238+
239+
$fill
240+
[1] "fill"
241+
242+
$alt
243+
[1] ""
244+
245+
246+
---
247+
248+
Code
249+
get_labs(res)
250+
Output
251+
$x.sec
252+
NULL
253+
254+
$x
255+
[1] "Observed"
256+
257+
$y
258+
[1] "Predicted"
259+
260+
$y.sec
261+
NULL
262+
263+
$intercept
264+
[1] "intercept"
265+
266+
$slope
267+
[1] "slope"
268+
269+
$colour
270+
[1] "colour"
271+
272+
$fill
273+
[1] "fill"
274+
275+
$alt
276+
[1] ""
277+
278+
36279
# regression plot function errors - grouped_df
37280

38281
x This function does not work with grouped data frames.

tests/testthat/test-cal-estimate.R

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ test_that("Logistic spline estimates work - tune_results", {
121121

122122
test_that("Logistic spline switches to linear if too few unique", {
123123
skip_if_not_installed("modeldata")
124-
skip("until refactored")
125124

126125
segment_logistic$.pred_good <- rep(
127126
x = 1,
@@ -134,8 +133,8 @@ test_that("Logistic spline switches to linear if too few unique", {
134133
sl_lm <- cal_estimate_logistic(segment_logistic, Class, smooth = FALSE)
135134

136135
expect_identical(
137-
sl_gam,
138-
sl_lm
136+
sl_gam$estimates[[1]]$estimate[[1]],
137+
sl_lm$estimates[[1]]$estimate[[1]]
139138
)
140139

141140
segment_logistic$id <- rep(
@@ -148,8 +147,8 @@ test_that("Logistic spline switches to linear if too few unique", {
148147
sl_lm <- cal_estimate_logistic(segment_logistic, Class, .by = id, smooth = FALSE)
149148

150149
expect_identical(
151-
sl_gam,
152-
sl_lm
150+
sl_gam$estimates[[1]]$estimate[[1]],
151+
sl_lm$estimates[[1]]$estimate[[1]]
153152
)
154153
})
155154

@@ -619,7 +618,6 @@ test_that("Linear spline estimates work - tune_results", {
619618

620619
test_that("Linear spline switches to linear if too few unique", {
621620
skip_if_not_installed("modeldata")
622-
skip("until refactored")
623621

624622
boosting_predictions_oob$.pred <- rep(
625623
x = 1:5,
@@ -632,8 +630,8 @@ test_that("Linear spline switches to linear if too few unique", {
632630
sl_lm <- cal_estimate_linear(boosting_predictions_oob, outcome, smooth = FALSE)
633631

634632
expect_identical(
635-
sl_gam,
636-
sl_lm
633+
sl_gam$estimates[[1]]$estimate[[1]],
634+
sl_lm$estimates[[1]]$estimate[[1]]
637635
)
638636

639637
expect_snapshot(
@@ -642,8 +640,8 @@ test_that("Linear spline switches to linear if too few unique", {
642640
sl_lm <- cal_estimate_linear(boosting_predictions_oob, outcome, .by = id, smooth = FALSE)
643641

644642
expect_identical(
645-
sl_gam,
646-
sl_lm
643+
sl_gam$estimates[[1]]$estimate[[1]],
644+
sl_lm$estimates[[1]]$estimate[[1]]
647645
)
648646
})
649647

0 commit comments

Comments
 (0)