`AutoregressiveModels.ARMAProcess`

— Type`ARMAProcess(ars, mas, intercept=nothing)`

Return an autoregressive–moving-average process $y_t$ defined as

\[\left(1-\sum_{i=1}^p \rho_i L^i\right) = c + \left(1-\sum_{i=1}^q \varphi_i L^i\right) \varepsilon_t\]

where $\{\rho_i\}_i$, $\{\varphi_i\}_i$ and $c$ are specified with `mas`

, `ars`

and `intercept`

respectively; $L$ is the lag operator. Notice the *negative* sign associated with the moving-average terms.

`AutoregressiveModels.Factor`

— Type`Factor{TF, S} <: RegressionModel`

Results and cache from estimating a factor model. This object holds all arrays that are necessary for estimating the model without additional memory allocations. See also `fit`

and `fit!`

.

**Fields**

`Y::Matrix{TF}`

: data matrix where each column corresponds to a time series.`Ystd::Matrix{TF}`

: standardized data with zero mean and unit standard deviation across the columns.`Ysd::Vector{TF}`

: standard deviation of each column in`Y`

.`Yca::Matrix{TF}`

: cache of the same size as`Y`

.`fac::Matrix{TF}`

: factors of the model; observed factors are placed in the beginning columns.`crossfac::Matrix{TF}`

: cache for holding`fac'fac`

and factorization.`Λ::Matrix{TF}`

: loading matrix of the model; each row corresponds to a factor in`fac`

.`crossΛu::Union{Matrix{TF}, Nothing}`

: cache needed when factors and loading matrix need to be solved iteratively.`svdca::Union{SDDcache{TF}, SVDcache{TF}, Nothing}`

: cache for singular value decomposition if any unobserved factor is involved.`nfaco::Int`

: number of observed factors.`resid::Matrix{TF}`

: residuals from the standardized data`Ystd`

and estimated`fac`

before scaling the loading matrix`Λ`

for`Y`

.`tss::Vector{TF}`

: total sum of squares for each columns of`Ystd`

.`rss::Vector{TF}`

: residual sum of squares for each columns of`Ystd`

.`r2::Vector{TF}`

: r-squared for each columns of`Ystd`

.`esample::BitVector`

: indicators for rows involved in estimation from original data table when constructing`Y`

; irrelevant to estimation once`Y`

is given.

`AutoregressiveModels.OLS`

— Type`OLS <: RegressionModel`

Data from an ordinary least squares regression for vector autoregression estimation.

`AutoregressiveModels.VARProcess`

— Type`VARProcess(B::AbstractMatrix, B0=nothing; copy::Bool=false)`

Return a vector autoregressive process $Y_t$ defined as

\[Y_t = B_0 + \sum_{l=1}^p B_l Y_{t-l} + \ε_t\]

where the autoregressive coefficients $\{\B_l\}_l$ are collected in matrix `B`

by column and the optional intercept $B_0$ is in a vector `B0`

.

`AutoregressiveModels.VARProcess`

— Method`VARProcess(r::VectorAutoregression; copy::Bool=false)`

Construct a `VARProcess`

based on the coefficient estimates from `r`

.

`AutoregressiveModels.VectorAutoregression`

— Type`VectorAutoregression{TE, HasIntercept} <: RegressionModel`

Results from vector autoregression estimation.

`AutoregressiveModels.biascorrect`

— Method`biascorrect(r::VectorAutoregression; kwargs...)`

Correct the bias of the least-squares coefficient estimates in `r`

with Pope's formula. The corrected estimates can be retrieved from the returned object with `coefcorrected`

.

**Reference**

**Pope, Alun L.** 1990. "Biases of Estimators in Multivariate Non-Gaussian Autoregressions." *Journal of Time Series Analysis* 11 (3): 249–258.

`AutoregressiveModels.bootstrap!`

— Method`bootstrap!(stats, r::VectorAutoregression; kwargs...)`

