This function requires a correctly formated history table (see history
).
It produces a simple count of records per year, optionally by segment,
& runs a validation test: pct change per year.
est_part(history, segment = "tot", test_threshold = 20, show_test_stat = FALSE, suppress_warning = FALSE, outvar = "participants") est_recruit(history, segment = "tot", test_threshold = 35, show_test_stat = FALSE, suppress_warning = FALSE, outvar = "recruits")
history | data frame: input license history table |
---|---|
segment | character: defaults to "tot", which indicates no segmentation. Alternatively specifiy other license history variables ("res", "sex", etc.) |
test_threshold | numeric: threshold in whole number percentage points for pct change per year. A warning will be printed if the absolute value of the change for any year exceeds the threshold. |
show_test_stat | logical: If TRUE, the output table will include a variable holding the test statistic for each row. |
suppress_warning | logical: If TRUE, no test warning will be displayed (even if threshold is exceeded). Test statistics can still be included by setting show_test_stat = TRUE. |
outvar | character: name of variable that stores metric |
Returns a data frame with 3 variables (segment, "year", outvar), and optionally with 2 extra variables ("change", "pct_change") if show_test_stat = TRUE
Salic Function Reference: salic
Other dashboard functions: check_threshold
,
est_churn
, format_result
,
scaleup_part
library(dplyr) data(history) history <- history %>% label_categories() %>% recode_agecat() %>% filter(!agecat %in% c("0-17", "65+")) # participants est_part(history)#> # A tibble: 11 x 3 #> tot year participants #> <chr> <int> <int> #> 1 All 2008 5834 #> 2 All 2009 6775 #> 3 All 2010 6820 #> 4 All 2011 6734 #> 5 All 2012 6964 #> 6 All 2013 6801 #> 7 All 2014 7253 #> 8 All 2015 7153 #> 9 All 2016 7095 #> 10 All 2017 7045 #> 11 All 2018 6701# by segment # produces a warning est_part(history, "agecat")#> Warning: Threshold of 20 for pct_change exceeded: #> agecat year participants change pct_change #> 1 55-64 2009 1323 244 22.61353#> # A tibble: 55 x 3 #> agecat year participants #> <fct> <int> <int> #> 1 18-24 2008 709 #> 2 18-24 2009 827 #> 3 18-24 2010 835 #> 4 18-24 2011 805 #> 5 18-24 2012 849 #> 6 18-24 2013 864 #> 7 18-24 2014 948 #> 8 18-24 2015 963 #> 9 18-24 2016 968 #> 10 18-24 2017 884 #> # ... with 45 more rows# suppress warning x <- est_part(history, "agecat", test_threshold = 25) # new recruits history_new <- filter(history, !is.na(R3), R3 == "Recruit") est_recruit(history_new)#> # A tibble: 6 x 3 #> tot year recruits #> <chr> <int> <int> #> 1 All 2013 1618 #> 2 All 2014 1954 #> 3 All 2015 1984 #> 4 All 2016 2040 #> 5 All 2017 1873 #> 6 All 2018 1699# apply over multiple segments segs <- c("tot", "res", "sex", "agecat") part <- sapply(segs, function(x) est_part(history, x), simplify = FALSE)#> Warning: Threshold of 20 for pct_change exceeded: #> res year participants change pct_change #> 1 Nonresident 2009 1511 445 41.74484 #> 2 Nonresident 2014 1731 324 23.02772#> Warning: Threshold of 20 for pct_change exceeded: #> agecat year participants change pct_change #> 1 55-64 2009 1323 244 22.61353# specify test thesholds by segment to suppress warnings tests <- c(tot = 20, res = 45, sex = 30, agecat = 40) part <- sapply(segs, function(x) est_part(history, x, tests[x]), simplify = FALSE)