MyNixOS website logo
Description

State-Dependent Empirical Analysis.

A set of tools for state-dependent empirical analysis through both VAR- and local projection-based state-dependent forecasts, impulse response functions, historical decompositions, and forecast error variance decompositions.

sovereign: State-Dependent Empirical Analysis

License: GPL v3 CRAN status Lifecycle: stable codecov R-CMD-check

The sovereign package introduces a set of tools for state-dependent empirical analysis through both VAR- and local projection-based state-dependent forecasts, impulse response functions, forecast error variance decompositions, and historical decompositions.

See the sovereign package website for examples and documentation.


Installation

One may install sovereign through the package’s GitHub page with

devtools::install_github('tylerJPike/sovereign')

or through CRAN via

install.packages("sovereign")

Available Tools

Unsupervised Regime Assignment

  1. random forest
  2. k-means clustering
  3. EM
  4. Bai & Perron (2003)

Local Projections (LP)

  1. direct projection forecasting
  2. impulse responses

Vector Auto-Regression (VAR), Structural VAR (SVAR),
and external instrument SVAR (Proxy-SVAR)

  1. recursive forecasting
  2. impulse responses
  3. forecast error variance decomposition
  4. historical error decomposition

Basic Workflow

# load packages
library(sovereign)         # analysis
library(dplyr)             # general cleaning
library(lubridate)         # date functions

#-------------------------------------------
# create data
#-------------------------------------------
# pull and prepare data from FRED
quantmod::getSymbols.FRED(
    c('UNRATE','INDPRO','GS10'), 
    env = globalenv())

Data = cbind(UNRATE, INDPRO, GS10)

Data = data.frame(Data, date = zoo::index(Data)) %>%
    filter(lubridate::year(date) >= 1990,
           lubridate::year(date) <  2020) %>% 
    na.omit()

# create a regime explicitly   
Data.threshold = Data %>%
    mutate(mp = if_else(GS10 > median(GS10), 1, 0))

#------------------------------------------
# learn regimes
#------------------------------------------
# assign regimes based on unsurpervised kmeans
#  (will not be used further)
regimes = 
    regimes(
        data = Data, 
        regime.n = 3, 
        engine = 'kmeans')

#------------------------------------------
# single-regime var
#------------------------------------------
# estimate VAR
# (using IC lag selection and short-term 
#  impact restrictions, i.e. calculate structurals
   errors via Cholesky decomposition)
var =
    VAR(
        data = Data,
        horizon = 10,
        freq = 'month',
        lag.ic = 'BIC',
        lag.max = 4)

# if impacts of the COVID shock are present,
#  in the user's data, then the user can 
#  implement the Lenza-Primiceri COVID volatility
#  correction for VARs: 
# var = covid_volatility_correction(var)

# plot forecasts
plot_forecast(var$forecasts[[1]])

# plot residuals
plot_error(var$residuals[[1]])

# estimate IRF
irf =
    IRF(
        var,
        bootstraps.num = 10,
        CI = c(0.05,0.95))

# plot IRF
plot_irf(irf)

# estimate forecast error variance decomposition
fevd =
    FEVD(
        var,
        horizon = 10)

# plot FEVD
plot_fevd(fevd)

# estimate historical decomposition
hd = HD(var)

# plot HD
plot_hd(hd)

#-------------------------------------------
# multi-regime var
#-------------------------------------------
# estimate multi-regime VAR
var =
    RVAR(
        data = Data.threshold,
        regime = 'mp',
        p = 1,
        horizon = 1,
        freq = 'month')

# estimate IRF
rvar.irf =
    IRF(
        rvar,
        horizon = 10,
        bootstraps.num = 10,
        CI = c(0.05,0.95))

# plot IRF
# regime 1: low interest rates
plot_irf(rvar.irf[[1]])
# regime 2: high interest rates
plot_irf(rvar.irf[[2]])

# estimate forecast error variance decomposition
rvar.fevd =
    FEVD(
        rvar,
        horizon = 10)

# plot FEVD
# regime 1: low interest rates
plot_fevd(rvar.fevd[[1]])
# regime 2: high interest rates
plot_fevd(rvar.fevd[[2]])

# estimate HD
rvar.hd = HD(rvar)

#-------------------------------------------
# single-regime local projections
#-------------------------------------------
# estimate single-regime forecasts 
#  (one or multiple horizons may be estimated)
lp = 
    LP(
        data = Data,
        p = 1,
        horizon = 1,
        freq = 'month')

# estimate single-regime IRF
lp.irf = IRF(lp)

# plot IRF
plot_irf(lp.irf)

#-------------------------------------------
# multi-regime local projections
#-------------------------------------------
# estimate multi-regime IRF
rlp = 
    RLP(
        data = Data,
        regime = 'mp',
        p = 1,
        horizon = 1,
        freq = 'month')

# estimate multi-regime IRF
rlp.irf = IRF(rlp)

# plot IRF
# regime 1: low interest rates
plot_irf(rlp.irf[[1]])
# regime 2: high interest rates
plot_irf(rlp.irf[[2]])

Contact

If you should have questions, concerns, or wish to collaborate, please contact Tyler J. Pike.

Metadata

Version

1.2.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows