Building a more sophisticated model
One of the best predictors of future giving is a history of recent, frequent, and large gifts. In marketing terms, this is known as R/F/M:
- Recency
- Frequency
- Money
Donors that haven't given both recently and frequently may be especially likely to give again; in other words, the combined impact of recency and frequency may be greater than the sum of the separate effects.
Because these predictors together have a greater impact on the dependent variable, their joint effect must be modeled as an interaction. The donors
dataset has been loaded for you.
This exercise is part of the course
Supervised Learning in R: Classification
Exercise instructions
- Create a logistic regression model of
donated
as a function ofmoney
plus the interaction ofrecency
andfrequency
. Use*
to add the interaction term. - Examine the model's
summary()
to confirm the interaction effect was added. - Save the model's predicted probabilities as
rfm_prob
. Use thepredict()
function, and remember to set thetype
argument. - Plot a ROC curve by using the function
roc()
. Remember, this function takes the column of outcomes and the vector of predictions. - Compute the AUC for the new model with the function
auc()
and compare performance to the simpler model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Build a recency, frequency, and money (RFM) model
rfm_model <- ___
# Summarize the RFM model to see how the parameters were coded
# Compute predicted probabilities for the RFM model
rfm_prob <- ___
# Plot the ROC curve and find AUC for the new model
library(pROC)
ROC <- ___
plot(___, col = "red")
auc(___)