Conduct autoregressive bootstrap for statistics specified with `stats`

while assuming the data generating process can be approximated by an estimated vector autoregressive model `r`

.

Each statistic to be computed needs to be paired with an array for storing the output. The number of bootstrap iterations is determined by the last dimension of the array; while the other dimensions should match the size of the statistic. For example, if the statistic is a scalar, the output array should be a vector; it should be a matrix if the statistic is a vector. The statistic is specified as a function accepting a `NamedTuple`

as the single argument, which contains a field `out`

that points to a view of the array indexed by the last dimension, a field `data`

that provides the current sample of bootstrap data, and a field `r`

for the results of VAR estimation based on `data`

if the keyword `estimatevar`

is `true`

(`nothing`

otherwise). The provided function is called in each bootstrap iteration with such a `NamedTuple`

containing the updated values and the computed statistics are expected to be saved in-place to `out`

. For the sake of performance, unnecessary allocations should be avoided when defining such a function. The argument `stats`

can be either a `Pair`

of the pre-allocated output array and the statistic function or an iterable of `Pairs`

if more than one statistic is needed for the same bootstrap procedure.

**Keywords**

`initialindex::Union{Function,Integer}=randomindex`

: the row index of a data columns from`r`

for selecting the initial lags to be used for the bootstrap data.`drawresid::Function=wilddraw!`

: a function that specifies how residuals are generated for the bootstrap data given the initial lags.`correctbias=false`

: conduct bias correction with`biascorrect`

.`estimatevar::Bool=true`

: re-estimate VAR model specified in`r`

with each sample of the bootstrap data.`ntasks::Integer=Threads.nthreads()`

: number of tasks spawned to conduct bootstrap iterations in concurrent chunks with multiple threads.`keepbootdata::Bool=false`

: collect and return each sample of bootstrap data generated (with possibly very large memory usage).

`AutoregressiveModels.coefcorrected`

— Method`coefcorrected(r::VectorAutoregression)`

Return the coefficient estimates after bias correction. See also `biascorrect`

.

`AutoregressiveModels.companionform`

— Method`companionform(var::VARProcess)`

Return a coefficient matrix representing the companion form of `var`

.

`AutoregressiveModels.forecastvar!`

— Method`forecastvar!(out::AbstractArray{T,3}, irfs::AbstractArray{T,3})`

Compute the variance of forecast error over each horizon given orthogonalized impulse response coefficients specified with `irfs`

and store the results in an array `out`

. The number of horizons computed is determined by the second dimension of `irfs`

and `out`

should have the same size as `irfs`

. See also `forecastvar`

.

`AutoregressiveModels.forecastvar`

— Method`forecastvar(irfs::AbstractArray)`

Same as `forecastvar!`

, but allocates an array for storing the results.

`AutoregressiveModels.histvar!`

— Method`histvar!(out::AbstractArray{TF,3}, irfs::AbstractArray{TF,3}, shocks::AbstractMatrix)`

Compute the variance to be used for historical decomposition given impulse response coefficients specified with `irfs`

and historical `shocks`

. Results are stored in an array `out`

. See also `histvar`

.

`AutoregressiveModels.histvar`

— Method`histvar(irfs::AbstractArray, shocks::AbstractMatrix)`

Same as `histvar!`

, but allocates an array for storing the results.

`AutoregressiveModels.impulse`

— Function`impulse(arma::ARMAProcess, nhorz::Integer, ε0::Real=1.0)`

Same as `impulse!`

, but allocates an array for storing the results. The number of horizons needs to be specified explicitly with `nhorz`

.

`AutoregressiveModels.impulse!`

— Function`AutoregressiveModels.impulse!`

— Method```
impulse!(out, var::VARProcess, ε0::AbstractVecOrMat; kwargs...)
impulse!(out, var::VARProcess, ishock::Union{Integer, AbstractRange}; kwargs...)
```

Compute the responses of the `var`

process to the impulse specified with `ε0`

or `ishock`

and store the results in an array `out`

. The number of horizons to be computed is determined by the second dimension of `out`

. See also `impulse`

and `simulate!`

.

As a vector, `ε0`

specifies the magnitude of the impulse to each variable; columns in a matrix are interpreted as multiple impulses with results stored separately along the third dimension of array `out`

. Alternatively, `ishock`

specifies the index of a single variable that is affected on impact; a range of indices is intercepted as multiple impulses.

**Keywords**

`nlag::Integer=arorder(var)`

: the number of lags from`var`

used for simulations.

`AutoregressiveModels.impulse!`

— Method```
impulse!(out, r::VectorAutoregression, ε0::AbstractVecOrMat; kwargs...)
impulse!(out, r::VectorAutoregression, ishock::Union{Integer, AbstractRange}; kwargs...)
```

Compute impulse responses to shocks specified with `ε0`

or `ishock`

based on the estimation result in `r`

and store the results in an array `out`

. The number of horizons to be computed is determined by the second dimension of `out`

. Responses to structural shocks identified based on temporal (short-run) restrictions can be computed if Cholesky factorization has been conducted for `r`

. See also `impulse`

and `simulate!`

.

As a vector, `ε0`

specifies the magnitude of the impulse to each variable; columns in a matrix are interpreted as multiple impulses with results stored separately along the third dimension of array `out`

. Alternatively, `ishock`

specifies the index of a single variable that is affected on impact; a range of indices is intercepted as multiple impulses. With the keyword `choleskyshock`

being `true`

, any shock index specified is interpreted as referring to the structural shock instead of the reduced-form shock.

**Keywords**

`nlag::Integer=arorder(var)`

: the number of lags from`var`

used for simulations.`choleskyshock::Bool=false`

: whether any shock index refers to a structural shock.

`AutoregressiveModels.impulse`

— Method```
impulse(var::VARProcess, ε0::AbstractVecOrMat, nhorz::Integer; kwargs...)
impulse(var::VARProcess, ishock::Union{Integer, AbstractRange}, nhorz::Integer; kwargs...)
```

Same as `impulse!`

, but allocates an array for storing the results. The number of horizons needs to be specified explicitly with `nhorz`

.

`AutoregressiveModels.impulse`

— Method```
impulse(r::VectorAutoregression, ε0::AbstractVecOrMat, nhorz::Integer; kwargs...)
impulse(r::VectorAutoregression, ishock::Union{Integer, AbstractRange}, nhorz::Integer; kwargs...)
```

Same as `impulse!`

, but allocates an array for storing the results. The number of horizons needs to be specified explicitly with `nhorz`

.

`AutoregressiveModels.isstable`

— Function`isstable(var::VARProcess, offset::Real=0)`

Return a Boolean value indicating whether `var`

is stable, optionally with the comparison adjusted by `offset`

for some tolerance.

`AutoregressiveModels.residchol`

— Method`residchol(r::VectorAutoregression)`

Return the lower-triangular matrix from Cholesky factorization of the residual variance-covariance matrix.

`AutoregressiveModels.residvcov`

— Function`residvcov(r::VectorAutoregression, id1, id2=id1)`

Return the variance-covariance estimate between the reduced-form errors from equation `id1`

and `id2`

. The equations are indexed by the outcome variables, which can be variable names of type `Symbol`

or integer indices.

`AutoregressiveModels.residvcov`

— Method`residvcov(r::VectorAutoregression)`

Return the variance-covariance matrix of the residuals.

`AutoregressiveModels.simulate`

— Function`simulate(εs::AbstractArray, var::VARProcess, Y0=nothing; nlag::Integer=arorder(var))`

Same as `simulate!`

, but makes a copy of `εs`

for results and hence does not overwrite `εs`

.

`AutoregressiveModels.simulate`

— Function`simulate(εs::AbstractArray, arma::ARMAProcess, y0=nothing)`

Same as `simulate!`

