diff --git a/DESCRIPTION b/DESCRIPTION index d58b162d..2ff15959 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Title: Multivariate (Dynamic) Generalized Additive Models Version: 1.1.4 Date: 2024-09-05 Authors@R: person("Nicholas J", "Clark", , "nicholas.j.clark1214@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7131-3301")) -Description: Fit Bayesian Dynamic Generalized Additive Models to sets of time series. Users can build dynamic nonlinear State-Space models that can incorporate semiparametric effects in observation and process components, using a wide range of observation families. Estimation is performed using Markov Chain Monte Carlo with Hamiltonian Monte Carlo in the software 'Stan'. References: Clark & Wells (2022) . +Description: Fit Bayesian Dynamic Generalized Additive Models to multivariate observations. Users can build nonlinear State-Space models that can incorporate semiparametric effects in observation and process components, using a wide range of observation families. Estimation is performed using Markov Chain Monte Carlo with Hamiltonian Monte Carlo in the software 'Stan'. References: Clark & Wells (2022) . URL: https://github.com/nicholasjclark/mvgam, https://nicholasjclark.github.io/mvgam/ BugReports: https://github.com/nicholasjclark/mvgam/issues License: MIT + file LICENSE @@ -23,10 +23,8 @@ Imports: bayesplot (>= 1.5.0), ggplot2 (>= 2.0.0), parallel, - pbapply, mvnfast, purrr, - zoo, dplyr, magrittr, rlang diff --git a/NEWS.md b/NEWS.md index 827df4f8..3bcbd5eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ * Added a `fevd.mvgam()` method to compute forecast error variance decompositions from models fit with Vector Autoregressive dynamics (#21 and #76) ## Bug fixes +* Not necessarily a "bug fix", but this update removes several dependencies to lighten installation and improve efficiency of the workflow (#93) * Fixed a minor bug in the way `trend_map` recognises levels of the `series` factor * Bug fix to ensure `lfo_cv` recognises the actual times in `time`, just in case the user supplies data that doesn't start at `t = 1`. Also updated documentation to better reflect this * Bug fix to ensure `update.mvgam` captures any `knots` or `trend_knots` arguments that were passed to the original model call diff --git a/R/evaluate_mvgams.R b/R/evaluate_mvgams.R index 7ae31883..6493dfc3 100644 --- a/R/evaluate_mvgams.R +++ b/R/evaluate_mvgams.R @@ -340,8 +340,8 @@ roll_eval_mvgam = function(object, validate_pos_integer(fc_horizon) # Generate time variable from training data - if(class(object$obs_data)[1] == 'list'){ - all_timepoints <- (data.frame(time = object$obs_data$time) %>% + if(inherits(object$obs_data, 'list')){ + all_timepoints <- (data.frame(time = object$obs_data$index..time..index) %>% dplyr::select(time) %>% dplyr::distinct() %>% dplyr::arrange(time) %>% @@ -350,9 +350,9 @@ roll_eval_mvgam = function(object, } else { all_timepoints <- (object$obs_data %>% - dplyr::select(time) %>% + dplyr::select(index..time..index) %>% dplyr::distinct() %>% - dplyr::arrange(time) %>% + dplyr::arrange(index..time..index) %>% dplyr::mutate(time = dplyr::row_number())) %>% dplyr::pull(time) } @@ -393,14 +393,17 @@ roll_eval_mvgam = function(object, clusterEvalQ(cl, library(mgcv)) clusterEvalQ(cl, library(rstan)) clusterEvalQ(cl, library(dplyr)) - clusterExport(cl = cl, - unclass(lsf.str(envir = asNamespace("mvgam"), - all = T)), - envir = as.environment(asNamespace("mvgam")) - ) - - pbapply::pboptions(type = "none") - evals <- pbapply::pblapply(evaluation_seq, function(timepoint){ + + # Grab internal functions to export to each worker + funs_list <- c('eval_mvgam') + attr(funs_list, 'envir') <- as.environment(asNamespace("mvgam")) + attr(funs_list, 'mode') <- 'function' + + parallel::clusterExport(cl = cl, + funs_list, + envir = as.environment(asNamespace("mvgam"))) + + evals <- parallel::parLapply(cl = cl, evaluation_seq, function(timepoint){ eval_mvgam(object = object, n_samples = n_samples, n_cores = 1, @@ -409,8 +412,7 @@ roll_eval_mvgam = function(object, score = score, log = log, weights = weights) - }, - cl = cl) + }) stopCluster(cl) # Take sum of score at each evaluation point for multivariate models diff --git a/R/forecast.mvgam.R b/R/forecast.mvgam.R index c0bf46b8..2c31790e 100644 --- a/R/forecast.mvgam.R +++ b/R/forecast.mvgam.R @@ -858,14 +858,21 @@ forecast_draws = function(object, 'obs_uncertainty', 'time_dis'), envir = environment()) + + # Grab internal functions to export to each worker + funs_list <- c('extract_general_trend_pars', + 'linkfun', + 'forecast_trend', + 'extract_series_trend_pars', + 'mvgam_predict') + attr(funs_list, 'envir') <- as.environment(asNamespace("mvgam")) + attr(funs_list, 'mode') <- 'function' + parallel::clusterExport(cl = cl, - unclass(lsf.str(envir = asNamespace("mvgam"), - all = T)), + funs_list, envir = as.environment(asNamespace("mvgam"))) - pbapply::pboptions(type = "none") - - fc_preds <- pbapply::pblapply(seq_len(dim(betas)[1]), function(i){ + fc_preds <- parallel::parLapply(cl = cl, seq_len(dim(betas)[1]), function(i){ # Sample index samp_index <- i @@ -1023,7 +1030,7 @@ forecast_draws = function(object, }) } out - }, cl = cl) + }) stopCluster(cl) } diff --git a/docs/news/index.html b/docs/news/index.html index 85388faf..ad8ea0ca 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -69,7 +69,8 @@

