From c9383a74e2519934c432046bd05d9eda8fb76d62 Mon Sep 17 00:00:00 2001 From: Frank Blaauw Date: Fri, 7 Sep 2018 16:01:05 +0200 Subject: [PATCH 1/2] Update evaluate_model.r Vars + IRF does some weird loading of global state. What happens is that it tries to load the `lag` variable from global state which is not defined, but the `lag` function is. Hence it loads that one and everything crashes. Now we actually look for the `p` variable which should be stored globally. This is probably a bug in vars. --- R/evaluate_model.r | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/evaluate_model.r b/R/evaluate_model.r index 4b66103..86d4280 100644 --- a/R/evaluate_model.r +++ b/R/evaluate_model.r @@ -239,15 +239,15 @@ run_var <- function(data,lag,simple_models,...) { m } -estimate_var_model <- function(data, lag, ...) { +estimate_var_model <- function(data, p, ...) { # This fix is performed so the call to the VAR function does not include a # ..1 whenever all of the ...'s elements are NULL. This matters when # performing IRF, as it will use the call function to perform an update of # the VAR model. if (all(unlist(lapply(list(...), function(x) is.null(x))))) { - return(vars::VAR(data, p = lag)) + return(vars::VAR(y = data, p = p)) } - return(vars::VAR(data, p = lag, ...)) + return(vars::VAR(y = data, p = p, ...)) } add_intercepts <- function(varest) { From 5087f5135d910ccd678b126270e670085edae435 Mon Sep 17 00:00:00 2001 From: Frank Blaauw Date: Mon, 10 Sep 2018 09:18:27 +0200 Subject: [PATCH 2/2] Updated evaluate model function to make it more robust in irf --- R/evaluate_model.r | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/evaluate_model.r b/R/evaluate_model.r index 86d4280..5d1e49e 100644 --- a/R/evaluate_model.r +++ b/R/evaluate_model.r @@ -247,7 +247,13 @@ estimate_var_model <- function(data, p, ...) { if (all(unlist(lapply(list(...), function(x) is.null(x))))) { return(vars::VAR(y = data, p = p)) } - return(vars::VAR(y = data, p = p, ...)) + # Note the do.call here. Instead of running + # vars::VAR(y = data, p = p, ...) + # we run this do.call in order to expand and explicitly include the ... and + # other params. This way, when we run the `update` function on the call of + # this object, we can rely on all information being available in the object + # itself (instead of relying on global env). + return(do.call(vars::VAR, c(list(y=data, p=p), list(...)))) } add_intercepts <- function(varest) {