, but allocates an array for results.

`AutoregressiveModels.simulate`

— Function`simulate(εs::AbstractArray, r::VectorAutoregression, Y0=nothing; kwargs...)`

Same as `simulate!`

, but makes a copy of `εs`

for results and hence does not overwrite `εs`

.

`AutoregressiveModels.simulate!`

— Function`simulate!(εs::AbstractArray, r::VectorAutoregression, Y0=nothing; kwargs...)`

Simulate the `VARProcess`

with the coefficient estimates in `r`

using the shocks specified in `εs`

and initial values `Y0`

. Results are stored by overwriting `εs`

in-place. If `Y0`

is `nothing`

or does not contain enough lags, zeros are used. See also `simulate`

and `impulse!`

.

**Keywords**

`nlag::Integer=arorder(var)`

: the number of lags from`var`

used for simulations.

`AutoregressiveModels.simulate!`

— Function`AutoregressiveModels.simulate!`

— Function`simulate!(εs::AbstractArray, var::VARProcess, Y0=nothing; kwargs...)`

Simulate the `var`

process using the shocks specified in `εs`

and initial values `Y0`

. Results are stored by overwriting `εs`

in-place. If `Y0`

is `nothing`

or does not contain enough lags, zeros are used. See also `simulate`

and `impulse!`

.

**Keywords**

`nlag::Integer=arorder(var)`

: the number of lags from`var`

used for simulations.

`StatsAPI.coef`

— Function`coef(r::VectorAutoregression, yid, xid, lag::Integer=1)`

Return the coefficient estimate of `r`

for variable `yid`

with respect to variable `xid`

with lag `lag`

. `yid`

and `xid`

can be variable names of type `Symbol`

or integer indices. Unless `var.nocons`

is `true`

, the intercept term is always named `:constant`

and has an index of `1`

.

`StatsAPI.fit!`

— Method`StatsAPI.fit`

— Method`fit(::Type{<:Factor}, data, names, fonames, nfac::Integer; kwargs...)`

Fit a factor model with `nfac`

factors using variables indexed by `names`

from a `Tables.jl`

-compatible `data`

table. Factors that are observed are specified with `fonames`

as indices of columns from `data`

. R-squared for each variable is computed based on standardized data with zero mean and unit standard deviation. See also `Factor`

and `fit!`

.

**Keywords**

`subset::Union{BitVector, Nothing}=nothing`

: subset of`data`

to be used for estimation.`TF::Type=Float64`

: numeric type used for estimation.`svdalg::Algorithm=DivideAndConquer()`

: algorithm for singular value decomposition.`maxiter::Integer=10000`

: maximum number of iterations; only relevant when the model involves both observed and unobserved factors.`tol::Real=1e-8`

: tolerance level for convergence; only relevant when the model involves both observed and unobserved factors.

**Reference**

**Stock, James H. and Mark W. Watson.** 2016. "Chapter 8–-Dynamic Factor Models, Factor-Augmented Vector Autoregressions, and Structural Vector Autoregressions in Macroeconomics." In *Handbook of Macroeconomics*, Vol. 2A, edited by John B. Taylor and Harald Uhlig, 415–525. Amsterdam: Elsevier.

`StatsAPI.fit`

— Method`fit(::Type{<:VARProcess}, data, names, nlag::Integer; kwargs...)`

Estimate vector autoregression with ordinary least squares using `nlag`

lags of variables indexed by `names`

from a `Tables.jl`

-compatible `data`

table.

**Keywords**

`subset::Union{BitVector, Nothing}=nothing`

: subset of`data`

to be used for estimation.`choleskyresid::Bool=false`

: conduct Cholesky factorization for the residual variance-covariance matrix.`adjust_dofr::Bool=true`

: adjust the degrees of freedom when computing the residual variance-covariance matrix.`nocons::Bool=false`

: do not include an intercept term in the estimation.`TF::Type=Float64`

: numeric type used for estimation.