Description Usage Arguments Functions See Also Examples
Convenience functions for predicting on a dataset using a specified model fit.
1 2 3 | yrs_predict_retain(predict_df, model_fit, method = "retain")
yrs_predict_renew(predict_df, model_fit, method = "renew")
|
predict_df |
data frame to use for prediction |
model_fit |
model to run |
method |
character name of method used (for plotting) |
yrs_predict_retain
: Predict license buying - retention
yrs_predict_renew
: Predict license buying - renewal
Other functions to estimate annual license buying: yrs_avidity
,
yrs_calc_avg
, yrs_calc
,
yrs_fit
, yrs_lifetime
,
yrs_plot
, yrs_predict_avg
,
yrs_result
, yrs_zero
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 26 | library(dplyr)
library(ggplot2)
data(all_sports)
df_split <- all_sports %>%
yrs_avidity() %>%
yrs_zero_split() %>%
yrs_zero_filter(function(x) filter(x, age_year %in% 30:50))
# log trend fit of retention rates
train_df <- yrs_calc_retain(df_split)
model_fit <- yrs_fit_retain(train_df)
out <- yrs_predict_retain(data.frame(years_since = 1:40), model_fit)
sum(out$pct) # estimated annual license purchases over 40 years
ggplot(out, aes(years_since, pct)) + geom_line() + geom_point(data = train_df)
# logistic regression based on individual-level renewal
train_df2 <- yrs_calc_renew(df_split)
model_fit2 <- yrs_fit_renew(train_df2)
predict_df2 <- filter(df_split$year0, year == 2011) %>% select(num_years_held)
out2 <- 1:40 %>%
sapply(function(i) mutate(predict_df2, years_since = i), simplify = FALSE) %>%
bind_rows() %>%
yrs_predict_renew(model_fit2)
sum(out2$pct)
ggplot(out2, aes(years_since, pct)) + geom_line() + geom_point(data = train_df)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.