New functionalities

Bug fixes

-
  • Fixed a minor bug in the way trend_map recognises levels of the series factor
  • +
    • Not necessarily a “bug fix”, but this update removes several dependencies to lighten installation and improve efficiency of the workflow (#93)
    • +
    • Fixed a minor bug in the way trend_map recognises levels of the series factor
    • Bug fix to ensure lfo_cv recognises the actual times in time, just in case the user supplies data that doesn’t start at t = 1. Also updated documentation to better reflect this
    • Bug fix to ensure update.mvgam captures any knots or trend_knots arguments that were passed to the original model call
diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png index 17a35806..7ae9c377 100644 Binary files a/docs/reference/Rplot001.png and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png index c75d4e2e..038edc52 100644 Binary files a/docs/reference/Rplot002.png and b/docs/reference/Rplot002.png differ diff --git a/docs/reference/Rplot003.png b/docs/reference/Rplot003.png index 86c28580..e739e3c0 100644 Binary files a/docs/reference/Rplot003.png and b/docs/reference/Rplot003.png differ diff --git a/docs/reference/Rplot004.png b/docs/reference/Rplot004.png index 20b8a969..579b29a6 100644 Binary files a/docs/reference/Rplot004.png and b/docs/reference/Rplot004.png differ diff --git a/docs/reference/Rplot005.png b/docs/reference/Rplot005.png index 5a91a972..d2bf39e1 100644 Binary files a/docs/reference/Rplot005.png and b/docs/reference/Rplot005.png differ diff --git a/docs/reference/Rplot006.png b/docs/reference/Rplot006.png index b25f273f..ba555a83 100644 Binary files a/docs/reference/Rplot006.png and b/docs/reference/Rplot006.png differ diff --git a/docs/reference/Rplot007.png b/docs/reference/Rplot007.png index 1858e4b9..8b2d434e 100644 Binary files a/docs/reference/Rplot007.png and b/docs/reference/Rplot007.png differ diff --git a/docs/reference/Rplot008.png b/docs/reference/Rplot008.png index 2e095d37..ed5b2d19 100644 Binary files a/docs/reference/Rplot008.png and b/docs/reference/Rplot008.png differ diff --git a/docs/reference/Rplot009.png b/docs/reference/Rplot009.png index 23ea0650..e6c65dbd 100644 Binary files a/docs/reference/Rplot009.png and b/docs/reference/Rplot009.png differ diff --git a/docs/reference/Rplot010.png b/docs/reference/Rplot010.png index 0d4c06b7..b57bcf19 100644 Binary files a/docs/reference/Rplot010.png and b/docs/reference/Rplot010.png differ diff --git a/docs/reference/Rplot011.png b/docs/reference/Rplot011.png index 09e3ae50..217b0833 100644 Binary files a/docs/reference/Rplot011.png and b/docs/reference/Rplot011.png differ diff --git a/docs/reference/Rplot012.png b/docs/reference/Rplot012.png index a77fe094..ed5bea27 100644 Binary files a/docs/reference/Rplot012.png and b/docs/reference/Rplot012.png differ diff --git a/docs/reference/Rplot013.png b/docs/reference/Rplot013.png index 39a292ce..5643a58f 100644 Binary files a/docs/reference/Rplot013.png and b/docs/reference/Rplot013.png differ diff --git a/docs/reference/code.html b/docs/reference/code.html index 973b12a6..b9c7f095 100644 --- a/docs/reference/code.html +++ b/docs/reference/code.html @@ -1,5 +1,5 @@ -Stan code and data objects for mvgam models — code • mvgamStan code and data objects for mvgam models — code • mvgam @@ -10,7 +10,7 @@ mvgam - 1.1.3 + 1.1.4