Skip to content

Commit 1d657a9

Browse files
fix bugs in trend_map with VAR1 models
1 parent e719335 commit 1d657a9

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

R/mvgam.R

+5
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ mvgam = function(formula,
712712
drift <- FALSE
713713
}
714714

715+
if(use_lv & trend_model == 'VAR1' & missing(trend_map)){
716+
stop('Cannot identify dynamic factor models that evolve as VAR processes',
717+
call. = FALSE)
718+
}
719+
715720
# JAGS cannot support latent GP or VAR trends
716721
if(!use_stan & trend_model %in% c('GP', 'VAR1')){
717722
stop('gaussian process and VAR trends not supported for JAGS',

R/predict.mvgam.R

+11-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ predict.mvgam = function(object, newdata,
7676
}
7777

7878
if(object$trend_model %in% c('VAR1')){
79-
family_pars <- list(sigma_obs =
80-
mcmc_chains(object$model_output, 'Sigma')[ ,
81-
seq(1, NCOL(object$ytimes)^2,
82-
by = NCOL(object$ytimes)+1)])
79+
if(object$use_lv){
80+
family_pars <- list(sigma_obs =
81+
mcmc_chains(object$model_output, 'Sigma')[ ,
82+
seq(1, object$n_lv^2,
83+
by = object$n_lv+1)])
84+
} else {
85+
family_pars <- list(sigma_obs =
86+
mcmc_chains(object$model_output, 'Sigma')[ ,
87+
seq(1, NCOL(object$ytimes)^2,
88+
by = NCOL(object$ytimes)+1)])
89+
}
8390
}
8491

8592
# Indicators of which trend to use for each observation

R/stan_utils.R

+8
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,14 @@ if(trend_model != 'VAR1'){
23202320
model_file, fixed = TRUE)] <-
23212321
"matrix[n_lv, n_lv] A;"
23222322

2323+
model_file[grep("vector[n_series] mu[n - 1];",
2324+
model_file, fixed = TRUE)] <-
2325+
"vector[n_lv] mu[n];"
2326+
2327+
model_file[grep("array[n] vector[n_series] mu;",
2328+
model_file, fixed = TRUE)] <-
2329+
"array[n] vector[n_lv] mu;"
2330+
23232331
model_file[grep("matrix[n_series, n_series] Sigma;",
23242332
model_file, fixed = TRUE)] <-
23252333
"matrix[n_lv, n_lv] Sigma;"

src/mvgam.dll

0 Bytes
Binary file not shown.

tests/testthat/Rplots.pdf

-6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)