diff --git a/R/mvgam.R b/R/mvgam.R index bd73bc07..076d0c06 100644 --- a/R/mvgam.R +++ b/R/mvgam.R @@ -683,6 +683,12 @@ mvgam = function(formula, drift = drift, noncentred = noncentred) + # Cannot yet map observations to trends that evolve as CAR1 + if(trend_model == 'CAR1' & !missing(trend_map)){ + stop('cannot yet use trend mapping for CAR1 dynamics', + call. = FALSE) + } + # Ensure series and time variables are present data_train <- validate_series_time(data_train, name = 'data', trend_model = orig_trend_model) diff --git a/R/validations.R b/R/validations.R index 50574a81..e83b17fd 100644 --- a/R/validations.R +++ b/R/validations.R @@ -666,12 +666,6 @@ validate_trendmap = function(trend_map, call. = FALSE) } - # Cannot yet map observations to trends that evolve as CAR1 - if(trend_model == 'CAR1'){ - stop('cannot yet use trend mapping for CAR1 dynamics', - call. = FALSE) - } - # trend_map must have an entry for each unique time series if(!all(sort(trend_map$series) == sort(unique(data_train$series)))){ stop('Argument "trend_map" must have an entry for every unique time series in "data"', diff --git a/tests/testthat/test-mvgam.R b/tests/testthat/test-mvgam.R index b2eb6387..c43346c0 100644 --- a/tests/testthat/test-mvgam.R +++ b/tests/testthat/test-mvgam.R @@ -401,7 +401,6 @@ test_that("prior_only works", { mod$model_file, fixed = TRUE))) expect_true(!any(grepl('flat_ys ~ ', mod$model_file, fixed = TRUE))) - mod <- mvgam(y ~ 1, trend_formula = ~ s(season) + s(trend, bs = 're'), trend_model = CAR(), @@ -416,6 +415,20 @@ test_that("prior_only works", { expect_true(!any(grepl('flat_ys ~ ', mod$model_file, fixed = TRUE))) + # trend_map not yet allowed for CAR1 dynamics + trend_map <- data.frame(series = unique(gaus_data$data_train$series), + trend = c(1, 1, 2)) + expect_error(mvgam(y ~ 1, + trend_formula = ~ s(season) + s(trend, bs = 're'), + trend_model = CAR(), + trend_map = trend_map, + data = gaus_data$data_train, + prior_simulation = TRUE, + family = gaussian(), + threads = 2, + run_model = FALSE), + 'cannot yet use trend mapping for CAR1 dynamics') + mod <- mvgam(y ~ s(season), trend_model = AR(p = 3), data = beta_data$data_train,