I have a threshold VAR. Since nonlinear irf's are not possible in R, I want to get my way around it with IRF's.
Following are the codes for my multivariate time series and then the TVAR
complete=ts.intersect(GDPdiff2,Inflationdiff2,Euribordiff2,CISSdiff2)
tvarcomplete= TVAR(complete, lag=4, nthresh=1, thDelay=1, thVar=complete[,1], trim=0.15)
I want to divide the existing time series with the 4 variables into two (one VAR with the values of all variables which have real GDP growth > 0 and one with < 0 ) and the calculate the corresponding IRFs.
SPLITGDPup <- complete[(GDPdiff2>(0))]
did not work.
I have a two part answer to your question: (1) I'll show you how to subset
complete
correctly, (2) I'll point you to a resource for impulse response functions of nonlinear VARs.Subsetting Multivariate Time Series
There are a couple of issues with the way you attempted to subset
complete
: (1) you were essentially subsetting a matrix like it was a vector, and (2) you were using a logical vector of lengthlength(GDPdiff2)
when you wanted a logical vector of lengthnrow(complete)
. To illustrate, I first make some example data since you didn't provide yours:Now we'll try subsetting it like you did:
That resulted in a vector instead of a matrix. Why? From Hadley Wickham's Advanced R:
Moreover, the elements it pulled from the second column of
complete
don't line up with the positive elements of the first column. Why? Let's look at the logical vector you'd use to subset:There are 10 elements, while
complete
only has 8 rows because you've usedts.intersect
which only gives complete cases (ts2
has less observations thants1
). The combination of these two issues are why your subsetting strategy didn't work. Here's how to do it right:Alternatively, if you know and would prefer to use the column number:
Impulse Response Function for TVAR
I would caution you to do more Googling before you ever make a statement like "Since nonlinear irf's are not possible in R". Almost anything is possible in R, and because of the great R community, so many of the things you could want to do (regarding extant statistical methods) have already been implemented by someone if you know where to look.
In your case, if you had looked at the GitHub repository for the package you're using you'd see that while a generalized impulse response function hasn't been implemented in the tsDyn package, one of the authors has made code for it that you can find here that does this for
TVAR
results.