Skip to content

Commit 72e3245

Browse files
committed
predict(boots) runs when other params are given
1 parent 99e02d6 commit 72e3245

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

tests/testthat/test_runability_bootstrapping.R

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ for(clv.fitted in list(
262262
}
263263

264264

265-
# predict(boots) works on all model specifications -----------------------------
266-
# This also includes testing clv.bootstrapped.apply because it is used under the hood
265+
# predict(uncertainty=boots) works on all model specifications -----------------------------
266+
# This also includes testing `clv.bootstrapped.apply` because it is used under the hood
267267
# - fit with correlation
268268
# - constrained params
269269
# - regularization
270270
# - combinations
271271

272-
test_that("predict(boots) works on all model specifications", {
272+
test_that("predict(uncertainty=boots) works on all model specifications", {
273273
fn.predict.boots <- function(clv.fitted){
274274
expect_warning(predict(clv.fitted, uncertainty='boots', num.boots=2, predict.spending=TRUE, verbose=FALSE), regexp = 'recommended to run')
275275
}
@@ -307,3 +307,53 @@ test_that("predict(boots) works on all model specifications", {
307307

308308
})
309309

310+
311+
312+
# predict(uncertainty=boots) works with various inputs ------------------------------------
313+
314+
test_that("predict(uncertainty=boots) works with predict.spending, newdata, prediction.end", {
315+
316+
p.cdnow <- fit.cdnow(optimx.args = optimx.args.NM)
317+
318+
fn.predict.boots <- function(predict.spending=TRUE, newdata=NULL, prediction.end=NULL){
319+
expect_warning(dt.pred <- predict(
320+
p.cdnow,
321+
verbose=FALSE,
322+
uncertainty='boots',
323+
num.boots=2,
324+
newdata=newdata,
325+
prediction.end=prediction.end,
326+
predict.spending=predict.spending
327+
), regexp = "recommended to run")
328+
return(dt.pred)
329+
}
330+
331+
# predict.spending
332+
fn.predict.boots(predict.spending = TRUE)
333+
fn.predict.boots(predict.spending = FALSE)
334+
fn.predict.boots(predict.spending = gg)
335+
fn.predict.boots(predict.spending = fit.cdnow(model = gg))
336+
337+
# newdata
338+
clv.apparel.nocov <- fct.helper.create.clvdata.apparel.nocov()
339+
dt.pred <- fn.predict.boots(newdata=clv.apparel.nocov)
340+
# really did predict for the apparel dataset and not the cdnow
341+
expect_true(dt.pred[, .N] == nobs(clv.apparel.nocov))
342+
343+
# prediction.end
344+
clv.cdnow.noholdout <- fct.helper.create.clvdata.cdnow(estimation.split = NULL)
345+
346+
# with holdout, no prediction.end is required
347+
fn.predict.boots(prediction.end=NULL)
348+
# with holdout, can also with prediction.end
349+
fn.predict.boots(prediction.end=10)
350+
351+
# without holdout, prediction.end is required
352+
expect_error(
353+
predict(p.cdnow, uncertainty='boots', newdata=clv.cdnow.noholdout),
354+
regexp = "Cannot predict without prediction.end"
355+
)
356+
# without holdout, works if prediction.end is given
357+
fn.predict.boots(newdata=clv.cdnow.noholdout, prediction.end=10)
358+
359+
})

0 commit comments

Comments
 (0)