From ef913d868619a836004e89756d9e510a4b022b5b Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 2 Jul 2024 09:07:01 +1000 Subject: [PATCH] allow trend intercept if trend_map supplied --- R/mvgam.R | 4 +++- R/stan_utils.R | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/mvgam.R b/R/mvgam.R index be899f9f..7cf62b29 100644 --- a/R/mvgam.R +++ b/R/mvgam.R @@ -1427,7 +1427,9 @@ mvgam = function(formula, # Add modifications for trend mapping and trend predictors, if # supplied trend_sp_names <- NA + if(add_nmix) drop_trend_int <- FALSE else drop_trend_int <- TRUE if(!missing(trend_map)){ + drop_trend_int <- FALSE trend_map_setup <- trend_map_mods(model_file = vectorised$model_file, model_data = vectorised$model_data, trend_map = trend_map, @@ -1460,7 +1462,7 @@ mvgam = function(formula, }, model_file = vectorised$model_file, model_data = vectorised$model_data, - nmix = add_nmix, + drop_trend_int = drop_trend_int, drift = drift) vectorised$model_file <- trend_pred_setup$model_file diff --git a/R/stan_utils.R b/R/stan_utils.R index efb9d030..b57c2ea0 100644 --- a/R/stan_utils.R +++ b/R/stan_utils.R @@ -2441,7 +2441,7 @@ add_trend_predictors = function(trend_formula, data_test, model_file, model_data, - nmix = FALSE, + drop_trend_int = TRUE, drift = FALSE){ #### Creating the trend mvgam model file and data structures #### @@ -2457,8 +2457,8 @@ add_trend_predictors = function(trend_formula, } # Drop any intercept from the formula if this is not an N-mixture model - # as the intercept will almost surely be unidentifiable - if(!nmix){ + # or a trend_map was supplied, as the intercept will almost surely be unidentifiable + if(drop_trend_int){ if(attr(terms(trend_formula), 'intercept') == 1){ trend_formula <- update(trend_formula, trend_y ~ . -1) } else {