1"irf.vec2var" <- 2function(x, impulse=NULL, response=NULL, n.ahead=10, ortho=TRUE, cumulative=FALSE, boot=TRUE, ci=0.95, runs=100, seed=NULL, ...){ 3 if(!(class(x)=="vec2var")){ 4 stop("\nPlease provide an object of class 'vec2var', generated by 'vec2var()'.\n") 5 } 6 y.names <- colnames(x$y) 7 if(is.null(impulse)){ 8 impulse <- y.names 9 } else { 10 impulse <- as.vector(as.character(impulse)) 11 if(any(!(impulse %in% y.names))) { 12 stop("\nPlease provide variables names in impulse\nthat are in the set of endogenous variables.\n") 13 } 14 impulse <- subset(y.names, subset = y.names %in% impulse) 15 } 16 if(is.null(response)){ 17 response <- y.names 18 } else { 19 response <- as.vector(as.character(response)) 20 if(any(!(response %in% y.names))){ 21 stop("\nPlease provide variables names in response\nthat are in the set of endogenous variables.\n") 22 } 23 response <- subset(y.names, subset = y.names %in% response) 24 } 25 ## Getting the irf 26 irs <- .irf(x = x, impulse = impulse, response = response, y.names = y.names, n.ahead = n.ahead, ortho = ortho, cumulative = cumulative) 27 ## Bootstrapping 28 Lower <- NULL 29 Upper <- NULL 30 if(boot){ 31 ci <- as.numeric(ci) 32 if((ci <= 0)|(ci >= 1)){ 33 stop("\nPlease provide a number between 0 and 1 for the confidence interval.\n") 34 } 35 ci <- 1 - ci 36 if(!(is.null(seed))) set.seed(abs(as.integer(seed))) 37 BOOT <- .bootirfvec2var(x = x, n.ahead = n.ahead, runs = runs, ortho = ortho, cumulative = cumulative, impulse = impulse, response = response, ci = ci, seed = seed, y.names = y.names) 38 Lower <- BOOT$Lower 39 Upper <- BOOT$Upper 40 names(Lower) <- impulse 41 names(Upper) <- impulse 42 } 43 result <- list(irf=irs, Lower=Lower, Upper=Upper, response=response, impulse=impulse, ortho=ortho, cumulative=cumulative, runs=runs, ci=ci, boot=boot, model = class(x)) 44 class(result) <- "varirf" 45 return(result) 46} 47