Skip to content

Commit 40a5408

Browse files
committed
whitespace changes
1 parent 9a04383 commit 40a5408

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

docs/src/plotting.md

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Load a model:
3939
r_real_ann[0] = 4 * log(realinterest[0])
4040
M_real[0] = Y[0] / R[0] ^ η
4141
end
42+
4243
@parameters Gali_2015_chapter_3_nonlinear begin
4344
σ = 1
4445
φ = 5
@@ -71,9 +72,9 @@ plot_irf(Gali_2015_chapter_3_nonlinear)
7172

7273
The plot shows every endogenous variable affected by each exogenous shock and annotates the title with the model name, shock identifier, sign of the impulse (positive by default), and the page indicator (e.g. `(1/3)`). Each subplot overlays the steady state as a horizontal reference line (non‑stochastic for first‑order solutions, stochastic otherwise) and, when the variable is strictly positive, adds a secondary axis with percentage deviations.
7374

74-
### Algorithm
75+
### `algorithm`
7576

76-
[Default: `:first_order`, Type: `Symbol`]: algorithm to solve for the dynamics of the model. Available algorithms: `:first_order`, `:second_order`, `:pruned_second_order`, `:third_order`, `:pruned_third_order`
77+
[Default: `:first_order`, Type: `Symbol`]: algorithm to solve for the dynamics of the model. Available algorithms: `:first_order`, `:second_order`, `:pruned_second_order`, `:third_order`, `:pruned_third_order`.
7778
You can plot IRFs for different solution algorithms. Here we use a second-order perturbation solution:
7879

