Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIRF: add regime-specific option #45

Open
2 tasks
MatthieuStigler opened this issue Oct 5, 2022 · 2 comments
Open
2 tasks

GIRF: add regime-specific option #45

MatthieuStigler opened this issue Oct 5, 2022 · 2 comments
Labels
feature-request Asking for a new feature

Comments

@MatthieuStigler
Copy link
Owner

Many users have been inquiring about a regime-specific GIRF plot. I believe the function GIRF contains all the output to do so, but it seems to be complex enough to deter users from using the raw output.

First step is to find the definition of the regime-specific GIRF. I guess one needs to define first a "regime-specific trajectory". Is that a trajectory whose:

  • history originates in regime A,
  • history originates in A and the shock preserves the regime?
  • stays n.ahead in regime A?

Then, is the regime-specific GIRF history/shock-trajectory dependent? Or can be aggregated over the trajectories? Over shocks or histories?

To do:

  • Find definition of regime-specific GIRF
  • Implement
@MatthieuStigler MatthieuStigler added the feature-request Asking for a new feature label Oct 5, 2022
@giovci
Copy link

giovci commented Oct 6, 2022

Hi Matthieu,

As I wrote https://groups.google.com/g/tsdyn/c/NTwuPN2g4AE for the regime-specific GIRF one would refer to the Baum and Koester, 2011 algorithm.
With the GIRF package, I am not able to obtain the GIRF conditional of the state.
I think there is a problem with rewriting the function because, in TVAR.sim, which is used for simulation, it is not allowed to use an external threshold. And I think this a problem both for the GIRF and for the confidence interval.
I do not know if what I am saying is correct, but I think so. I think that a definition of a regime-specific trajectory is a trajectory whose history originates in regime A. Additionally, I think that regime-specific GIRF is history and shock-trajectory dependent.
In the appendix (page 30) for the algorithm of Baum and Koester, 2011 https://www.econstor.eu/bitstream/10419/44961/1/65618079X.pdf they say that if you have 2 regimes "the same algorithm has to be conducted twice, for the lower and again for the upper regime".
In this case, I believe the division by regimes is done by taking a history (Omega t-1) referring to the actual value of the lagged endogenous variable at a particular date r, where r=1....R are observations for a given regime.

In the algorithm, I think the shock epslion0 refers to the shock of the current period.
This is because in non-linear models the effect of a shock depends on the entire history of the system up to the point when the shock occurs. Thus, as Koop et al. (1996) say, it is necessary to model the GIRF conditional on this history and as a consequence conditional on the size and the direction (sign) of the shock. The GIRF allows the regimes to switch after a shock, a characteristic that is responsible for the different outcomes of positive and negative shocks as well as their size. This is what actually the paper said.

So I think it would be important to extend the function TVAR.sim for the external threshold, as it is a part of the calculation of the GIRF

Thank you,
Giovanna

@MatthieuStigler
Copy link
Owner Author

I believe you have most, if not all, elements in the output of GIRF to construct a regime-specific GIRF. See the output below on how to obtain all GIRF, then plot those for all shocks and histories, or all histories, or all shocks. Admittedly, the regime information is missing, so you would need to compute manually, or enter regime-specific shocks/histories with arguments hist_li and shock_li`. If you further want to aggregate over all histories as in the cited paper you would further aggregate.

Now this is about regime-specific GIRF. Indeed, you will not be able to use it directly with TVAR, as TVAR.boot lacks a thVar argument, see #46. Please direct any discussion about this there.

To do:

  • Return once the regime() value for each histo?
  • Implement a regime-specific plot?

Example of useful plots:

library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
library(tidyverse, warn.conflicts = FALSE)

set <- setar.sim(B = c(0.5, 0.2, 0.5, 0.5), lag = 1, Thresh = 0.5, n = 500)
set_estim <- setar(set, m = 1)

## GIRF
girf_out <- GIRF(set_estim, n.hist = 10, n.shock = 10,
                 n.ahead = 10, R=10) %>% 
  as_tibble()

nrow(girf_out)
#> [1] 1100


girf_out %>% 
  count(hist_x1_l1, shock_var1)
#> # A tibble: 100 × 3
#>    hist_x1_l1 shock_var1     n
#>         <dbl>      <dbl> <int>
#>  1      -1.21     -1.58     11
#>  2      -1.21     -1.10     11
#>  3      -1.21     -1.08     11
#>  4      -1.21     -0.925    11
#>  5      -1.21     -0.689    11
#>  6      -1.21     -0.477    11
#>  7      -1.21     -0.363    11
#>  8      -1.21     -0.254    11
#>  9      -1.21      0.283    11
#> 10      -1.21      0.747    11
#> # … with 90 more rows
#> # ℹ Use `print(n = ...)` to see more rows

girf_out %>% 
  mutate(group = paste(hist_x1_l1, shock_var1)) %>% 
  ggplot(aes(x= n.ahead, y=girf, group=group)) +
  geom_line(alpha=0.6)+
  ggtitle("All GIRF")

girf_out %>% 
  slice_max(hist_x1_l1, n=1) %>% 
  ggplot(aes(x= n.ahead, y=girf, color=factor(shock_var1))) +
  geom_line(alpha=0.6)+
  ggtitle("All GIRF for same history")

girf_out %>% 
  slice_max(shock_var1, n=1) %>% 
  ggplot(aes(x= n.ahead, y=girf, color=factor(hist_x1_l1))) +
  geom_line(alpha=0.6)+
  ggtitle("All GIRF for same shock")

Created on 2022-10-16 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Asking for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants