Skip to content

Commit

Permalink
earlier handling of trend_map / CAR1 error
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjclark committed Dec 3, 2024
1 parent 603e876 commit 8b057d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions R/mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions R/validations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
Expand Down
15 changes: 14 additions & 1 deletion tests/testthat/test-mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down

0 comments on commit 8b057d9

Please sign in to comment.