statsmodels.tsa.statespace.tools.companion_matrix

statsmodels.tsa.statespace.tools.companion_matrix(polynomial)[source]

Create a companion matrix

Parameters:
polynomialarray_like or list

If an iterable, interpreted as the coefficients of the polynomial from which to form the companion matrix. Polynomial coefficients are in order of increasing degree, and may be either scalars (as in an AR(p) model) or coefficient matrices (as in a VAR(p) model). If an integer, it is interpreted as the size of a companion matrix of a scalar polynomial, where the polynomial coefficients are initialized to zeros. If a matrix polynomial is passed, \(C_0\) may be set to the scalar value 1 to indicate an identity matrix (doing so will improve the speed of the companion matrix creation).

Returns:
companion_matrixndarray

Notes

Given coefficients of a lag polynomial of the form:

\[c(L) = c_0 + c_1 L + \dots + c_p L^p\]

returns a matrix of the form

\[\begin{split}\begin{bmatrix} \phi_1 & 1 & 0 & \cdots & 0 \\ \phi_2 & 0 & 1 & & 0 \\ \vdots & & & \ddots & 0 \\ & & & & 1 \\ \phi_n & 0 & 0 & \cdots & 0 \\ \end{bmatrix}\end{split}\]

where some or all of the \(\phi_i\) may be non-zero (if polynomial is None, then all are equal to zero).

If the coefficients provided are scalars \((c_0, c_1, \dots, c_p)\), then the companion matrix is an \(n \times n\) matrix formed with the elements in the first column defined as \(\phi_i = -\frac{c_i}{c_0}, i \in 1, \dots, p\).

If the coefficients provided are matrices \((C_0, C_1, \dots, C_p)\), each of shape \((m, m)\), then the companion matrix is an \(nm \times nm\) matrix formed with the elements in the first column defined as \(\phi_i = -C_0^{-1} C_i', i \in 1, \dots, p\).

It is important to understand the expected signs of the coefficients. A typical AR(p) model is written as:

\[y_t = a_1 y_{t-1} + \dots + a_p y_{t-p} + \varepsilon_t\]

This can be rewritten as:

\[\begin{split}(1 - a_1 L - \dots - a_p L^p )y_t = \varepsilon_t \\ (1 + c_1 L + \dots + c_p L^p )y_t = \varepsilon_t \\ c(L) y_t = \varepsilon_t\end{split}\]

The coefficients from this form are defined to be \(c_i = - a_i\), and it is the \(c_i\) coefficients that this function expects to be provided.


Last update: Nov 14, 2024