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, C0 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)=c0+c1L++cpLp

returns a matrix of the form

[ϕ1100ϕ201001ϕn000]

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

If the coefficients provided are scalars (c0,c1,,cp), then the companion matrix is an n×n matrix formed with the elements in the first column defined as ϕi=cic0,i1,,p.

If the coefficients provided are matrices (C0,C1,,Cp), each of shape (m,m), then the companion matrix is an nm×nm matrix formed with the elements in the first column defined as ϕi=C01Ci,i1,,p.

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

yt=a1yt1++apytp+εt

This can be rewritten as:

(1a1LapLp)yt=εt(1+c1L++cpLp)yt=εtc(L)yt=εt

The coefficients from this form are defined to be ci=ai, and it is the ci coefficients that this function expects to be provided.