From 2807af75d39e5642674e92fccda70d00b521db16 Mon Sep 17 00:00:00 2001 From: laresbernardo Date: Mon, 5 Feb 2024 12:25:16 +0100 Subject: [PATCH 1/2] fix: intercept input not being stored (thus not exported in JSON file) --- R/DESCRIPTION | 2 +- R/R/outputs.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/DESCRIPTION b/R/DESCRIPTION index 347edba70..637e88f72 100644 --- a/R/DESCRIPTION +++ b/R/DESCRIPTION @@ -1,7 +1,7 @@ Package: Robyn Type: Package Title: Semi-Automated Marketing Mix Modeling (MMM) from Meta Marketing Science -Version: 3.10.5.9013 +Version: 3.10.5.9014 Authors@R: c( person("Gufeng", "Zhou", , "gufeng@meta.com", c("cre","aut")), person("Leonel", "Sentana", , "leonelsentana@meta.com", c("aut")), diff --git a/R/R/outputs.R b/R/R/outputs.R index e7aa09a82..313f16912 100644 --- a/R/R/outputs.R +++ b/R/R/outputs.R @@ -140,6 +140,7 @@ robyn_outputs <- function(InputCollect, OutputModels, cores = OutputModels$cores, iterations = OutputModels$iterations, trials = OutputModels$trials, + intercept = OutputModels$intercept, intercept_sign = OutputModels$intercept_sign, nevergrad_algo = OutputModels$nevergrad_algo, add_penalty_factor = OutputModels$add_penalty_factor, From b449273c6757c940ae7c1dda9bf46ea0ae19174f Mon Sep 17 00:00:00 2001 From: laresbernardo Date: Mon, 5 Feb 2024 12:43:35 +0100 Subject: [PATCH 2/2] fix: add ts_validation plot to all_plots and export regardless of ts_validation param for convergence viz --- R/R/plots.R | 18 ++++++++---------- R/man/robyn_outputs.Rd | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/R/R/plots.R b/R/R/plots.R index baacd294b..138d73164 100644 --- a/R/R/plots.R +++ b/R/R/plots.R @@ -224,12 +224,13 @@ robyn_plots <- function( } } # End of !hyper_fixed + # Time series and errors convergence validation get_height <- ceiling(12 * OutputCollect$OutputModels$trials / 3) - if (isTRUE(OutputCollect$OutputModels$ts_validation)) { - ts_validation_plot <- ts_validation(OutputCollect$OutputModels, quiet = TRUE, ...) + all_plots[["ts_validation"]] <- ts_validation(OutputCollect$OutputModels, quiet = TRUE, ...) + if (export) { ggsave( paste0(plot_folder, "ts_validation", ".png"), - plot = ts_validation_plot, dpi = 300, + plot = all_plots[["ts_validation"]], dpi = 300, width = 10, height = get_height, limitsize = FALSE ) } @@ -1400,10 +1401,10 @@ refresh_plots_json <- function(OutputCollectRF, json_file, export = TRUE, ...) { #################################################################### -#' Generate Plots for Time-Series Validation +#' Generate Plots for Time-Series Validation and Convergence #' #' Create a plot to visualize the convergence for each of the datasets -#' when time-series validation is enabled when running \code{robyn_run()}. +#' when running \code{robyn_run()}, especially useful for when using ts_validation. #' As a reference, the closer the test and validation convergence points are, #' the better, given the time-series wasn't overfitted. #' @@ -1411,9 +1412,6 @@ refresh_plots_json <- function(OutputCollectRF, json_file, export = TRUE, ...) { #' @return Invisible list with \code{ggplot} plots. #' @export ts_validation <- function(OutputModels, quiet = FALSE, ...) { - if (!isTRUE(OutputModels$ts_validation)) { - return(NULL) - } resultHypParam <- bind_rows( lapply(OutputModels[ which(names(OutputModels) %in% paste0("trial", seq(OutputModels$trials))) @@ -1466,8 +1464,8 @@ ts_validation <- function(OutputModels, quiet = FALSE, ...) { colour = .data$dataset # group = as.character(.data$trial) )) + - geom_point(alpha = 0.2, size = 0.9) + - geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs")) + + geom_point(alpha = 0.2, size = 0.9, na.rm = TRUE) + + geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs"), na.rm = TRUE) + facet_grid(.data$trial ~ .) + geom_hline(yintercept = 0, linetype = "dashed") + labs(y = "NRMSE [Upper 1% Winsorized]", x = "Iteration", colour = "Dataset") + diff --git a/R/man/robyn_outputs.Rd b/R/man/robyn_outputs.Rd index c48d83a4a..8c8312b45 100644 --- a/R/man/robyn_outputs.Rd +++ b/R/man/robyn_outputs.Rd @@ -140,7 +140,7 @@ outcomes on \code{robyn_run()} results. When \code{UI=TRUE}, enriched \code{OutputModels} results with additional plots and objects. Create a plot to visualize the convergence for each of the datasets -when time-series validation is enabled when running \code{robyn_run()}. +when running \code{robyn_run()}, especially useful for when using ts_validation. As a reference, the closer the test and validation convergence points are, the better, given the time-series wasn't overfitted. }