Learn R Programming

sectorgap

'sectorgap' enables the estimation of a large Bayesian state space model for economic trend cycle decomposition. Economic output is decomposed into potential output and the output gap, consistent with individual sub-sectors of the economy and a set of economic indicators, e.g. regarding labor market and inflation dynamics.

Details on the methodology can be found here:

KOF Working Paper 514

A related paper that uses the above methodology can be found here:

KOF Working Paper 513

If you use 'sectorgap' in your paper, please cite it properly, see citation("sectorgap") in R, or above link to the paper.

Details

Determining potential output and the output gap - two inherently unobservable variables - is a major challenge for macroeconomists. This paper presents the R package sectorgap, which features a flexible modeling and estimation framework for a multivariate Bayesian state space model identifying economic output fluctuations consistent with subsectors of the economy. The proposed model is able to capture various correlations between output and a set of aggregate as well as subsector indicators. Estimation of the latent states and parameters is achieved using a simple Gibbs sampling procedure and various plotting options facilitate the assessment of the results.

Main features

  • data preparation
  • state space model definition
  • prior initialization
  • Bayesian estimation via Gibbs sampling
  • visualization of the results

Install the package

You can install the package from ‘Github’ using the install_github function from the devtools package.

library(devtools)
install_github('sinast3000/sectorgap')

Streicher, S. (2024). sectorgap: An R package for consistent economic trend cycle decomposition. KOF Working Papers 514.

Rathke A. and S. Streicher (2023). Improving output gap estimation---a bottom-up approach. KOF Working Papers 513.

Copy Link

Version

Install

install.packages('sectorgap')

Monthly Downloads

159

Version

0.1.0

License

GPL-3

Maintainer

Sina Streicher

Last Published

January 22nd, 2024

Functions in sectorgap (0.1.0)

mvrnorm

Draws from the multivariate normal distribution.
plot.ss_fit

Plots of results
plot_densities

Prior and posterior plots
pct

Computes the period on period percentage change
draw_variance_multi

Draws a variance from an inverse Wishart distribution. .
ts_c

Creates a constant time series with same dates and frequency as the one given.
print.ss_model

Print ss_model object
print.ss_fit

Print ss_fit object.
is.settings

Settings object validity check
initialize_ss

Initializes a state space model
update_nonlinear_constraints

Non linear constraints update
define_ssmodel

State space model
initialize_prior

Prior distribution
initialize_settings

Model settings
postARp_phi

Draws the autoregressive parameters of an AR process (AR parameters only). .
recessions_ch

Swiss recessions
postARp

Draws the parameters of an AR process (AR parameters and variance).
draw_output_gap

Draws the parameters of the output gap..
recessions_us

US recessions
plot_time_series

Time series plots
print.prior

Print prior object
print.settings

Print settings object
update_ssmodel

State space model update
matmult3d

array multiplication
hpd_interval

Highest posterior density interval (HPDI)
hpfilter

HP filter
settings_to_df

Data frames with model settings
results_state

MCMC summary statistics for states
plot_trace

Prior and posterior plots
mcmc_summary

MCMC summary statistics
post_regression

Draws the parameters in a regression equation with AR errors, if specified.
substr_r

Extracts last letter in string
prepate_data

Input data
transform_results

Format results
data_ch

Swiss data set
compute_mcmc_results

Results for sampled parameters and states
estimate_ssmodel

Bayesian estimation via Gibbs sampling
geweke_test

Geweke test for convergence
compute_weights

Computes weights from sub sector data
add_cycle

Add a cycle to a state space model
draw_variance_scalar

Draws a variance from an inverse Wishart distribution.
compute_gaps

Gaps of observation equations
add_error

Add error to state equation
helper_posterior_assignment

Settings for draws from posterior
add_lag

Add lags to state equation
add_init_mat

Add initialization matrices to state space model
aggregate_gap

Output gap contributions
add_trend

Add a trend to a state space model
draw_trend_innovations

Draws (correlated) trend variances.