Computing Means and Bands
Procedure
After running a full-distribution forecast, we are often interested in finding means and density bands of the various forecast outputs. This will allow us to plot our estimation of the full distribution of the forecast outputs.
Main Steps:
Load data: Load and transform data, population data, and population forecast (required for forecast output transformations)
Read in forecast outputs: Read in the outputs saved by
forecast_one, one variable (e.g. one observable) and oneoutput_typeat a time.Transform forecast outputs: If necessary, use
reverse_transformto apply transformations specified in theObservableorPseudoObservabletype to the given forecast output series.Compute means and bands: Compute the means and density bands of the forecast output.
Write to file: For each
output_var, Write aMeansBandsobject (see The MeansBands Type below) to the file specified byget_meansbands_output_file.
Computing means and bands is done by calling compute_meansbands. If desired, you can also write your computed means and bands as matrices by calling meansbands_matrix_all.
For example, to compute means and bands for an unconditional, full-distribution forecast of states and observables:
m = AnSchorfheide()
compute_meansbands(m, :mode, :none, [:forecaststates, forecastobs])DSGE.compute_meansbands โ Function.compute_meansbands(m, input_type, cond_type, output_vars; forecast_string = "",
verbose = :low, kwargs...)
compute_meansbands(m, input_type, cond_type, output_var, df; forecast_string = "",
population_data = DataFrame(), population_forecast = DataFrame(),
verbose = :none, kwargs...)
compute_meansbands(m, input_type, cond_type, output_var, var_name, df;
forecast_string = "", population_data = DataFrame(),
population_forecast = DataFrame(), verbose = :low, kwargs...)Compute means and bands for pseudo-observables, observables, and shocks, and write the results to a file. Other methods are for one output_var and one var_name respectively.
Keyword Arguments
forecast_string::String: forecast identifier string (the value "fcid=value" in the forecast output filename). Required wheninput_type == :subsetdensity_bands::Vector{Float64}: a vector of percent values (between 0 and 1) for which to compute density bandsminimize::Bool: iftrue, choose shortest interval, otherwise just chop off lowest and highest (percent/2)verbose: level of error messages to be printed to screen. One of:none,:low,:high
The MeansBands Type
DSGE.MeansBands โ Type.mutable struct MeansBandsStores the means and bands of results for a particular set of outputs from the forecast step.
Specifically, forecasts can be made for any element in the Cartesian product of 4 sets:
input_type: some subset of the parameter draws from the estimation step. Seeforecast_onefor all possible options.cond_type: conditional type. Seeforecast_onefor all possible options.product: a particular result computed in the forecast. This could be one of the following:
- `hist`: smoothed histories
- `forecast`: forecasted values
- `shockdec`: shock decompositions
- `irf`: impulse responses- variable class: the category in which a particular variable, like
:y_t, falls. Options are:
- `state`: state (from `m.endogenous_states` or `m.endogenous_states_augmented`)
- `obs`: observable (from `m.observables`)
- `pseudo`: pseudoobservable (from `pseudo_measurement` equation)
- `shock`: shock (from `m.exogenous_shocks`)Note that the Cartesian product (product x class) is the set of options for output_vars in the forecast_one function signature.
Fields
metadata::Dict{Symbol,Any}: Contains metadata keeping track of theinput_type,cond_type, product (history, forecast, shockdec, etc), and variable class (observable, pseudoobservable, state, etc) stored in thisMeansBandsstructure.means::DataFrame: aDataFrameof the mean of the time seriesbands::Dict{Symbol,DataFrame}: aDictmapping variable names toDataFrames containing confidence bands for each variable. Seefind_density_bandsfor more information.