Compute VAR Companion Matrix
Arguments
- beta
Coefficient matrix. Dimensions: (Np+c+M) x N, where N is the number of variables, p is the lag order, c is 1 if intercept included (0 otherwise), and M is the number of exogenous variables
- c
Integer indicator for intercept (1 if intercept included, 0 otherwise)
- p
Integer lag order of the VAR model
Details
This function constructs the companion form matrix of a VAR(p) model. The companion matrix representation allows the VAR(p) to be written as a VAR(1) system, which is useful for various computations including impulse response functions and forecasting.
When exogenous variables are present, they are excluded from the companion matrix as they do not have a dynamic feedback structure in the VAR system.
The companion matrix has the structure: $$ \begin{bmatrix} A_1 & A_2 & \cdots & A_{p-1} & A_p \\ I_N & 0 & \cdots & 0 & 0 \\ 0 & I_N & \cdots & 0 & 0 \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & \cdots & I_N & 0 \end{bmatrix} $$
Examples
if (FALSE) { # \dontrun{
# VAR(2) model with 3 variables, no intercept
beta <- matrix(rnorm(18), 6, 3) # 6 rows (2*3), 3 columns
result <- fcompanionMatrix(beta, c = 0, p = 2)
# VAR(2) model with 3 variables, with intercept and 2 exogenous variables
beta_int <- matrix(rnorm(27), 9, 3) # 9 rows (2*3+1+2), 3 columns
result <- fcompanionMatrix(beta_int, c = 1, p = 2)
} # }