7980
```julia
@@ -98,6 +99,7 @@ We can compare the two solution methods side by side with `plot_irf!`, which add
9899
```julia
99100
plot_irf(Gali_2015_chapter_3_nonlinear,
100101
shocks = :eps_a)
102+
101103
plot_irf!(Gali_2015_chapter_3_nonlinear,
102104
shocks = :eps_a,
103105
algorithm = :second_order)
@@ -119,7 +121,7 @@ plot_irf!(Gali_2015_chapter_3_nonlinear,
119121

120122
Note that the pruned third-order solution includes the effect of time varying risk and flips the sign for the reaction of `MC` and `N`. The additional solution is added to the plot as another colored line and another entry in the legend and a new entry in the table below highlighting the relevant steady states.
121123

122-
### Initial state
124+
### `initial_state`
123125

124126
[Default: `[0.0]`, Type: `Union{Vector{Vector{Float64}},Vector{Float64}}`]: The initial state defines the starting point for the model. In the case of pruned solution algorithms the initial state can be given as multiple state vectors (Vector{Vector{Float64}}). In this case the initial state must be given in deviations from the non-stochastic steady state. In all other cases the initial state must be given in levels. If a pruned solution algorithm is selected and `initial_state` is a Vector{Float64} then it impacts the first order initial state vector only. The state includes all variables as well as exogenous variables in leads or lags if present. `get_irf(𝓂, shocks = :none, variables = :all, periods = 1)` returns a `KeyedArray` with all variables. The `KeyedArray` type is provided by the AxisKeys package.
125127

@@ -192,9 +194,7 @@ init_state_2nd = get_irf(Gali_2015_chapter_3_nonlinear,
192194
Then we set `nu` to 0.1:
193195

194196
```julia
195-
init_state_2nd(:nu,
196-
:,
197-
:) .= 0.1
197+
init_state_2nd(:nu, :, :) .= 0.1
198198
```
199199

200200
and plot the IRF for `eps_a` starting from this initial state:
@@ -212,6 +212,7 @@ While we can also stack the two components, they will not add up linearly becaus
212212
plot_irf(Gali_2015_chapter_3_nonlinear,
213213
shocks = :eps_a,
214214
initial_state = vec(init_state))
215+
215216
plot_irf!(Gali_2015_chapter_3_nonlinear,
216217
shocks = :eps_a,
217218
initial_state = vec(init_state_2nd),
@@ -251,6 +252,7 @@ Then we set `nu` to 0.1 in the first order terms. Inspecting `init_state_pruned_
251252

252253
```julia
253254
init_states_pruned_3rd_vec[1][18] = 0.1
255+
254256
plot_irf(Gali_2015_chapter_3_nonlinear,
255257
shocks = :eps_a,
256258
initial_state = init_states_pruned_3rd_vec,
@@ -268,9 +270,9 @@ init_state_pruned_3rd = get_irf(Gali_2015_chapter_3_nonlinear,
268270
periods = 1,
269271
levels = true,
270272
algorithm = :pruned_third_order)
271-
init_state_pruned_3rd(:nu,
272-
:,
273-
:) .= 0.1
273+
274+
init_state_pruned_3rd(:nu, :, :) .= 0.1
275+
274276
plot_irf(Gali_2015_chapter_3_nonlinear,
275277
shocks = :eps_a,
276278
initial_state = vec(init_state_pruned_3rd),
@@ -284,6 +286,7 @@ plot_irf!(Gali_2015_chapter_3_nonlinear,
284286
shocks = :eps_a,
285287
initial_state = vec(init_state_2nd),
286288
algorithm = :second_order)
289+
287290
plot_irf!(Gali_2015_chapter_3_nonlinear,
288291
shocks = :eps_a,
289292
initial_state = vec(init_state))
@@ -385,9 +388,7 @@ get_state_variables(Gali_2015_chapter_3_nonlinear)
385388
Now let's modify the initial state and set `nu` to 0.1:
386389

387390
```julia
388-
init_state(:nu,
389-
:,
390-
:) .= 0.1
391+
init_state(:nu, :, :) .= 0.1
391392
```
392393

393394
Now we can input the modified initial state into the `plot_irf` function as a vector and set `shocks` to `:none`:
@@ -406,8 +407,10 @@ We can also compare shocks:
406407

407408
```julia
408409
shocks = get_shocks(Gali_2015_chapter_3_nonlinear)
410+
409411
plot_irf(Gali_2015_chapter_3_nonlinear,
410412
shocks = shocks[1])
413+
411414
for s in shocks[2:end]
412415
plot_irf!(Gali_2015_chapter_3_nonlinear,
413416
shocks = s)
@@ -422,7 +425,9 @@ A series of shocks can be passed on using either a `Matrix{Float64}`, or a `Keye
422425

423426
```julia
424427
shocks = get_shocks(Gali_2015_chapter_3_nonlinear)
428+
425429
n_periods = 3
430+
426431
shock_keyedarray = KeyedArray(
427432
zeros(length(shocks), n_periods),
428433
Shocks = shocks,
@@ -436,6 +441,7 @@ and then we set a one standard deviation shock to `eps_a` in period 1, a negativ
436441
shock_keyedarray("eps_a", [1]) .= 1
437442
shock_keyedarray("eps_z", [2]) .= -1/2
438443
shock_keyedarray("eps_nu", [3]) .= 1/3
444+
439445
plot_irf(Gali_2015_chapter_3_nonlinear,
440446
shocks = shock_keyedarray)
441447
```
@@ -448,9 +454,11 @@ The same can be done with a Matrix:
448454

449455
```julia
450456
shock_matrix = zeros(length(shocks), n_periods)
457+
451458
shock_matrix[1, 1] = 1
452459
shock_matrix[3, 2] = -1/2
453460
shock_matrix[2, 3] = 1/3
461+
454462
plot_irf(Gali_2015_chapter_3_nonlinear,
455463
shocks = shock_matrix)
456464
```
@@ -459,10 +467,14 @@ In certain circumstances a shock matrix might correspond to a certain scenario a
459467

460468
```julia
461469
shock_matrix_1 = zeros(length(shocks), n_periods)
470+
462471
shock_matrix_1[1, 1] = 1
463472
shock_matrix_1[3, 2] = -1/2
464473
shock_matrix_1[2, 3] = 1/3
474+
475+
465476
shock_matrix_2 = zeros(length(shocks), n_periods * 2)
477+
466478
shock_matrix_2[1, 4] = -1
467479
shock_matrix_2[3, 5] = 1/2
468480
shock_matrix_2[2, 6] = -1/3
@@ -473,6 +485,7 @@ We can plot them on top of each other using the :stack option:
473485
```julia
474486
plot_irf(Gali_2015_chapter_3_nonlinear,
475487
shocks = shock_matrix_1)
488+
476489
plot_irf!(Gali_2015_chapter_3_nonlinear,
477490
shocks = shock_matrix_2,
478491
plot_type = :stack)
@@ -501,9 +514,11 @@ Let's take a shock matrix with 15 period length as input and set the periods arg
501514

502515
```julia
503516
shock_matrix = zeros(length(shocks), 15)
517+
504518
shock_matrix[1, 1] = .1
505519
shock_matrix[3, 5] = -1/2
506520
shock_matrix[2, 15] = 1/3
521+
507522
plot_irf!(Gali_2015_chapter_3_nonlinear,
508523
shocks = shock_matrix,
509524
periods = 20)
@@ -623,6 +638,7 @@ In order to see the auxiliary variables let's use a model that has auxiliary var
623638
log_gy_obs[0] = log(gy_obs[0])
624639
log_gp_obs[0] = log(gp_obs[0])
625640
end
641+
626642
@parameters FS2000 begin
627643
alp = 0.356
628644
bet = 0.993
@@ -639,8 +655,8 @@ end
639655
both c and P appear in t+2 and will thereby add auxiliary variables to the model. If we now plot the IRF for all variables excluding OBC-related ones we see the auxiliary variables as well:
640656

641657
```julia
642-
plot_irf(FS2000,
643-
variables = :all_excluding_obc)
658+
plot_irf(FS2000,
659+
variables = :all_excluding_obc)
644660
```
645661

646662
![FS2000 IRF - e_a shock with auxiliary variables](../assets/with_aux_vars_irf__FS2000__e_a__1.png)
@@ -675,6 +691,7 @@ c and P appear twice, once as the variable itself and once as an auxiliary varia
675691
r_real_ann[0] = 4 * log(realinterest[0])
676692
M_real[0] = Y[0] / R[0] ^ η
677693
end
694+
678695
@parameters Gali_2015_chapter_3_obc begin
679696
= 1.0
680697
σ = 1
@@ -737,6 +754,7 @@ The steady states and dynamics changed as a result of changing the discount fact
737754
plot_irf(Gali_2015_chapter_3_nonlinear,
738755
parameters = => 0.99,
739756
shocks = :eps_a)
757+
740758
plot_irf!(Gali_2015_chapter_3_nonlinear,
741759
parameters = => 0.95,
742760
shocks = :eps_a)
@@ -770,7 +788,9 @@ or simply a Vector of parameter values in the order they were defined in the mod
770788

771789
```julia
772790
params = get_parameters(Gali_2015_chapter_3_nonlinear, values = true)
791+
773792
param_vals = [p[2] for p in params]
793+
774794
plot_irf(Gali_2015_chapter_3_nonlinear,
775795
parameters = param_vals,
776796
shocks = :eps_a)
@@ -868,9 +888,9 @@ plot_irf!(Gali_2015_chapter_3_nonlinear,
868888

869889
The comparison of the IRFs for S reveals that the reaction of S is highly state dependent and can go either way depending on the state of the economy when the shock hits. The same is true for `W_real`, while the other variables are less state dependent and the GIRF and standard IRF are more similar.
870890

871-
### `generalised_irf_warmup_iterations` and `generalised_irf_draws`
891+
### `generalised_irf_warmup_iterations`, `generalised_irf_draws`
872892

873-
The number of draws and warmup iterations can be adjusted using the generalised_irf_draws and generalised_irf_warmup_iterations arguments. Increasing the number of draws will increase the accuracy of the GIRF at the cost of increased computation time. The warmup iterations are used to ensure that the starting points of the individual draws are exploring the state space sufficiently and are representative of the model's ergodic distribution.
893+
The number of draws and warmup iterations can be adjusted using the `generalised_irf_draws` and `generalised_irf_warmup_iterations` arguments. Increasing the number of draws will increase the accuracy of the GIRF at the cost of increased computation time. The warmup iterations are used to ensure that the starting points of the individual draws are exploring the state space sufficiently and are representative of the model's ergodic distribution.
874894

875895
Let's start with the GIRF that had the wiggly lines above:
876896

@@ -915,6 +935,7 @@ In order to fully cover the ergodic distribution of the model it can be useful t
915935
plot_irf(Gali_2015_chapter_3_nonlinear,
916936
shocks = :eps_a,
917937
algorithm = :pruned_second_order)
938+
918939
plot_irf!(Gali_2015_chapter_3_nonlinear,
919940
generalised_irf = true,
920941
generalised_irf_draws = 5000,
@@ -939,6 +960,7 @@ plot_irf(Gali_2015_chapter_3_nonlinear,
939960
parameters = ( => 0.99, => 0.0),
940961
shocks = :eps_a,
941962
label = "Std. params")
963+
942964
plot_irf!(Gali_2015_chapter_3_nonlinear,
943965
parameters = ( => 0.95, => 0.5),
944966
shocks = :eps_a,
@@ -956,6 +978,7 @@ plot_irf(Gali_2015_chapter_3_nonlinear,
956978
parameters = ( => 0.99, => 0.0),
957979
shocks = :eps_a,
958980
label = :standard)
981+
959982
plot_irf!(Gali_2015_chapter_3_nonlinear,
960983
parameters = ( => 0.95, => 0.5),
961984
shocks = :eps_a,
@@ -969,6 +992,7 @@ plot_irf(Gali_2015_chapter_3_nonlinear,
969992
parameters = ( => 0.99, => 0.0),
970993
shocks = :eps_a,
971994
label = 0.99)
995+
972996
plot_irf!(Gali_2015_chapter_3_nonlinear,
973997
parameters = ( => 0.95, => 0.5),
974998
shocks = :eps_a,
@@ -1045,17 +1069,7 @@ Let's select 9 variables to plot and set plots_per_page to 4:
10451069

10461070
```julia
10471071
plot_irf(Gali_2015_chapter_3_nonlinear,
1048-
variables = [
1049-
:Y,
1050-
:Pi,
1051-
:R,
1052-
:C,
1053-
:N,
1054-
:W_real,
1055-
:MC,
1056-
:i_ann,
1057-
:A,
1058-
],
1072+
variables = [:Y, :Pi, :R, :C, :N, :W_real, :MC, :i_ann, :A],
10591073
shocks = :eps_a,
10601074
plots_per_page = 2)
10611075
```
@@ -1113,11 +1127,12 @@ plot_irf(Gali_2015_chapter_3_nonlinear,
11131127
### `tol`
11141128

11151129
[Default: `Tolerances()`, Type: `Tolerances`]: define various tolerances for the algorithm used to solve the model. See documentation of Tolerances for more details: `?Tolerances`
1116-
You can adjust the tolerances used in the numerical solvers. The Tolerances object allows you to set tolerances for the non-stochastic steady state solver (NSSS), Sylvester equations, Lyapunov equation, and quadratic matrix equation (qme). For example, to set tighter tolerances (here we also change parameters to force a recomputation of the solution):
1130+
You can adjust the tolerances used in the numerical solvers. The Tolerances object allows you to set tolerances for the non-stochastic steady state solver (NSSS), Sylvester equations, Lyapunov equation, and quadratic matrix equation (QME). For example, to set tighter tolerances (here we also change parameters to force a recomputation of the solution):
11171131

11181132
```julia
11191133
custom_tol = Tolerances(qme_acceptance_tol = 1e-12,
11201134
sylvester_acceptance_tol = 1e-12)
1135+
11211136
plot_irf(Gali_2015_chapter_3_nonlinear,
11221137
shocks = :eps_a,
11231138
tol = custom_tol,
@@ -1141,7 +1156,7 @@ plot_irf(Gali_2015_chapter_3_nonlinear,
11411156
verbose = true)
11421157
```
11431158

1144-
For most use cases, the default :schur algorithm is recommended. Use this argument if you have specific needs or encounter issues with the default solver.
1159+
For most use cases, the default `:schur` algorithm is recommended. Use this argument if you have specific needs or encounter issues with the default solver.
11451160

11461161
### `sylvester_algorithm`
11471162

@@ -1162,8 +1177,7 @@ For third-order solutions, you can specify different algorithms for the second a
11621177
plot_irf(Gali_2015_chapter_3_nonlinear,
11631178
shocks = :eps_a,
11641179
algorithm = :third_order,
1165-
sylvester_algorithm = (:doubling,
1166-
:bicgstab),
1180+
sylvester_algorithm = (:doubling, :bicgstab),
11671181
verbose = true)
11681182
```
11691183

0 commit comments

Comments
 (0)