Skip to content

Commit

Permalink
switch to dontrun for most examples; skip some more tests on cran
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed May 1, 2024
1 parent c320a2e commit 5b8c7c6
Show file tree
Hide file tree
Showing 136 changed files with 616 additions and 4,570 deletions.
2 changes: 1 addition & 1 deletion R/RW.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' arguments to be interpreted by the parsing functions in \code{mvgam}
#' @rdname RW
#'@examples
#'\donttest{
#'\dontrun{
#'# A short example to illustrate CAR(1) models
#'# Function to simulate CAR1 data with seasonality
#'sim_corcar1 = function(n = 120,
Expand Down
2 changes: 1 addition & 1 deletion R/as.data.frame.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#'@param ... Ignored
#'@return A `data.frame`, `matrix`, or `array` containing the posterior draws.
#'@examples
#'\donttest{
#'\dontrun{
#'sim <- sim_mvgam(family = Gamma())
#'mod1 <- mvgam(y ~ s(season, bs = 'cc'),
#' trend_model = 'AR1',
Expand Down
2 changes: 1 addition & 1 deletion R/conditional_effects.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' @author Nicholas J Clark
#' @seealso \code{\link[marginaleffects]{plot_predictions}}, \code{\link[marginaleffects]{plot_slopes}}
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data
#' simdat <- sim_mvgam(family = poisson(),
#' seasonality = 'hierarchical')
Expand Down
2 changes: 1 addition & 1 deletion R/dynamic.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#' @rdname dynamic
#' @return a `list` object for internal usage in 'mvgam'
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate a time-varying coefficient
#'#(as a Gaussian Process with length scale = 10)
#'set.seed(1111)
Expand Down
2 changes: 1 addition & 1 deletion R/evaluate_mvgams.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#'stable forecasts
#'@seealso \code{\link{forecast}}, \code{\link{score}}, \code{\link{lfo_cv}}
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate from a Poisson-AR2 model with a seasonal smooth
#'set.seed(100)
#'dat <- sim_mvgam(T = 75,
Expand Down
2 changes: 1 addition & 1 deletion R/families.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ student_t = function(link = 'identity'){

#' @rdname mvgam_families
#' @examples
#' \donttest{
#' \dontrun{
#' # Example showing how to set up N-mixture models
#' set.seed(999)
#'# Simulate observations for species 1, which shows a declining trend and 0.7 detection probability
Expand Down
2 changes: 1 addition & 1 deletion R/forecast.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ forecast <- function(object, ...){
#'@rdname forecast.mvgam
#'@method forecast mvgam
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 3, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
#' trend_model = AR(),
Expand Down
2 changes: 1 addition & 1 deletion R/hindcast.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ hindcast <- function(object, ...){
#'@rdname hindcast.mvgam
#'@method hindcast mvgam
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 3, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
#' trend_model = AR(),
Expand Down
2 changes: 1 addition & 1 deletion R/index-mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NULL
#' @return a `list` object of the variables that can be extracted, along
#' with their aliases
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
#' trend_model = AR(),
Expand Down
18 changes: 10 additions & 8 deletions R/lfo_cv.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#'@references Paul-Christian Bürkner, Jonah Gabry & Aki Vehtari (2020). Approximate leave-future-out cross-validation for Bayesian time series models
#'Journal of Statistical Computation and Simulation. 90:14, 2499-2523.
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate from a Poisson-AR2 model with a seasonal smooth
#'set.seed(100)
#'dat <- sim_mvgam(T = 75,
Expand Down Expand Up @@ -127,9 +127,11 @@ lfo_cv.mvgam = function(object,
if(missing(data)){
all_data <- object$obs_data
} else {
all_data <- data
all_data <- validate_series_time(data,
name = 'data',
trend_model = attr(object$model_data, 'trend_model'))
}
N <- max(all_data$time)
N <- max(all_data$index..time..index)

# Default minimum training time is 30, or
# whatever training time allows for at least 10 lfo_cv calculations
Expand Down Expand Up @@ -440,7 +442,7 @@ cv_split = function(data, last_train, fc_horizon = 1){
if(inherits(data, 'list')){

# Find indices of training and testing splits
temp_dat = data.frame(time = data$time,
temp_dat = data.frame(time = data$index..time..index,
series = data$series) %>%
dplyr::mutate(index = dplyr::row_number()) %>%
dplyr::arrange(time, series)
Expand Down Expand Up @@ -472,12 +474,12 @@ cv_split = function(data, last_train, fc_horizon = 1){

} else {
data_train <- data %>%
dplyr::filter(time <= last_train) %>%
dplyr::arrange(time, series)
dplyr::filter(index..time..index <= last_train) %>%
dplyr::arrange(index..time..index, series)

data_test <- data %>%
dplyr::filter(time > last_train) %>%
dplyr::arrange(time, series)
dplyr::filter(index..time..index > last_train) %>%
dplyr::arrange(index..time..index, series)

}

Expand Down
2 changes: 1 addition & 1 deletion R/logLik.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#'original model via the `newdata` argument in \code{\link{mvgam}},
#'testing observations)
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
Expand Down
2 changes: 1 addition & 1 deletion R/loo.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' for details). For `loo_compare.mvgam`, an object of class `compare.loo` (
#' [loo::loo_compare()] for details)
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate 4 time series with hierarchical seasonality
#'# and independent AR1 dynamic processes
#'set.seed(111)
Expand Down
2 changes: 1 addition & 1 deletion R/lv_correlations.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'@return A \code{list} object containing the mean posterior correlations
#'and the full array of posterior correlations
#'@examples
#'\donttest{
#'\dontrun{
#'simdat <- sim_mvgam()
#'mod <- mvgam(y ~ s(season, bs = 'cc',
#' k = 6),
Expand Down
2 changes: 1 addition & 1 deletion R/mcmc_plot.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @seealso \code{\link{mvgam_draws}} for an overview of some of the shortcut strings
#' that can be used for argument `variable`
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
#' trend_model = AR(),
Expand Down
2 changes: 1 addition & 1 deletion R/monotonic.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' @author Nicholas J Clark
#' @name monotonic
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate data from a monotonically increasing function
#' set.seed(123123)
#' x <- runif(80) * 4 - 1
Expand Down
2 changes: 1 addition & 1 deletion R/mvgam_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' @return The exact form of the output depends on the method.
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
#' trend_model = AR(),
Expand Down
2 changes: 1 addition & 1 deletion R/pairs.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' \code{\link[bayesplot:MCMC-scatterplots]{mcmc_pairs}}.
#'
#' @examples
#' \donttest{
#' \dontrun{
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
#' trend_model = AR(),
Expand Down
2 changes: 1 addition & 1 deletion R/plot.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#'@author Nicholas J Clark
#'@return A base R plot or set of plots
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate some time series
#'dat <- sim_mvgam(T = 80, n_series = 3)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/plot_mvgam_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'@return A \code{dataframe} of factor contributions and,
#'optionally, a series of base \code{R} plots
#'@examples
#'\donttest{
#'\dontrun{
#'simdat <- sim_mvgam()
#'mod <- mvgam(y ~ s(season, bs = 'cc',
#' k = 6),
Expand Down
8 changes: 4 additions & 4 deletions R/posterior_epred.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#' @seealso \code{\link{hindcast.mvgam}} \code{\link{posterior_linpred.mvgam}} \code{\link{posterior_predict.mvgam}}
#' @aliases posterior_epred
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down Expand Up @@ -110,7 +110,7 @@ posterior_epred.mvgam = function(object,
#' and \code{n_obs} is the number of observations in \code{newdata}
#' @seealso \code{\link{hindcast.mvgam}} \code{\link{posterior_epred.mvgam}} \code{\link{posterior_predict.mvgam}}
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down Expand Up @@ -193,7 +193,7 @@ posterior_linpred.mvgam = function(object,
#' and \code{n_obs} is the number of observations in \code{newdata}
#' @seealso \code{\link{hindcast.mvgam}} \code{\link{posterior_linpred.mvgam}} \code{\link{posterior_epred.mvgam}}
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down Expand Up @@ -260,7 +260,7 @@ posterior_predict.mvgam = function(object,
#' quantile estimates as specified via argument \code{probs}.
#' @seealso \code{\link{hindcast.mvgam}}
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down
4 changes: 2 additions & 2 deletions R/ppc.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#'@author Nicholas J Clark
#'@seealso \code{\link{pp_check.mvgam}}, \code{\link{predict.mvgam}}
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some smooth effects and fit a model
#' set.seed(0)
#' dat <- mgcv::gamSim(1, n = 200, scale = 2)
Expand Down Expand Up @@ -785,7 +785,7 @@ ppc.mvgam = function(object, newdata, data_test, series = 1, type = 'hist',
#' package.
#' @seealso \code{\link{ppc}} \code{\link{predict.mvgam}}
#' @examples
#' \donttest{
#' \dontrun{
#'simdat <- sim_mvgam(seasonality = 'hierarchical')
#'mod <- mvgam(y ~ series +
#' s(season, bs = 'cc', k = 6) +
Expand Down
26 changes: 26 additions & 0 deletions R/predict.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@
#' `predict.gam(object, type = "terms", se.fit = TRUE)`, where mean contributions
#' from each effect are returned in `matrix` form while standard errors (representing
#' the interval: `(max(probs) - min(probs)) / 2`) are returned in a separate `matrix`
#'@examples
#'\dontrun{
#'# Simulate 4 time series with hierarchical seasonality
#'# and independent AR1 dynamic processes
#'set.seed(111)
#'simdat <- sim_mvgam(seasonality = 'hierarchical',
#' trend_model = 'AR1',
#' family = gaussian())
#'
#'# Fit a model with shared seasonality
#'mod1 <- mvgam(y ~ s(season, bs = 'cc', k = 6),
#' data = simdat$data_train,
#' family = gaussian(),
#' trend_model = AR(),
#' burnin = 300,
#' samples = 300,
#' chains = 2)
#'
#'# Generate predictions against observed data
#'preds <- predict(mod1, summary = TRUE)
#'head(preds)
#'
#'# Generate predictions against test data
#'preds <- predict(mod1, newdata = simdat$data_test, summary = TRUE)
#'head(preds)
#'}
#'@export
predict.mvgam = function(object,
newdata,
Expand Down
2 changes: 1 addition & 1 deletion R/residuals.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' \code{robust}). The remaining columns starting with \code{Q} contain
#' quantile estimates as specified via argument \code{probs}.
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down
2 changes: 1 addition & 1 deletion R/score.mvgam_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#'posterior empirical quantiles. Intervals are not calculated when using `elpd` because forecasts
#'will only contain the linear predictors
#'@examples
#'\donttest{
#'\dontrun{
#'# Simulate observations for three count-valued time series
#'data <- sim_mvgam()
#'# Fit a dynamic model using 'newdata' to automatically produce forecasts
Expand Down
2 changes: 1 addition & 1 deletion R/update.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' for other functions in the package. See \code{\link{mvgam-class}} for details.
#' Use `methods(class = "mvgam")` for an overview on available methods.
#' @examples
#' \donttest{
#' \dontrun{
#' # Simulate some data and fit a Poisson AR1 model
#' simdat <- sim_mvgam(n_series = 1, trend_model = AR())
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* DESCRIPTION has been shortened appropriately
* Missing Rd tags have been added for all exported functions
* Examples that previously used non-exported functions have been fixed
* `\dontrun` has been replaced with `\donttest` throughout, but note that many of these examples take some time to run due to the need for 'Stan' models to compile. Using `--run-donttest`, the examples take between 38 and 50 minutes, depending on the test environment. A very similar R package that is on CRAN ('brms') sticks to the `\dontrun` convention because of this
* `\dontrun` was replaced with `\donttest` throughout, but this is likely to cause problems in any later CRAN checks because many of these examples take some time to run due to the need for 'Stan' models to compile. Using `--run-donttest`, the examples take between 38 and 50 minutes, depending on the test environment. A very similar R package that is on CRAN ('brms') sticks to the `\dontrun` convention because of this, so I have elected to only use `\donttest` in the examples for the package's primary function `mvgam()`
* `cat()` has been replaced with `message()` throughout
* `onexit()` has been used as suggested to ensure the user's `par` is not changed

Expand Down
Loading

0 comments on commit 5b8c7c6

Please sign in to comment.