From 705b93ff656f52a48ca142591ea33cdd1ea051e2 Mon Sep 17 00:00:00 2001 From: Simon Kucharsky Date: Thu, 5 Dec 2024 17:52:18 +0100 Subject: [PATCH] Fix map seasonality plots (#110) * compute seasonality even for map * update test plots * update ignore files * try to fix test for windows --- .Rbuildignore | 2 + .gitignore | 2 + R/prophet.R | 16 +- .../_snaps/prophet/changepoint-plotdays.svg | 188 +++++----- .../_snaps/prophet/changepoint-plothours.svg | 180 +++++----- .../_snaps/prophet/changepoint-plotmins.svg | 188 +++++----- .../_snaps/prophet/changepoint-plotsecs.svg | 188 +++++----- .../_snaps/prophet/changepoint-plotweeks.svg | 180 +++++----- .../_snaps/prophet/changepoint-plotyears.svg | 180 +++++----- .../_snaps/prophet/covariate-plot-multi.svg | 332 +++++++++--------- .../prophet/custom-seasonality-plot-days.svg | 2 +- .../prophet/custom-seasonality-plot-hours.svg | 2 +- .../prophet/custom-seasonality-plot-mins.svg | 2 +- .../prophet/custom-seasonality-plot-multi.svg | 2 +- .../prophet/custom-seasonality-plot-secs.svg | 2 +- .../prophet/custom-seasonality-plot-weeks.svg | 2 +- .../prophet/custom-seasonality-plot-years.svg | 2 +- tests/testthat/_snaps/prophet/growth-rate.svg | 146 ++++---- tests/testthat/_snaps/prophet/offset.svg | 158 ++++----- .../_snaps/prophet/residual-variance.svg | 138 ++++---- .../_snaps/prophet/trend-forecast-plot.svg | 2 +- tests/testthat/test-prophet.R | 2 +- 22 files changed, 960 insertions(+), 956 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 4aa59b4..eb72242 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +^renv$ +^renv\.lock$ ^.*\.Rproj$ ^\.Rproj\.user$ ^\.travis\.yml$ diff --git a/.gitignore b/.gitignore index e46a21b..0fc8708 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,5 @@ Thumbs.db # RStudio files .Rproj.user _processedLockFile.lock +.Rprofile +renv/ diff --git a/R/prophet.R b/R/prophet.R index 675b7cd..5eed651 100644 --- a/R/prophet.R +++ b/R/prophet.R @@ -366,6 +366,14 @@ Prophet <- function(jaspResults, dataset = NULL, options) { } .prophetModelResultsReduce <- function(prophetModelResults, options) { + # seasonality estimates + predictedSeasonalities <- list() + for (seas in options[["seasonalities"]]) { + name <- seas[["name"]] + predictedSeasonalities[[name]] <- .prophetPredictSeasonality(name, prophetModelResults, options) + } + prophetModelResults[["predictedSeasonalities"]] <- predictedSeasonalities + if (options$estimation == "mcmc") { # posterior summaries ci <- .prophetIntervalLevels(options, "credible") @@ -383,14 +391,6 @@ Prophet <- function(jaspResults, dataset = NULL, options) { } prophetModelResults[["parameterDensities"]] <- parameterDensities - # seasonality estimates - predictedSeasonalities <- list() - for (seas in options[["seasonalities"]]) { - name <- seas[["name"]] - predictedSeasonalities[[name]] <- .prophetPredictSeasonality(name, prophetModelResults, options) - } - prophetModelResults[["predictedSeasonalities"]] <- predictedSeasonalities - # remove stanfit and mcmc samples from the results to reduce size of the results prophetModelResults$stan.fit <- NULL prophetModelResults$params <- NULL diff --git a/tests/testthat/_snaps/prophet/changepoint-plotdays.svg b/tests/testthat/_snaps/prophet/changepoint-plotdays.svg index b423dfa..50757b4 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plotdays.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plotdays.svg @@ -1,94 +1,94 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - - - -Jan 01 -Jan 15 -Feb 01 -Feb 15 -Mar 01 -Mar 15 -Apr 01 -dateDay -Change in growth rate -changepoint-plotdays - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + + + +Jan 01 +Jan 15 +Feb 01 +Feb 15 +Mar 01 +Mar 15 +Apr 01 +dateDay +Change in growth rate +changepoint-plotdays + + diff --git a/tests/testthat/_snaps/prophet/changepoint-plothours.svg b/tests/testthat/_snaps/prophet/changepoint-plothours.svg index 4b338b1..a119c45 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plothours.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plothours.svg @@ -1,90 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - -Jan 01 -Jan 02 -Jan 03 -Jan 04 -Jan 05 -timeHour -Change in growth rate -changepoint-plothours - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + +Jan 01 +Jan 02 +Jan 03 +Jan 04 +Jan 05 +timeHour +Change in growth rate +changepoint-plothours + + diff --git a/tests/testthat/_snaps/prophet/changepoint-plotmins.svg b/tests/testthat/_snaps/prophet/changepoint-plotmins.svg index 1b51dab..3f2b86b 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plotmins.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plotmins.svg @@ -1,94 +1,94 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - - - -00:00 -00:15 -00:30 -00:45 -01:00 -01:15 -01:30 -timeMinute -Change in growth rate -changepoint-plotmins - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + + + +00:00 +00:15 +00:30 +00:45 +01:00 +01:15 +01:30 +timeMinute +Change in growth rate +changepoint-plotmins + + diff --git a/tests/testthat/_snaps/prophet/changepoint-plotsecs.svg b/tests/testthat/_snaps/prophet/changepoint-plotsecs.svg index e45c7ab..8529290 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plotsecs.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plotsecs.svg @@ -1,94 +1,94 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - - - -00 -15 -30 -45 -00 -15 -30 -timeSecond -Change in growth rate -changepoint-plotsecs - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + + + +00 +15 +30 +45 +00 +15 +30 +timeSecond +Change in growth rate +changepoint-plotsecs + + diff --git a/tests/testthat/_snaps/prophet/changepoint-plotweeks.svg b/tests/testthat/_snaps/prophet/changepoint-plotweeks.svg index c201d5d..a7a01d5 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plotweeks.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plotweeks.svg @@ -1,90 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - -2018-01 -2018-07 -2019-01 -2019-07 -2020-01 -dateWeek -Change in growth rate -changepoint-plotweeks - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + +2018-01 +2018-07 +2019-01 +2019-07 +2020-01 +dateWeek +Change in growth rate +changepoint-plotweeks + + diff --git a/tests/testthat/_snaps/prophet/changepoint-plotyears.svg b/tests/testthat/_snaps/prophet/changepoint-plotyears.svg index 4ec1246..9d5caca 100644 --- a/tests/testthat/_snaps/prophet/changepoint-plotyears.svg +++ b/tests/testthat/_snaps/prophet/changepoint-plotyears.svg @@ -1,90 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.06 --0.04 --0.02 -0.00 -0.02 -0.04 -0.06 - - - - - - - - - - - - - -2020 -2040 -2060 -2080 -2100 -dateYear -Change in growth rate -changepoint-plotyears - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.06 +-0.04 +-0.02 +0.00 +0.02 +0.04 +0.06 + + + + + + + + + + + + + +2020 +2040 +2060 +2080 +2100 +dateYear +Change in growth rate +changepoint-plotyears + + diff --git a/tests/testthat/_snaps/prophet/covariate-plot-multi.svg b/tests/testthat/_snaps/prophet/covariate-plot-multi.svg index b379aae..b0e9a3e 100644 --- a/tests/testthat/_snaps/prophet/covariate-plot-multi.svg +++ b/tests/testthat/_snaps/prophet/covariate-plot-multi.svg @@ -1,166 +1,166 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --300% --200% --100% -0% -100% -200% -300% - - - - - - - - - - - - - -Jan -Feb -Mar -Apr -May -dateDay -contcor1 -covariate-plot-multi - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-300% +-200% +-100% +0% +100% +200% +300% + + + + + + + + + + + + + +Jan +Feb +Mar +Apr +May +dateDay +contcor1 +covariate-plot-multi + + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-days.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-days.svg index c2f7a24..cd81564 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-days.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-days.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-hours.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-hours.svg index 2253b5d..a90946c 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-hours.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-hours.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-mins.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-mins.svg index 6464d7e..e3e97bc 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-mins.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-mins.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-multi.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-multi.svg index 4cc60d8..b11cf2d 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-multi.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-multi.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-secs.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-secs.svg index 42d9530..bdb5226 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-secs.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-secs.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-weeks.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-weeks.svg index 2df1625..5eb3584 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-weeks.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-weeks.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/custom-seasonality-plot-years.svg b/tests/testthat/_snaps/prophet/custom-seasonality-plot-years.svg index 410cdeb..a7711cc 100644 --- a/tests/testthat/_snaps/prophet/custom-seasonality-plot-years.svg +++ b/tests/testthat/_snaps/prophet/custom-seasonality-plot-years.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/_snaps/prophet/growth-rate.svg b/tests/testthat/_snaps/prophet/growth-rate.svg index 28a4bfc..2463152 100644 --- a/tests/testthat/_snaps/prophet/growth-rate.svg +++ b/tests/testthat/_snaps/prophet/growth-rate.svg @@ -1,73 +1,73 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -1 -2 -3 -4 -5 -6 -7 - - - - - - - - - - - - - - - --0.5 --0.4 --0.3 --0.2 --0.1 -0.0 -Growth rate -Density -growth-rate - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +1 +2 +3 +4 +5 +6 +7 + + + + + + + + + + + + + + + +-0.5 +-0.4 +-0.3 +-0.2 +-0.1 +0.0 +Growth rate +Density +growth-rate + + diff --git a/tests/testthat/_snaps/prophet/offset.svg b/tests/testthat/_snaps/prophet/offset.svg index d6bd5fd..1721c2e 100644 --- a/tests/testthat/_snaps/prophet/offset.svg +++ b/tests/testthat/_snaps/prophet/offset.svg @@ -1,79 +1,79 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -2 -4 -6 -8 -10 -12 -14 - - - - - - - - - - - - - - - - - - --0.05 -0.00 -0.05 -0.10 -0.15 -0.20 -0.25 -0.30 -0.35 -Offset -Density -offset - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +2 +4 +6 +8 +10 +12 +14 + + + + + + + + + + + + + + + + + + +-0.05 +0.00 +0.05 +0.10 +0.15 +0.20 +0.25 +0.30 +0.35 +Offset +Density +offset + + diff --git a/tests/testthat/_snaps/prophet/residual-variance.svg b/tests/testthat/_snaps/prophet/residual-variance.svg index bcbd308..6dfca4a 100644 --- a/tests/testthat/_snaps/prophet/residual-variance.svg +++ b/tests/testthat/_snaps/prophet/residual-variance.svg @@ -1,69 +1,69 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -1 -2 -3 -4 -5 - - - - - - - - - - - - - -0.2 -0.4 -0.6 -0.8 -1.0 -1.2 -Residual variance -Density -residual-variance - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +1 +2 +3 +4 +5 + + + + + + + + + + + + + +0.2 +0.4 +0.6 +0.8 +1.0 +1.2 +Residual variance +Density +residual-variance + + diff --git a/tests/testthat/_snaps/prophet/trend-forecast-plot.svg b/tests/testthat/_snaps/prophet/trend-forecast-plot.svg index 98c7009..11fa49b 100644 --- a/tests/testthat/_snaps/prophet/trend-forecast-plot.svg +++ b/tests/testthat/_snaps/prophet/trend-forecast-plot.svg @@ -18,7 +18,7 @@ - + diff --git a/tests/testthat/test-prophet.R b/tests/testthat/test-prophet.R index 12a41a8..e52431f 100644 --- a/tests/testthat/test-prophet.R +++ b/tests/testthat/test-prophet.R @@ -186,7 +186,7 @@ test_that("Parameter Estimates Table results match (MAP)", { { # test windows result testthat::skip_on_os(c("mac", "linux")) - jaspTools::expect_equal_tables(table, list(-2.50859195109382, -2.31656506358638, 0.32805219661169)) + jaspTools::expect_equal_tables(table, list(-2.50358957234044, -2.32147823235013, 0.328046513061461)) } {