Modeling subscription churn
Subscription churn usually clusters around the first day and each subsequent bill. “Buyer’s remorse” is a common phrase for early churn, and it’s no surprise that subscribers churn when presented with a bill. It’s important to model these clusters well because they’re where most customers churn.
Generate a subscription history
Let’s generate some toy data reflecting this common business scenario. In this example, 400 customers face a higher risk of leaving on the first day and around each monthly bill.
library(eha)
example_hazard_rates <- c(
0.06, # buyer's remorse
0.003,
0.055, # second bill
0.002,
0.05, # third bill
0.002,
0.04, # fourth bill
0.004)
# It seems that the eha::rpch function has a little bug
# with failing to pass the cuts, levels params. This is
# a quick fix.
# First generate piecewise-constant survival data
rpch <- function(n, cuts, levels) {
x <- runif(n)
qpch(x, cuts, levels)
}
x <- data.frame(
times = rpch(
n = 400,
cuts = c(1, # initial purchase
31, 34, # second bill
62, 65, # third bill
93, 96 # fourth bill
),
levels = example_hazard_rates
),
censor = 1
)
plot(
survfit(Surv(times, censor) ~ 1, data = x),
xlim = c(0, 100),
ylim = c(0.5, 1),
conf.int = TRUE,
main = "Subscription lifetime",
ylab = "% still paying",
xlab = "Days since subscribing"
)
Fit a generalized gamma model
Alright, now we have our toy dataset. Typical smooth parametric models will struggle in the face of buyer’s remorse and billing churn, so we need something new.
library(flexsurv) # <-- awesome library; Christopher Jackson, you rock!
fitg <- flexsurvreg(
Surv(times, censor) ~ 1,
data = x, dist = "gengamma")
plot(fitg, xlim = c(0, 100), ylim = c(0.5, 1),
main = "Subscription lifetime",
ylab = "% still paying",
xlab = "Days since subscribing")
Let the cancellation rate change at renewal
A piecewise model lets the rate change between intervals. Here we put cut points at the beginning and end of each billing window.
pfit <- phreg(
Surv(times, censor) ~ 1, data = x,
dist = "pch",
cuts = c(1, # initial purchase
31, 34, # second bill
62, 65, # third bill
93, 96 # fourth bill
)
)
survival_estimates <- function(x, xlim = c(0, 100)) {
if(x$n.strata > 1) stop("Developed for a single strata.")
ncov <- length(x$means)
npts <- 4999
xx <- seq(xlim[[1]], xlim[[2]], length = npts)
ppch(xx, x$cuts, x$hazards[1, ], lower.tail = FALSE)
}
estimates <- survival_estimates(pfit)
plot(fitg, xlim = c(0, 100), ylim = c(0.5, 1),
main = "Subscription lifetime",
ylab = "% still paying",
xlab = "Days since subscribing")
lines(
x = seq(0, 100, length = length(estimates)),
y = estimates,
col = "blue")
We can compare the estimated hazard rates with the rates used to generate the data.
estimated_hazard_rates <- piecewise(
enter = 0, exit = x$times, event = x$censor,
cutpoints = c(1, # initial purchase
31, 34, # second bill
62, 65, # third bill
93, 96 # fourth bill
))$intensity
data.frame(
actual = round(example_hazard_rates, 3),
estimates = round(estimated_hazard_rates, 3)
)
Measure uncertainty in the retention curve
Since we’re specifying the random data up front, we’re able to choose perfect cut points from a known distribution. It’s no surprise the model fits very well. With actual churn data, we need to take this a step further. Let’s bootstrap the estimates for a measure of uncertainty by resampling subscribers, refitting the model, and collecting its survival estimates at each time point.
piecewise_fit <- function(d, i) {
survival_estimates(
phreg(
Surv(times, censor) ~ 1, data = d[i, ],
dist = "pch",
cuts = c(1, # initial purchase
31, 34, # second bill
62, 65, # third bill
93, 96 # fourth bill
)
)
)
}
library(boot)
library(dplyr)
library(reshape2)
pch_estimates <- t(boot(x, piecewise_fit, R = 100)$t) %>%
as.data.frame() %>%
tbl_df() %>%
mutate(index = 1:n()) %>%
melt("index") %>%
tbl_df %>%
group_by(index) %>%
summarise(lower = quantile(value, 0.05),
estimate = mean(value),
upper = quantile(value, 0.95))
plot(fitg, xlim = c(0, 100), ylim = c(0.5, 1), conf.int = F,
main = "Subscription lifetime",
ylab = "% still paying",
xlab = "Days since subscribing")
dashed_lines <- function(y) {
lines(
x = seq(0, 100, length = nrow(pch_estimates)),
y = y,
col = "blue",
lty = 2)
}
lines(
x = seq(0, 100, length = nrow(pch_estimates)),
y = pch_estimates$estimate,
col = "blue",
lty = 1)
dashed_lines(pch_estimates$lower)
dashed_lines(pch_estimates$upper)
The piecewise-constant model assumes a steady exponential rate within each interval. It is a parametric model. In this example the generalized gamma distribution, a distribution that includes many others, can’t cope with the quick drops caused by buyer’s remorse and bills. The piecewise-constant model follows those drops. If we want to deploy an experiment that targets days 31–34, we can use this model to measure what happens when customers receive that renewal bill.