Skip to content

Commit

Permalink
Allow for country-specific submodel conversion from VAR to VEC
Browse files Browse the repository at this point in the history
  • Loading branch information
franzmohr committed Jun 24, 2023
1 parent 8ab1b79 commit dab67a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 26 additions & 2 deletions R/ctryvec_to_ctryvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#' An object of class \code{"bgvecest"} is transformed to a VAR in level representation.
#'
#' @param object an object of class \code{"bgvecest"}.
#' @param ctry character. Name of the element in argument \code{object}, for which
#' the transformation should be carried out. If \code{NULL} (default), all submodels
#' are transformed.
#'
#' @return An object of class \code{"bgvarest"}.
#'
Expand All @@ -11,18 +14,39 @@
#' Lütkepohl, H. (2006). \emph{New introduction to multiple time series analysis} (2nd ed.). Berlin: Springer.
#'
#' @export
ctryvec_to_ctryvar <- function(object) {
ctryvec_to_ctryvar <- function(object, ctry = NULL) {

if (!any(c("bgvecest", "ctryvecest") %in% class(object))) {
stop("Argument 'object' must be of class 'bgvecest' or 'ctryvecest'.")
}

if ("bgvecest" %in% class(object)) {
object <- lapply(object, .transform_ctryvec)
if (!is.null(ctry)) {
# Determine position of countries in object
pos <- which(names(object) %in% ctry)
if (length(pos) == 0) {
stop("Specified countries not available.")
}
# Perform transformations for selected submodels
result <- NULL
for (i in pos) {
temp <- .transform_ctryvec(object[[i]])
result <- c(result, list(temp))
rm(temp)
}
names(result) <- names(object)[pos]
object <- result
rm(result)
} else {
object <- lapply(object, .transform_ctryvec)
}
class(object) <- c("bgvarest", "list")
}

if ("ctryvecest" %in% class(object)) {
if (!is.null(ctry)) {
warning("Only one model provided. Argument 'ctry' will be ignored.")
}
object <- .transform_ctryvec(object)
class(object) <- c("ctryvarest", "list")
}
Expand Down
6 changes: 5 additions & 1 deletion man/ctryvec_to_ctryvar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dab67a5

Please sign in to comment.