@@ -185,23 +185,43 @@ predict.clv.fitted.transactions <- function(object, newdata=NULL, prediction.end
185
185
continuous.discount.factor = log(1 + 0.1 ), uncertainty = c(" none" , " boots" ), level = 0.9 , num.boots = 100 , verbose = TRUE , ... ){
186
186
187
187
check_err_msg(check_user_data_emptyellipsis(... ))
188
- check_err_msg(check_user_data_uncertainty(uncertainty = uncertainty ))
189
- # match uncertainty to one of the allowed values
190
- uncertainty <- match.arg(tolower(uncertainty ), choices = c(" none" , " boots" ), several.ok = FALSE )
191
188
192
189
# The usual prediction unless newdata indicates a new customer prediction (ie newdata=newcustomer())
193
- # the newdata classes for static and dyncov inherit from `clv.newcustomer.no.cov`
194
- if (is(newdata , " clv.newcustomer.no.cov" )){
195
- # TODO: Check that is not newcustomer.spending()
190
+ if (is(newdata , " clv.newcustomer.base" )){
191
+
196
192
# not other parameters except object and newdata may be given (all others must be missing)
197
- if (! all(missing(prediction.end ), missing(predict.spending ), missing(continuous.discount.factor ))){
198
- check_err_msg(" Parameters prediction.end, predict.spending and continuous.discount.factor may not be specified when predicting for new customers." )
193
+ if (! all(missing(prediction.end ), missing(predict.spending ),
194
+ missing(continuous.discount.factor ), missing(uncertainty ),
195
+ missing(level ), missing(num.boots ))){
196
+ check_err_msg(" No other parameters ('prediction.end', 'predict.spending', 'continuous.discount.factor', uncertainty', 'level', 'num.boots') may be specified when predicting for new customers!" )
199
197
}
200
198
199
+ # the newdata classes for static and dyncov inherit from `clv.newcustomer.no.cov`
200
+ # but `clv.newcustomer.spending` does not
201
+ if (! is(newdata , " clv.newcustomer.no.cov" )){
202
+
203
+ if (is(object , " clv.fitted.transactions.dynamic.cov" )){
204
+ msg.newcustomer <- " newcustomer.dynamic()"
205
+ }else {
206
+ if (is(object , " clv.fitted.transactions.static.cov" )){
207
+ msg.newcustomer <- " newcustomer.static()"
208
+ }else {
209
+ msg.newcustomer <- " newcustomer()"
210
+ }
211
+ }
212
+ check_err_msg(paste0(" To predict for new customers, 'newdata' has to be the output of '" ,msg.newcustomer ," '!" ))
213
+ }
201
214
202
215
return (clv.controlflow.predict.new.customer(clv.fitted = object , clv.newcustomer = newdata ))
203
216
}
204
217
218
+
219
+ # match uncertainty to one of the allowed values. Only after newdata section
220
+ # because after match.arg(), missing() is always false
221
+ check_err_msg(check_user_data_uncertainty(uncertainty = uncertainty ))
222
+ # match uncertainty to one of the allowed values
223
+ uncertainty <- match.arg(tolower(uncertainty ), choices = c(" none" , " boots" ), several.ok = FALSE )
224
+
205
225
# If it was not explicitly passed in the call, the spending model should only be applied
206
226
# it there is spending data. Otherwise, predict does not work out-of-the-box for
207
227
# data object w/o spending
0 commit comments