|
23 | 23 | #' @examples |
24 | 24 | #' \dontrun{ |
25 | 25 | #' # Having InputCollect and OutputCollect objects |
| 26 | +#' ## Recreate original saturation curve |
| 27 | +#' Response <- robyn_response( |
| 28 | +#' InputCollect = InputCollect, |
| 29 | +#' OutputCollect = OutputCollect, |
| 30 | +#' select_model = select_model, |
| 31 | +#' metric_name = "facebook_S" |
| 32 | +#' ) |
| 33 | +#' Response$plot |
26 | 34 | #' |
27 | | -#' # Get marginal response (mResponse) and marginal ROI (mROI) for |
28 | | -#' # the next 1k on 80k for search_S |
29 | | -#' spend1 <- 80000 |
| 35 | +#' ## Or you can call a JSON file directly (a bit slower) |
| 36 | +#' # Response <- robyn_response( |
| 37 | +#' # json_file = "your_json_path.json", |
| 38 | +#' # dt_input = dt_simulated_weekly, |
| 39 | +#' # dt_holidays = dt_prophet_holidays, |
| 40 | +#' # metric_name = "facebook_S" |
| 41 | +#' # ) |
| 42 | +#' |
| 43 | +#' ## Get the "next 100 dollar" marginal response on Spend1 |
| 44 | +#' Spend1 <- 20000 |
30 | 45 | #' Response1 <- robyn_response( |
31 | 46 | #' InputCollect = InputCollect, |
32 | 47 | #' OutputCollect = OutputCollect, |
33 | | -#' metric_name = "search_S", |
34 | | -#' metric_value = spend1 |
35 | | -#' )$response |
36 | | -#' # Get ROI for 80k |
37 | | -#' Response1 / spend1 # ROI for search 80k |
| 48 | +#' select_model = select_model, |
| 49 | +#' metric_name = "facebook_S", |
| 50 | +#' metric_value = Spend1, # total budget for date_range |
| 51 | +#' date_range = "last_1" # last two periods |
| 52 | +#' ) |
| 53 | +#' Response1$plot |
38 | 54 | #' |
39 | | -#' # Get response for 81k |
40 | | -#' spend2 <- spend1 + 1000 |
| 55 | +#' Spend2 <- Spend1 + 100 |
41 | 56 | #' Response2 <- robyn_response( |
42 | 57 | #' InputCollect = InputCollect, |
43 | 58 | #' OutputCollect = OutputCollect, |
44 | | -#' metric_name = "search_S", |
45 | | -#' metric_value = spend2 |
46 | | -#' )$response |
| 59 | +#' select_model = select_model, |
| 60 | +#' metric_name = "facebook_S", |
| 61 | +#' metric_value = Spend2, |
| 62 | +#' date_range = "last_1" |
| 63 | +#' ) |
| 64 | +#' # ROAS for the 100$ from Spend1 level |
| 65 | +#' (Response2$response_total - Response1$response_total) / (Spend2 - Spend1) |
47 | 66 | #' |
48 | | -#' # Get ROI for 81k |
49 | | -#' Response2 / spend2 # ROI for search 81k |
50 | | -#' # Get marginal response (mResponse) for the next 1k on 80k |
51 | | -#' Response2 - Response1 |
52 | | -#' # Get marginal ROI (mROI) for the next 1k on 80k |
53 | | -#' (Response2 - Response1) / (spend2 - spend1) |
| 67 | +#' ## Get response from for a given budget and date_range |
| 68 | +#' Spend3 <- 100000 |
| 69 | +#' Response3 <- robyn_response( |
| 70 | +#' InputCollect = InputCollect, |
| 71 | +#' OutputCollect = OutputCollect, |
| 72 | +#' select_model = select_model, |
| 73 | +#' metric_name = "facebook_S", |
| 74 | +#' metric_value = Spend3, # total budget for date_range |
| 75 | +#' date_range = "last_5" # last 5 periods |
| 76 | +#' ) |
| 77 | +#' Response3$plot |
54 | 78 | #' |
55 | | -#' # Example of getting paid media exposure response curves |
56 | | -#' imps <- 1000000 |
| 79 | +#' ## Example of getting paid media exposure response curves |
| 80 | +#' imps <- 10000000 |
57 | 81 | #' response_imps <- robyn_response( |
58 | 82 | #' InputCollect = InputCollect, |
59 | 83 | #' OutputCollect = OutputCollect, |
| 84 | +#' select_model = select_model, |
60 | 85 | #' metric_name = "facebook_I", |
61 | 86 | #' metric_value = imps |
62 | | -#' )$response |
63 | | -#' response_per_1k_imps <- response_imps / imps * 1000 |
64 | | -#' response_per_1k_imps |
| 87 | +#' ) |
| 88 | +#' response_imps$response_total / imps * 1000 |
| 89 | +#' response_imps$plot |
65 | 90 | #' |
66 | | -#' # Get response for 80k for search_S from the a certain model SolID |
67 | | -#' # in the current model output in the global environment |
68 | | -#' robyn_response( |
| 91 | +#' ## Example of getting organic media exposure response curves |
| 92 | +#' sendings <- 30000 |
| 93 | +#' response_sending <- robyn_response( |
69 | 94 | #' InputCollect = InputCollect, |
70 | 95 | #' OutputCollect = OutputCollect, |
71 | | -#' metric_name = "search_S", |
72 | | -#' metric_value = 80000, |
73 | | -#' dt_hyppar = OutputCollect$resultHypParam, |
74 | | -#' dt_coef = OutputCollect$xDecompAgg |
| 96 | +#' select_model = select_model, |
| 97 | +#' metric_name = "newsletter", |
| 98 | +#' metric_value = sendings |
75 | 99 | #' ) |
| 100 | +#' # response per 1000 sendings |
| 101 | +#' response_sending$response_total / sendings * 1000 |
| 102 | +#' response_sending$plot |
76 | 103 | #' } |
77 | 104 | #' @return List. Response value and plot. Class: \code{robyn_response}. |
78 | 105 | #' @export |
|
0 commit comments