@@ -262,14 +262,14 @@ for(clv.fitted in list(
262
262
}
263
263
264
264
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
267
267
# - fit with correlation
268
268
# - constrained params
269
269
# - regularization
270
270
# - combinations
271
271
272
- test_that(" predict(boots) works on all model specifications" , {
272
+ test_that(" predict(uncertainty= boots) works on all model specifications" , {
273
273
fn.predict.boots <- function (clv.fitted ){
274
274
expect_warning(predict(clv.fitted , uncertainty = ' boots' , num.boots = 2 , predict.spending = TRUE , verbose = FALSE ), regexp = ' recommended to run' )
275
275
}
@@ -307,3 +307,53 @@ test_that("predict(boots) works on all model specifications", {
307
307
308
308
})
309
309
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