Skip to content

Commit

Permalink
allow trend intercept if trend_map supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjclark committed Jul 1, 2024
1 parent 5f5845b commit ef913d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion R/mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/stan_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####
Expand All @@ -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 {
Expand Down

0 comments on commit ef913d8

Please sign in to comment.