From c0a0c4bf035fd0cce20af5072bdfb3be7688e30a Mon Sep 17 00:00:00 2001 From: santikka Date: Wed, 23 Aug 2023 16:15:31 +0300 Subject: [PATCH] number of cores again for CRAN --- NEWS.md | 11 ++++++----- R/as_data_frame.R | 1 + R/as_data_table.R | 1 + R/as_draws.R | 1 + R/ci.R | 1 + R/coef.R | 1 + R/dynamite.R | 2 ++ R/dynamiteformula.R | 3 +++ R/fitted.R | 1 + R/getters.R | 6 ++++++ R/lags.R | 1 + R/latent_factor.R | 1 + R/lfo.R | 3 +++ R/loo.R | 1 + R/mcmc_diagnostics.R | 1 + R/ndraws.R | 1 + R/nobs.R | 1 + R/plot.R | 4 ++++ R/predict.R | 1 + R/print.R | 1 + R/random.R | 1 + R/splines.R | 1 + R/summary.R | 1 + R/update.R | 1 + man/as.data.frame.dynamitefit.Rd | 1 + man/as.data.table.dynamitefit.Rd | 1 + man/as_draws-dynamitefit.Rd | 1 + man/coef.dynamitefit.Rd | 1 + man/confint.dynamitefit.Rd | 1 + man/dynamite.Rd | 4 ++++ man/dynamiteformula.Rd | 3 +++ man/fitted.dynamitefit.Rd | 1 + man/get_code.Rd | 1 + man/get_data.Rd | 1 + man/get_parameter_dims.Rd | 1 + man/get_parameter_names.Rd | 1 + man/get_parameter_types.Rd | 1 + man/get_priors.Rd | 1 + man/lags.Rd | 1 + man/lfactor.Rd | 1 + man/lfo.Rd | 1 + man/loo.dynamitefit.Rd | 1 + man/mcmc_diagnostics.Rd | 1 + man/ndraws.dynamitefit.Rd | 1 + man/nobs.dynamitefit.Rd | 1 + man/plot.dynamitefit.Rd | 1 + man/plot.lfo.Rd | 1 + man/plot_betas.Rd | 1 + man/plot_deltas.Rd | 1 + man/plot_nus.Rd | 1 + man/predict.dynamitefit.Rd | 1 + man/print.lfo.Rd | 1 + man/random_spec.Rd | 1 + man/splines.Rd | 1 + man/update.dynamitefit.Rd | 1 + tests/testthat/test-cmdstanr.R | 2 ++ tests/testthat/test-edgecases.R | 2 ++ tests/testthat/test-errors.R | 2 ++ tests/testthat/test-extended.R | 2 ++ tests/testthat/test-grunfeld.R | 2 ++ tests/testthat/test-internals.R | 2 ++ tests/testthat/test-lfactor.R | 2 ++ tests/testthat/test-output.R | 2 ++ tests/testthat/test-predict.R | 3 ++- tests/testthat/test-priors.R | 2 ++ tests/testthat/test-random.R | 2 ++ tests/testthat/test-recovery.R | 2 ++ tests/testthat/test-scaling.R | 2 ++ tests/testthat/test-warnings.R | 2 ++ vignettes/dynamite.Rmd | 1 + vignettes/dynamite_priors.Rmd | 1 + vignettes/dynamite_simulation.Rmd | 1 + 72 files changed, 109 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index c92de401..849fbd98 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,14 +1,15 @@ # dynamite 1.4.5 - - * `get_data` method for `dynamitefit` object now correctly uses the previously defined priors instead of the default ones. + + * The `get_data()` method for `dynamitefit` objects now correctly uses the previously defined priors instead of the default ones. * Fixed a bug in indexing of random effect terms. + * Limited the number of parallel threads used by the `data.table` package to 1 in examples, tests, and vignettes for CRAN. # dynamite 1.4.4 * Example of the `lfo()` method now uses a single chain and core to avoid a compatibility issue with CRAN. - * Fixed `plot_nus` for categorical responses. - * Fixed an issue which caused an error in error message of `predict` and `fitted` methods when `newdata` contained duplicate time points within group. - * Fixed an issue (#72) which caused NA ELPD value in `lfo` in case of missing data. + * Fixed `plot_nus()` for categorical responses. + * Fixed an issue which caused an error in error message of `predict()` and `fitted()` methods when `newdata` contained duplicate time points within group. + * Fixed an issue (#72) which caused NA ELPD value in `lfo()` in case of missing data. # dynamite 1.4.3 diff --git a/R/as_data_frame.R b/R/as_data_frame.R index da76fb62..16f310f0 100644 --- a/R/as_data_frame.R +++ b/R/as_data_frame.R @@ -72,6 +72,7 @@ #' model parameters in a long format. For a wide format, see #' [dynamite::as_draws()]. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' as.data.frame( #' gaussian_example_fit, #' responses = "y", diff --git a/R/as_data_table.R b/R/as_data_table.R index 37f06e78..a8492c65 100644 --- a/R/as_data_table.R +++ b/R/as_data_table.R @@ -13,6 +13,7 @@ #' @return A `data.table` containing either samples or summary statistics of #' the model parameters. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' as.data.table( #' gaussian_example_fit, #' responses = "y", diff --git a/R/as_draws.R b/R/as_draws.R index 72969e21..17d8c48e 100644 --- a/R/as_draws.R +++ b/R/as_draws.R @@ -23,6 +23,7 @@ #' @inheritParams as.data.frame.dynamitefit #' @return A `draws_df` object. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' as_draws(gaussian_example_fit, types = c("sigma", "beta")) #' #' # Compute MCMC diagnostics using the posterior package diff --git a/R/ci.R b/R/ci.R index 7252baf2..708a42ba 100644 --- a/R/ci.R +++ b/R/ci.R @@ -18,6 +18,7 @@ #' to `NA`. #' @srrstats {RE4.3} Provides credible intervals. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' confint(gaussian_example_fit, level = 0.9) #' confint.dynamitefit <- function(object, parm, level = 0.95, ...) { diff --git a/R/coef.R b/R/coef.R index 7ea46ec3..3f183c19 100644 --- a/R/coef.R +++ b/R/coef.R @@ -23,6 +23,7 @@ #' model parameters in a long format. #' @srrstats {G2.3a, RE4.2} Provides model coefficients. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' betas <- coef(gaussian_example_fit, type = "beta") #' deltas <- coef(gaussian_example_fit, type = "delta") #' diff --git a/R/dynamite.R b/R/dynamite.R index 51ae9ae1..5df3250e 100644 --- a/R/dynamite.R +++ b/R/dynamite.R @@ -131,6 +131,7 @@ #' from Panel Data with Dynamic Multivariate Panel Models. SocArxiv preprint, #' . #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \donttest{ #' # Please update your rstan and StanHeaders installation before running #' # on Windows @@ -624,6 +625,7 @@ remove_redundant_parameters <- function(stan_input, backend, #' @family formulas #' @export #' @examples +#' data.table::setDTthreads(1) # For CRAN #' formula(gaussian_example_fit) #' formula.dynamitefit <- function(x, ...) { diff --git a/R/dynamiteformula.R b/R/dynamiteformula.R index 76fbacdd..6f9797a4 100644 --- a/R/dynamiteformula.R +++ b/R/dynamiteformula.R @@ -120,6 +120,7 @@ #' @srrstats {G2.3b} Uses tolower. #' @srrstats {RE1.0} Uses a formula interface. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' # A single gaussian response channel with a time-varying effect of 'x', #' # and a time-varying effect of the lag of 'y' using B-splines with #' # 20 degrees of freedom for the coefficients of the time-varying terms. @@ -351,6 +352,7 @@ parse_name <- function(x) { #' @param e2 \[`dynamiteformula`]\cr A model formula specification. #' @export #' @examples +#' data.table::setDTthreads(1) # For CRAN #' obs(y ~ x, family = "gaussian") + obs(z ~ w, family = "exponential") #' `+.dynamiteformula` <- function(e1, e2) { @@ -367,6 +369,7 @@ parse_name <- function(x) { #' @param ... Ignored. #' @export #' @examples +#' data.table::setDTthreads(1) # For CRAN #' x <- obs(y ~ x + random(~ 1 + lag(d)), family = "gaussian") + #' obs(z ~ varying(~w), family = "exponential") + #' aux(numeric(d) ~ log(y) | init(c(0, 1))) + diff --git a/R/fitted.R b/R/fitted.R index aa201fc8..d347aca3 100644 --- a/R/fitted.R +++ b/R/fitted.R @@ -16,6 +16,7 @@ #' @return A `data.frame` containing the fitted values. #' @srrstats {RE4.9} Returns the fitted values. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' fitted(gaussian_example_fit, n_draws = 2L) #' \donttest{ #' set.seed(1) diff --git a/R/getters.R b/R/getters.R index e3f16e88..c7a390d9 100644 --- a/R/getters.R +++ b/R/getters.R @@ -18,6 +18,7 @@ #' @return A `data.frame` containing the prior definitions. #' @srrstats {BS5.2} Provides access to the prior definitions of the model. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) #' get_priors(obs(y ~ x, family = "gaussian"), #' data = d, time = "time", group = "id" @@ -60,6 +61,7 @@ get_priors.dynamitefit <- function(x, ...) { #' extracts the full model code. #' @return The Stan model blocks as a `character` string. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) #' cat(get_code(obs(y ~ x, family = "gaussian"), #' data = d, time = "time", group = "id" @@ -164,6 +166,7 @@ get_code_ <- function(x, blocks = NULL) { #' @inheritParams get_priors.dynamiteformula #' @return A `list` containing the input data to Stan. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) #' str(get_data(obs(y ~ x, family = "gaussian"), #' data = d, time = "time", group = "id" @@ -218,6 +221,7 @@ get_data.dynamitefit <- function(x, ...) { #' @export #' @family output #' @examples +#' data.table::setDTthreads(1) # For CRAN #' get_parameter_dims(multichannel_example_fit) #' get_parameter_dims <- function(x, ...) { @@ -305,6 +309,7 @@ get_parameters <- function(x) { #' @export #' @family output #' @examples +#' data.table::setDTthreads(1) # For CRAN #' get_parameter_types(multichannel_example_fit) #' get_parameter_types <- function(x, ...) { @@ -343,6 +348,7 @@ get_parameter_types.dynamitefit <- function(x, ...) { #' @export #' @family output #' @examples +#' data.table::setDTthreads(1) # For CRAN #' get_parameter_names(multichannel_example_fit) #' get_parameter_names <- function(x, types = NULL, ...) { diff --git a/R/lags.R b/R/lags.R index c1f7a3de..569c91f5 100644 --- a/R/lags.R +++ b/R/lags.R @@ -16,6 +16,7 @@ #' @return An object of class `lags`. #' @srrstats {G2.3a} Uses match.arg #' @examples +#' data.table::setDTthreads(1) # For CRAN #' obs(y ~ -1 + varying(~x), family = "gaussian") + #' lags(type = "varying") + splines(df = 20) #' diff --git a/R/latent_factor.R b/R/latent_factor.R index 768d0974..1cb13c46 100644 --- a/R/latent_factor.R +++ b/R/latent_factor.R @@ -27,6 +27,7 @@ #' The number of knots is based `splines()` call. #' @return An object of class `latent_factor`. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' # three channel model with common factor affecting for responses x and y #' obs(y ~ 1, family = "gaussian") + #' obs(x ~ 1, family = "poisson") + diff --git a/R/lfo.R b/R/lfo.R index 0991c735..8ca17ced 100644 --- a/R/lfo.R +++ b/R/lfo.R @@ -36,6 +36,7 @@ #' Approximate leave-future-out cross-validation for Bayesian time series #' models, Journal of Statistical Computation and Simulation, 90:14, 2499-2523. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \donttest{ #' # Please update your rstan and StanHeaders installation before running #' # on Windows @@ -259,6 +260,7 @@ lfo <- function(x, L, verbose = TRUE, k_threshold = 0.7, ...) { #' @return Returns `x` invisibly. #' @export #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \donttest{ #' # Please update your rstan and StanHeaders installation before running #' # on Windows @@ -291,6 +293,7 @@ print.lfo <- function(x, ...) { #' @return A ggplot object. #' @export #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \donttest{ #' # Please update your rstan and StanHeaders installation before running #' # on Windows diff --git a/R/loo.R b/R/loo.R index 1e9ccdf9..db81dd98 100644 --- a/R/loo.R +++ b/R/loo.R @@ -19,6 +19,7 @@ #' Practical Bayesian model evaluation using leave-one-out cross-validation and #' WAIC. Statistics and Computing. 27(5), 1413–1432. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \donttest{ #' # Please update your rstan and StanHeaders installation before running #' # on Windows diff --git a/R/mcmc_diagnostics.R b/R/mcmc_diagnostics.R index e094de3e..8f86be31 100644 --- a/R/mcmc_diagnostics.R +++ b/R/mcmc_diagnostics.R @@ -12,6 +12,7 @@ #' positive (unrestricted) integer. #' @return Returns `x` (invisibly). #' @examples +#' data.table::setDTthreads(1) # For CRAN #' mcmc_diagnostics(gaussian_example_fit) #' mcmc_diagnostics <- function(x, n) { diff --git a/R/ndraws.R b/R/ndraws.R index 828a9ccb..ede07e7f 100644 --- a/R/ndraws.R +++ b/R/ndraws.R @@ -7,6 +7,7 @@ #' @param x \[`dynamitefit`]\cr The model fit object. #' @return Number of posterior draws as a single `integer` value. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' ndraws(gaussian_example_fit) #' ndraws.dynamitefit <- function(x) { diff --git a/R/nobs.R b/R/nobs.R index 626d1e40..fadf25e1 100644 --- a/R/nobs.R +++ b/R/nobs.R @@ -7,6 +7,7 @@ #' @return Total number of non-missing observations as an `integer`. #' @srrstats {RE4.5} Provides the number of observations. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' nobs(gaussian_example_fit) #' nobs.dynamitefit <- function(object, ...) { diff --git a/R/plot.R b/R/plot.R index 687a585d..d6a70a8f 100644 --- a/R/plot.R +++ b/R/plot.R @@ -22,6 +22,7 @@ #' method. Further plots can be easily constructed with the help of `as_draws` #' combined with `ggplot2`, for example. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' plot(gaussian_example_fit, type = "beta") #' plot.dynamitefit <- function(x, parameters = NULL, type = NULL, @@ -97,6 +98,7 @@ plot.dynamitefit <- function(x, parameters = NULL, type = NULL, #' @srrstats {G2.3a} Uses match.arg. #' @srrstats {BS6.1, RE6.0, RE6.1, BS6.3} Implements the `plot` method. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' plot_deltas(gaussian_example_fit, level = 0.025, scales = "free") + #' ggplot2::theme_minimal() #' @@ -210,6 +212,7 @@ plot_deltas <- function(x, parameters = NULL, responses = NULL, level = 0.05, #' @return A `ggplot` object. #' @srrstats {BS6.1, RE6.0, RE6.1, BS6.3} Implements the `plot` method. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' plot_betas(gaussian_example_fit, level = 0.1) #' plot_betas <- function(x, parameters = NULL, responses = NULL, level = 0.05, @@ -301,6 +304,7 @@ plot_betas <- function(x, parameters = NULL, responses = NULL, level = 0.05, #' @return A `ggplot` object. #' @srrstats {BS6.1, RE6.0, RE6.1, BS6.3} Implements the `plot` method. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' plot_nus(gaussian_example_fit) #' plot_nus <- function(x, parameters = NULL, responses = NULL, level = 0.05, diff --git a/R/predict.R b/R/predict.R index 66aa81c9..10dce09e 100644 --- a/R/predict.R +++ b/R/predict.R @@ -92,6 +92,7 @@ #' @srrstats {RE4.16} New group levels are supported via #' `new_levels` parameter. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' out <- predict(gaussian_example_fit, type = "response", n_draws = 2L) #' head(out) #' diff --git a/R/print.R b/R/print.R index db34a8c1..4e754859 100644 --- a/R/print.R +++ b/R/print.R @@ -11,6 +11,7 @@ #' @srrstats {BS6.0, RE4.17} Implements the `print` method for the model fit. #' @srrstats {BS5.3, BS5.5} Contains convergence statistics in the output. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' print(gaussian_example_fit) #' print.dynamitefit <- function(x, ...) { diff --git a/R/random.R b/R/random.R index 49ff3b59..986eb4ed 100644 --- a/R/random.R +++ b/R/random.R @@ -21,6 +21,7 @@ #' you encounter divergences or other problems in sampling. #' @return An object of class `random_spec`. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' # two channel model with correlated random effects for responses x and y #' obs(y ~ 1 + random(~1), family = "gaussian") + #' obs(x ~ 1 + random(~1 + z), family = "poisson") + diff --git a/R/splines.R b/R/splines.R index f82e1637..c6c54bfd 100644 --- a/R/splines.R +++ b/R/splines.R @@ -32,6 +32,7 @@ #' `splines()`. If `TRUE`, any existing definitions will be replaced. #' @return An object of class `splines`. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' # Two channel model with varying effects, with explicit lower bounds for the #' # random walk prior standard deviations, with noncentered parameterization #' # for the first channel and centered for the second channel. diff --git a/R/summary.R b/R/summary.R index f4c9f6e1..b531741d 100644 --- a/R/summary.R +++ b/R/summary.R @@ -11,6 +11,7 @@ #' @return `summary` returns a `data.frame`. #' @srrstats {BS6.4, RE4.18} Implements `summary` method. #' @examples +#' data.table::setDTthreads(1) # For CRAN #' summary(gaussian_example_fit, #' types = "beta", #' probs = c(0.05, 0.1, 0.9, 0.95) diff --git a/R/update.R b/R/update.R index 3dddebb2..5c6dff3e 100644 --- a/R/update.R +++ b/R/update.R @@ -23,6 +23,7 @@ #' @export #' @family fitting #' @examples +#' data.table::setDTthreads(1) # For CRAN #' \dontrun{ #' # re-estimate the example fit without thinning: #' # As the model is compiled on Windows, this will fail on other platforms diff --git a/man/as.data.frame.dynamitefit.Rd b/man/as.data.frame.dynamitefit.Rd index 8685fa3d..d314fa9e 100644 --- a/man/as.data.frame.dynamitefit.Rd +++ b/man/as.data.frame.dynamitefit.Rd @@ -105,6 +105,7 @@ Samples of the full correlation matrix can be extracted manually as } } \examples{ +data.table::setDTthreads(1) # For CRAN as.data.frame( gaussian_example_fit, responses = "y", diff --git a/man/as.data.table.dynamitefit.Rd b/man/as.data.table.dynamitefit.Rd index 7a763754..31d4d2fd 100644 --- a/man/as.data.table.dynamitefit.Rd +++ b/man/as.data.table.dynamitefit.Rd @@ -68,6 +68,7 @@ Provides a \code{data.table} representation of the posterior samples of the mode parameters. See \code{\link[=as.data.frame.dynamitefit]{as.data.frame.dynamitefit()}} for details. } \examples{ +data.table::setDTthreads(1) # For CRAN as.data.table( gaussian_example_fit, responses = "y", diff --git a/man/as_draws-dynamitefit.Rd b/man/as_draws-dynamitefit.Rd index 2f5d7f71..1fb65f7c 100644 --- a/man/as_draws-dynamitefit.Rd +++ b/man/as_draws-dynamitefit.Rd @@ -55,6 +55,7 @@ See potential values for the types argument in argument. } \examples{ +data.table::setDTthreads(1) # For CRAN as_draws(gaussian_example_fit, types = c("sigma", "beta")) # Compute MCMC diagnostics using the posterior package diff --git a/man/coef.dynamitefit.Rd b/man/coef.dynamitefit.Rd index 84e1d8ce..7e77e7d2 100644 --- a/man/coef.dynamitefit.Rd +++ b/man/coef.dynamitefit.Rd @@ -60,6 +60,7 @@ model parameters in a long format. Extracts either time-varying or time-invariant parameters of the model. } \examples{ +data.table::setDTthreads(1) # For CRAN betas <- coef(gaussian_example_fit, type = "beta") deltas <- coef(gaussian_example_fit, type = "delta") diff --git a/man/confint.dynamitefit.Rd b/man/confint.dynamitefit.Rd index b6dfc542..1b04948a 100644 --- a/man/confint.dynamitefit.Rd +++ b/man/confint.dynamitefit.Rd @@ -29,6 +29,7 @@ to \code{NA}. Extracts credible intervals from \code{dynamitefit} object. } \examples{ +data.table::setDTthreads(1) # For CRAN confint(gaussian_example_fit, level = 0.9) } diff --git a/man/dynamite.Rd b/man/dynamite.Rd index 365ab6e2..a728ed78 100644 --- a/man/dynamite.Rd +++ b/man/dynamite.Rd @@ -156,6 +156,7 @@ depend on the discrepancy of the data and the model (and the subsequent shape of the posterior), this can vary greatly. } \examples{ +data.table::setDTthreads(1) # For CRAN \donttest{ # Please update your rstan and StanHeaders installation before running # on Windows @@ -173,10 +174,13 @@ if (!identical(.Platform$OS.type, "windows")) { } } +data.table::setDTthreads(1) # For CRAN formula(gaussian_example_fit) +data.table::setDTthreads(1) # For CRAN print(gaussian_example_fit) +data.table::setDTthreads(1) # For CRAN summary(gaussian_example_fit, types = "beta", probs = c(0.05, 0.1, 0.9, 0.95) diff --git a/man/dynamiteformula.Rd b/man/dynamiteformula.Rd index f52f739e..f326f228 100644 --- a/man/dynamiteformula.Rd +++ b/man/dynamiteformula.Rd @@ -150,6 +150,7 @@ channels and whether to use centered or noncentered parameterization for the random effects. } \examples{ +data.table::setDTthreads(1) # For CRAN # A single gaussian response channel with a time-varying effect of 'x', # and a time-varying effect of the lag of 'y' using B-splines with # 20 degrees of freedom for the coefficients of the time-varying terms. @@ -175,8 +176,10 @@ obs(g ~ lag(g) + lag(logp), family = "gaussian") + obs(b ~ lag(b) * lag(logp) + lag(b) * lag(g), family = "bernoulli") + aux(numeric(logp) ~ log(p + 1)) +data.table::setDTthreads(1) # For CRAN obs(y ~ x, family = "gaussian") + obs(z ~ w, family = "exponential") +data.table::setDTthreads(1) # For CRAN x <- obs(y ~ x + random(~ 1 + lag(d)), family = "gaussian") + obs(z ~ varying(~w), family = "exponential") + aux(numeric(d) ~ log(y) | init(c(0, 1))) + diff --git a/man/fitted.dynamitefit.Rd b/man/fitted.dynamitefit.Rd index 0febdb6d..6c19a1b2 100644 --- a/man/fitted.dynamitefit.Rd +++ b/man/fitted.dynamitefit.Rd @@ -42,6 +42,7 @@ model parameters. See also \code{\link[=predict.dynamitefit]{predict.dynamitefit()}} for multi-step predictions. } \examples{ +data.table::setDTthreads(1) # For CRAN fitted(gaussian_example_fit, n_draws = 2L) \donttest{ set.seed(1) diff --git a/man/get_code.Rd b/man/get_code.Rd index afc5d907..dfe46ad2 100644 --- a/man/get_code.Rd +++ b/man/get_code.Rd @@ -50,6 +50,7 @@ Returns the Stan code of the model. Mostly useful for debugging or for building a customized version of the model. } \examples{ +data.table::setDTthreads(1) # For CRAN d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) cat(get_code(obs(y ~ x, family = "gaussian"), data = d, time = "time", group = "id" diff --git a/man/get_data.Rd b/man/get_data.Rd index 61eff15f..de8c7bf3 100644 --- a/man/get_data.Rd +++ b/man/get_data.Rd @@ -46,6 +46,7 @@ A \code{list} containing the input data to Stan. Returns the input data to the Stan model. Mostly useful for debugging. } \examples{ +data.table::setDTthreads(1) # For CRAN d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) str(get_data(obs(y ~ x, family = "gaussian"), data = d, time = "time", group = "id" diff --git a/man/get_parameter_dims.Rd b/man/get_parameter_dims.Rd index 348c325f..82443f19 100644 --- a/man/get_parameter_dims.Rd +++ b/man/get_parameter_dims.Rd @@ -51,6 +51,7 @@ the \code{stanfit} element of the \code{dynamitefit} object. When applied to to get the parameter dimensions. } \examples{ +data.table::setDTthreads(1) # For CRAN get_parameter_dims(multichannel_example_fit) } diff --git a/man/get_parameter_names.Rd b/man/get_parameter_names.Rd index 358133ee..35d3a0c8 100644 --- a/man/get_parameter_names.Rd +++ b/man/get_parameter_names.Rd @@ -32,6 +32,7 @@ exception to this is spline coefficients omega, which also contain the number denoting the knot number. } \examples{ +data.table::setDTthreads(1) # For CRAN get_parameter_names(multichannel_example_fit) } diff --git a/man/get_parameter_types.Rd b/man/get_parameter_types.Rd index aeff167b..4e897013 100644 --- a/man/get_parameter_types.Rd +++ b/man/get_parameter_types.Rd @@ -22,6 +22,7 @@ Extracts all parameter types of used in the \code{dynamitefit} object. See \code{\link[=as.data.frame.dynamitefit]{as.data.frame.dynamitefit()}} for explanations of different types. } \examples{ +data.table::setDTthreads(1) # For CRAN get_parameter_types(multichannel_example_fit) } diff --git a/man/get_priors.Rd b/man/get_priors.Rd index 97604c1c..3bb973ac 100644 --- a/man/get_priors.Rd +++ b/man/get_priors.Rd @@ -53,6 +53,7 @@ Only the \code{prior} column of the output should be altered when defining the user-defined priors for the \code{dynamite}. } \examples{ +data.table::setDTthreads(1) # For CRAN d <- data.frame(y = rnorm(10), x = 1:10, time = 1:10, id = 1) get_priors(obs(y ~ x, family = "gaussian"), data = d, time = "time", group = "id" diff --git a/man/lags.Rd b/man/lags.Rd index 617e98c4..65ca9632 100644 --- a/man/lags.Rd +++ b/man/lags.Rd @@ -25,6 +25,7 @@ Adds the lagged value of the response of each channel specified via can be either time-varying or time-invariant. } \examples{ +data.table::setDTthreads(1) # For CRAN obs(y ~ -1 + varying(~x), family = "gaussian") + lags(type = "varying") + splines(df = 20) diff --git a/man/lfactor.Rd b/man/lfactor.Rd index 844129e0..d3e58878 100644 --- a/man/lfactor.Rd +++ b/man/lfactor.Rd @@ -44,6 +44,7 @@ restrictions are added to the model. Details will be available in an upcoming paper. This component should be treated as experimental feature. } \examples{ +data.table::setDTthreads(1) # For CRAN # three channel model with common factor affecting for responses x and y obs(y ~ 1, family = "gaussian") + obs(x ~ 1, family = "poisson") + diff --git a/man/lfo.Rd b/man/lfo.Rd index f673bac2..567b4680 100644 --- a/man/lfo.Rd +++ b/man/lfo.Rd @@ -45,6 +45,7 @@ computed independently for each group, but the re-estimation of the model is triggered if pareto k values of any group exceeds the threshold. } \examples{ +data.table::setDTthreads(1) # For CRAN \donttest{ # Please update your rstan and StanHeaders installation before running # on Windows diff --git a/man/loo.dynamitefit.Rd b/man/loo.dynamitefit.Rd index 6ce96a44..1eb45979 100644 --- a/man/loo.dynamitefit.Rd +++ b/man/loo.dynamitefit.Rd @@ -26,6 +26,7 @@ Estimates the leave-one-out (LOO) information criterion for \code{dynamite} models using Pareto smoothed importance sampling with the \code{loo} package. } \examples{ +data.table::setDTthreads(1) # For CRAN \donttest{ # Please update your rstan and StanHeaders installation before running # on Windows diff --git a/man/mcmc_diagnostics.Rd b/man/mcmc_diagnostics.Rd index baaf50fc..6a14e711 100644 --- a/man/mcmc_diagnostics.Rd +++ b/man/mcmc_diagnostics.Rd @@ -25,6 +25,7 @@ sizes and largest Rhat values. See \code{\link[rstan:check_hmc_diagnostics]{rsta \code{\link[posterior:draws_summary]{posterior::default_convergence_measures()}} for details. } \examples{ +data.table::setDTthreads(1) # For CRAN mcmc_diagnostics(gaussian_example_fit) } diff --git a/man/ndraws.dynamitefit.Rd b/man/ndraws.dynamitefit.Rd index 5a8f2d77..a30e656d 100644 --- a/man/ndraws.dynamitefit.Rd +++ b/man/ndraws.dynamitefit.Rd @@ -17,6 +17,7 @@ Number of posterior draws as a single \code{integer} value. Return the Number of Posterior Draws of a \code{dynamitefit} Object } \examples{ +data.table::setDTthreads(1) # For CRAN ndraws(gaussian_example_fit) } diff --git a/man/nobs.dynamitefit.Rd b/man/nobs.dynamitefit.Rd index 242be845..fabd5eba 100644 --- a/man/nobs.dynamitefit.Rd +++ b/man/nobs.dynamitefit.Rd @@ -18,6 +18,7 @@ Total number of non-missing observations as an \code{integer}. Extract the Number of Observations Used to Fit a Dynamite Model } \examples{ +data.table::setDTthreads(1) # For CRAN nobs(gaussian_example_fit) } diff --git a/man/plot.dynamitefit.Rd b/man/plot.dynamitefit.Rd index 1e041ec7..3314f2dd 100644 --- a/man/plot.dynamitefit.Rd +++ b/man/plot.dynamitefit.Rd @@ -32,6 +32,7 @@ A \code{ggplot} object. Produces the traceplots and the density plots of the model parameters. } \examples{ +data.table::setDTthreads(1) # For CRAN plot(gaussian_example_fit, type = "beta") } diff --git a/man/plot.lfo.Rd b/man/plot.lfo.Rd index a6550e75..34bc6d42 100644 --- a/man/plot.lfo.Rd +++ b/man/plot.lfo.Rd @@ -19,6 +19,7 @@ Plots Pareto k values per each time point (with one point per group), together with a horizontal line representing the used threshold. } \examples{ +data.table::setDTthreads(1) # For CRAN \donttest{ # Please update your rstan and StanHeaders installation before running # on Windows diff --git a/man/plot_betas.Rd b/man/plot_betas.Rd index 0bb8e662..96da0224 100644 --- a/man/plot_betas.Rd +++ b/man/plot_betas.Rd @@ -36,6 +36,7 @@ A \code{ggplot} object. Plot Time-invariant Regression Coefficients of a Dynamite Model } \examples{ +data.table::setDTthreads(1) # For CRAN plot_betas(gaussian_example_fit, level = 0.1) } diff --git a/man/plot_deltas.Rd b/man/plot_deltas.Rd index c82cb764..b492b04f 100644 --- a/man/plot_deltas.Rd +++ b/man/plot_deltas.Rd @@ -44,6 +44,7 @@ A \code{ggplot} object. Plot Time-varying Regression Coefficients of a Dynamite Model } \examples{ +data.table::setDTthreads(1) # For CRAN plot_deltas(gaussian_example_fit, level = 0.025, scales = "free") + ggplot2::theme_minimal() diff --git a/man/plot_nus.Rd b/man/plot_nus.Rd index d7e1db6d..bde556cd 100644 --- a/man/plot_nus.Rd +++ b/man/plot_nus.Rd @@ -31,6 +31,7 @@ Note that as this function tries to draw a plot containing effects of all groups, the plot will become messy with large number of groups. } \examples{ +data.table::setDTthreads(1) # For CRAN plot_nus(gaussian_example_fit) } diff --git a/man/predict.dynamitefit.Rd b/man/predict.dynamitefit.Rd index 60cf03d1..03d5e765 100644 --- a/man/predict.dynamitefit.Rd +++ b/man/predict.dynamitefit.Rd @@ -117,6 +117,7 @@ package. However, such predictions can be obtained by augmenting the original data with \code{NA} values before model estimation. } \examples{ +data.table::setDTthreads(1) # For CRAN out <- predict(gaussian_example_fit, type = "response", n_draws = 2L) head(out) diff --git a/man/print.lfo.Rd b/man/print.lfo.Rd index 929672fd..2c69d615 100644 --- a/man/print.lfo.Rd +++ b/man/print.lfo.Rd @@ -18,6 +18,7 @@ Returns \code{x} invisibly. Prints the summary of the leave-future-out cross-validation. } \examples{ +data.table::setDTthreads(1) # For CRAN \donttest{ # Please update your rstan and StanHeaders installation before running # on Windows diff --git a/man/random_spec.Rd b/man/random_spec.Rd index 5183f847..68526c20 100644 --- a/man/random_spec.Rd +++ b/man/random_spec.Rd @@ -32,6 +32,7 @@ large variation in the intercepts (large sigma_nu) compared to the sampling variation (sigma) in the Gaussian case. } \examples{ +data.table::setDTthreads(1) # For CRAN # two channel model with correlated random effects for responses x and y obs(y ~ 1 + random(~1), family = "gaussian") + obs(x ~ 1 + random(~1 + z), family = "poisson") + diff --git a/man/splines.Rd b/man/splines.Rd index 1bf8a084..27356e86 100644 --- a/man/splines.Rd +++ b/man/splines.Rd @@ -51,6 +51,7 @@ This function can be used as part of \code{\link[=dynamiteformula]{dynamiteformu splines used for the time-varying coefficients \eqn{\delta}. } \examples{ +data.table::setDTthreads(1) # For CRAN # Two channel model with varying effects, with explicit lower bounds for the # random walk prior standard deviations, with noncentered parameterization # for the first channel and centered for the second channel. diff --git a/man/update.dynamitefit.Rd b/man/update.dynamitefit.Rd index 7177be58..352a7467 100644 --- a/man/update.dynamitefit.Rd +++ b/man/update.dynamitefit.Rd @@ -43,6 +43,7 @@ updating can lead to an error due to different naming in \code{cmdstanr} and \code{rstan} sampling arguments. } \examples{ +data.table::setDTthreads(1) # For CRAN \dontrun{ # re-estimate the example fit without thinning: # As the model is compiled on Windows, this will fail on other platforms diff --git a/tests/testthat/test-cmdstanr.R b/tests/testthat/test-cmdstanr.R index 0f570ec2..d257eba6 100644 --- a/tests/testthat/test-cmdstanr.R +++ b/tests/testthat/test-cmdstanr.R @@ -3,6 +3,8 @@ run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("stanc_options argument works", { skip_if_not(run_extended_tests) set.seed(1) diff --git a/tests/testthat/test-edgecases.R b/tests/testthat/test-edgecases.R index 6f23b2e1..3bfce7c5 100644 --- a/tests/testthat/test-edgecases.R +++ b/tests/testthat/test-edgecases.R @@ -1,5 +1,7 @@ #' @srrstats {G5.8,G5.8a, G5.8b, G5.8c, G5.8d} Edge conditions are tested. +data.table::setDTthreads(1) # For CRAN + # Model edgecases --------------------------------------------------------- set.seed(0) diff --git a/tests/testthat/test-errors.R b/tests/testthat/test-errors.R index 2379aa35..6b56adae 100644 --- a/tests/testthat/test-errors.R +++ b/tests/testthat/test-errors.R @@ -1,3 +1,5 @@ +data.table::setDTthreads(1) # For CRAN + obs_test <- obs(y ~ x + w, family = "gaussian") set.seed(0) diff --git a/tests/testthat/test-extended.R b/tests/testthat/test-extended.R index ebc28b86..984b43ab 100644 --- a/tests/testthat/test-extended.R +++ b/tests/testthat/test-extended.R @@ -1,5 +1,7 @@ run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("multivariate gaussian fit and predict work", { skip_if_not(run_extended_tests) diff --git a/tests/testthat/test-grunfeld.R b/tests/testthat/test-grunfeld.R index e68413a6..b6409486 100644 --- a/tests/testthat/test-grunfeld.R +++ b/tests/testthat/test-grunfeld.R @@ -2,6 +2,8 @@ #' model fitted to a classic Grunfeld data match with brms and plm. run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("parameters of the Grunfield model are recovered", { skip_if_not(run_extended_tests) diff --git a/tests/testthat/test-internals.R b/tests/testthat/test-internals.R index 555dee1c..c3a506cd 100644 --- a/tests/testthat/test-internals.R +++ b/tests/testthat/test-internals.R @@ -1,3 +1,5 @@ +data.table::setDTthreads(1) # For CRAN + test_that("formula model topology is correct", { f1 <- obs(c(y1, y2) ~ 1 | x, family = "mvgaussian") + obs(x ~ 1 + z, family = "gaussian") diff --git a/tests/testthat/test-lfactor.R b/tests/testthat/test-lfactor.R index 81d428b0..6c9379e6 100644 --- a/tests/testthat/test-lfactor.R +++ b/tests/testthat/test-lfactor.R @@ -3,6 +3,8 @@ run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + set.seed(1) T_ <- 20 N <- 50 diff --git a/tests/testthat/test-output.R b/tests/testthat/test-output.R index 43bc9890..f48f9cc2 100644 --- a/tests/testthat/test-output.R +++ b/tests/testthat/test-output.R @@ -1,3 +1,5 @@ +data.table::setDTthreads(1) # For CRAN + # Capture both message and output types capture_all_output <- function(x) { utils::capture.output( diff --git a/tests/testthat/test-predict.R b/tests/testthat/test-predict.R index c11d89ba..99d6d2dd 100644 --- a/tests/testthat/test-predict.R +++ b/tests/testthat/test-predict.R @@ -2,7 +2,8 @@ #' same scale. #' @srrstats {G5.4} Predict and fitted method produce results identical with #' "manual" computation based on the same posterior samples. -#' + +data.table::setDTthreads(1) # For CRAN test_that("predictions are on the same scale as input data", { expect_error( diff --git a/tests/testthat/test-priors.R b/tests/testthat/test-priors.R index 2a9f4720..a3dcde49 100644 --- a/tests/testthat/test-priors.R +++ b/tests/testthat/test-priors.R @@ -1,3 +1,5 @@ +data.table::setDTthreads(1) # For CRAN + test_that("priors can be extracted", { expect_error( get_priors(gaussian_example_fit), diff --git a/tests/testthat/test-random.R b/tests/testthat/test-random.R index bcb497ea..a74832d3 100644 --- a/tests/testthat/test-random.R +++ b/tests/testthat/test-random.R @@ -3,6 +3,8 @@ run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("multiple random effects work in fit and predict", { skip_if_not(run_extended_tests) diff --git a/tests/testthat/test-recovery.R b/tests/testthat/test-recovery.R index 7f66ea30..1166cd75 100644 --- a/tests/testthat/test-recovery.R +++ b/tests/testthat/test-recovery.R @@ -10,6 +10,8 @@ #' process are recovered when increasing the data size. run_extended_tests <- identical(Sys.getenv("DYNAMITE_EXTENDED_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("parameters for the linear regression are recovered as with lm", { skip_if_not(run_extended_tests) set.seed(1) diff --git a/tests/testthat/test-scaling.R b/tests/testthat/test-scaling.R index 0e80dc1c..720f218a 100644 --- a/tests/testthat/test-scaling.R +++ b/tests/testthat/test-scaling.R @@ -11,6 +11,8 @@ #' run_scaling_tests <- identical(Sys.getenv("DYNAMITE_SCALING_TESTS"), "true") +data.table::setDTthreads(1) # For CRAN + test_that("scaling for gaussian model is linear in number of time points", { skip_if_not(run_scaling_tests) set.seed(1) diff --git a/tests/testthat/test-warnings.R b/tests/testthat/test-warnings.R index 5d329996..faaea695 100644 --- a/tests/testthat/test-warnings.R +++ b/tests/testthat/test-warnings.R @@ -1,3 +1,5 @@ +data.table::setDTthreads(1) # For CRAN + # Data warnings ----------------------------------------------------------- test_that("factor time conversion warns", { diff --git a/vignettes/dynamite.Rmd b/vignettes/dynamite.Rmd index dce93a5d..d35685e6 100644 --- a/vignettes/dynamite.Rmd +++ b/vignettes/dynamite.Rmd @@ -33,6 +33,7 @@ options(dplyr.summarise.inform = FALSE) options(crayon.enabled = FALSE) options(dplyr.summarise.inform = FALSE) set.seed(0) +data.table::setDTthreads(1) # For CRAN ``` This vignette is a modification of [@dynamite] which contains more examples and details. diff --git a/vignettes/dynamite_priors.Rmd b/vignettes/dynamite_priors.Rmd index b0630b4c..43a32034 100644 --- a/vignettes/dynamite_priors.Rmd +++ b/vignettes/dynamite_priors.Rmd @@ -33,6 +33,7 @@ options(dplyr.summarise.inform = FALSE) options(crayon.enabled = FALSE) options(dplyr.summarise.inform = FALSE) set.seed(0) +data.table::setDTthreads(1) # For CRAN ``` # Default prior distributions in dynamite diff --git a/vignettes/dynamite_simulation.Rmd b/vignettes/dynamite_simulation.Rmd index 3e7926a3..5dcf2d6a 100644 --- a/vignettes/dynamite_simulation.Rmd +++ b/vignettes/dynamite_simulation.Rmd @@ -20,6 +20,7 @@ knitr::opts_chunk$set( ) library("dynamite") suppressPackageStartupMessages(library("ggplot2")) +data.table::setDTthreads(1) # For CRAN ``` # Using dynamite to generate panel data