% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hd.R
\name{hd}
\alias{hd}
\alias{hd.bgvar.irf}
\title{Historical Decomposition}
\usage{
hd(x, rotation.matrix=NULL, verbose=TRUE)
}
\arguments{
\item{x}{an item fitted by \code{irf}.}

\item{rotation.matrix}{If \code{NULL} and the \code{irf.bgvar} object has been fitted via sign restrictions, the rotation matrix is used that minimizes the distance to the median impulse responses at the posterior median.}

\item{verbose}{If set to \code{FALSE} it suppresses printing messages to the console.}
}
\value{
Returns a list with the following objects \describe{
\item{\code{hd_array}}{ is a three-dimensional array with the first dimension referring to the K time series, the second to the T observations and the third dimensions containing the contribution of the shocks in explaining historically deviations in the time series from their trend. The third dimension is K+3, since the last three entries contain the contributions of the constant, the initial condition and a residual component that the contributions sum up to the original time series. If a trend i specified in the model the third dimension is K+3 with trend ordered after the constant.}
\item{\code{struc.shcok}}{ contains the structural shock.}
\item{\code{x}}{ is a matrix object that contains the original time series, which is of dimension K times (T-plag).}
}
}
\description{
A function that calculates historical decomposition (HD) of the time series and the structural error.
}
\details{
To save computational time as well as due to storage limits, both functions are based on the posterior median (as opposed to calculating HDs and the structural error for each draw of the MCMC chain). In case the shock has been identified via sign restrictions, a rotation matrix has to be selected to calculate both statistics. If not specified otherwise (via \code{R}), the algorithm searches for 50 rotation matrices that fulfill the sign restrictions at the \emph{posterior median} of the coefficients and then singles out the rotation matrix that minimizes the distance to the median of the impulse responses as suggested in Fry and Pagan (2011).
}
\examples{
\donttest{
library(BGVAR)
data(testdata)
model.eer<-bgvar(Data=testdata, W=W.test, draws=50, burnin=50, 
                 plag=1, prior="SSVS", eigen=TRUE)
                 
# US monetary policy shock
shockinfo <- get_shockinfo("chol")
shockinfo$shock <- "US.stir"; shockinfo$scale <- -100
irf.chol.us.mp<-irf(model.eer,n.ahead=48,shockinfo=shockinfo)

# calculates historical decomposition
HD <- hd(irf.chol.us.mp)
}
}
\references{
Fry, R. and A. Pagan (2011) \emph{Sign restrictions in Structural Vector Autoregressions: A Critical Review}. Journal of Economic Literature, Vol. 49(4), pp. 938-960.
}
\seealso{
\code{\link{bgvar}} and \code{\link{irf}}.
}
\author{
Maximilian Boeck, Martin Feldkircher, Florian Huber
}
