yrs_plot: Plot results for predicting license buying

Description Usage Arguments See Also Examples

View source: R/model-YrsAnnual.R

Description

It's useful to visualize the results with retention estimates over time, especially for comparing alternative methods. This function takes the result of yrs_result and plots with some useful labelling and scaling.

Usage

1
yrs_plot(result_df, include_label = TRUE, xlim = 74, grp = method)

Arguments

result_df

results returned from yrs_result

include_label

if TRUE, displays the method name and years estimate next to the line

xlim

maximum x-axis limit for plot

grp

unquoted name of grouping variable

See Also

Other functions to estimate annual license buying: yrs_avidity, yrs_calc_avg, yrs_calc, yrs_fit, yrs_lifetime, yrs_predict_avg, yrs_predict, yrs_result, yrs_zero

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library(dplyr)
library(ggplot2)

data(all_sports)
avg <- yrs_result_avg(all_sports)

df_split <- all_sports %>%
    yrs_avidity(drop_na_yrs = FALSE) %>%
    yrs_zero_split() %>%
    yrs_zero_filter(function(x) filter(x, age_year %in% 25:35))

# comparing retention-based vs avg-years-based methods
observe <- yrs_result_observe(df_split)
retain <- yrs_result_retain(df_split)
max <- yrs_result_max(df_split)
bind_rows(retain, max, avg) %>% yrs_plot() + geom_point(data = observe)

# comparing retain & renew methods
renew <- yrs_result_renew(df_split)
bind_rows(retain, renew) %>% yrs_plot() + geom_point(data = observe)

# using a GAM for retain
retain <- df_split %>%
    yrs_result_retain(model = function(x) yrs_fit_retain_gam(x))
bind_rows(retain, max, avg) %>% yrs_plot() + geom_point(data = observe)

southwick-associates/lifetime documentation built on Feb. 24, 2020, 9:33 a.m.