Skip to content

Commit

Permalink
fix bugs in trend_map with VAR1 models
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjclark committed Sep 29, 2023
1 parent e719335 commit 1d657a9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions R/mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ mvgam = function(formula,
drift <- FALSE
}

if(use_lv & trend_model == 'VAR1' & missing(trend_map)){
stop('Cannot identify dynamic factor models that evolve as VAR processes',
call. = FALSE)
}

# JAGS cannot support latent GP or VAR trends
if(!use_stan & trend_model %in% c('GP', 'VAR1')){
stop('gaussian process and VAR trends not supported for JAGS',
Expand Down
15 changes: 11 additions & 4 deletions R/predict.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ predict.mvgam = function(object, newdata,
}

if(object$trend_model %in% c('VAR1')){
family_pars <- list(sigma_obs =
mcmc_chains(object$model_output, 'Sigma')[ ,
seq(1, NCOL(object$ytimes)^2,
by = NCOL(object$ytimes)+1)])
if(object$use_lv){
family_pars <- list(sigma_obs =
mcmc_chains(object$model_output, 'Sigma')[ ,
seq(1, object$n_lv^2,
by = object$n_lv+1)])
} else {
family_pars <- list(sigma_obs =
mcmc_chains(object$model_output, 'Sigma')[ ,
seq(1, NCOL(object$ytimes)^2,
by = NCOL(object$ytimes)+1)])
}
}

# Indicators of which trend to use for each observation
Expand Down
8 changes: 8 additions & 0 deletions R/stan_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,14 @@ if(trend_model != 'VAR1'){
model_file, fixed = TRUE)] <-
"matrix[n_lv, n_lv] A;"

model_file[grep("vector[n_series] mu[n - 1];",
model_file, fixed = TRUE)] <-
"vector[n_lv] mu[n];"

model_file[grep("array[n] vector[n_series] mu;",
model_file, fixed = TRUE)] <-
"array[n] vector[n_lv] mu;"

model_file[grep("matrix[n_series, n_series] Sigma;",
model_file, fixed = TRUE)] <-
"matrix[n_lv, n_lv] Sigma;"
Expand Down
Binary file modified src/mvgam.dll
Binary file not shown.
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.

0 comments on commit 1d657a9

Please sign in to comment.