Skip to contents

Extract properties for scalar and vector of seasons forms of multi-filters.

Usage

mf_order(x, i = "max", form = "pc", perm)
mf_period(x)
mf_poles(x, blocks = FALSE)
mf_VSform(x, first = 1, form = "U", perm)

Arguments

x

the filter, an object of class "MultiFilter".

i

index, integer vector or a string.

first

the first season of the year.

form

the form of the filter to which the result refers, one of "pc", "I", "U", or "L", see Details.

perm

permutation of the seasons within the year.

blocks

request lengths of Jordan chains.

Value

For mf_order, if i = "max" a positive integer, otherwise a vector of positive integers.

For mf_period the period of the filter, a positive integer.

For mf_poles, if blocks = FALSE, a vector of the eigenvalues of the associated multi-companion matrix, each eigenvalue repeated according to its algebraic multiplicity. If blocks = TRUE, a 2-column matrix with the eigenvalues in the first column and the lengths of the Jordan chains in the second. There is one row for each chain (i.e. multiple eigenvalues are repeated according to their geometric multiplicity).

For mf_VSform a list with components:

Phi0

the zero lag coefficient, a matrix,

Phi

the remaining coefficients, a matrix,

Phi0inv

(form=="I" only) the inverse of the zero lag coefficient matrix of the vs-form, a matrix. (TODO: the name of this component is misleading since in the case form = "I" Phi0 is the identity matrix and Phi0inv is not equal to the inverse of Phi0.)

Details

With the default i=="max" the function mf_order returns a single number, the order of the filter in the representation requested by form. The orders of the components may be obtained with the setting i=="all" which gives a vector whose j-th element is the order of the j-th component of the filter. A subset of these may be obtained with numeric i which is treated as standard index vector. Values for i other than the default are meaningful mainly for form="pc".

mf_VSform arranges the filter coefficients in one of the vector of seasons forms (todo: cite me). The component Phi of the result is a matrix obtained by putting the coefficient matrices next to each other, [A1 ... Ad]. If perm is provided, then the result is the same for "U" and "L".

mf_VSform is called implicitly by the subscripting operation ("[") when needed, it is more flexible and is recommended for general use.

For the vector forms ("I", "U", and "L") the argument perm specifies the arrangement of the components of the filter in that form. For the I- and U-forms the default is mf_period(x):1, for the L-form it is 1:mf_period(x).

Currently perm may take on values that can be obtained from the default by rotation, e.g. if the period is 4, perm may be one of (4,3,2,1), (1,4,3,2), (2,1,4,3), (3,2,1,4) for the U-form, and (1,2,3,4), (4,1,2,3), (3,4,1,2), (2,3,4,1) for the L-form. Other permutations may be usefull in some situations but may not result in U- or L- forms (without further transformations). For I-form any permutation should be permissible when implemented (todo:).

For mf_order the argument perm affects the computation only, not the ordering in the result. The result (if vector) is not permuted unless the argument i asks for this. For mf_VSform however such a behaviour would be very peculiar and the rows of the result are for the permuted seasons. In short, the i-th element of the result of mf_order (if vector) gives the order (in the requested form) of the i-th season but the i-th row of any of the matrices returned by mf_VSform depends on perm and form.

Note: the terminology here reflects application to pc processes, probably should be made more neutral in this respect.

todo: (2013-03-26) mf_order seems unfinished.

Author

Georgi N. Boshnakov

References

Boshnakov GN (2002). “Multi-companion matrices.” Linear Algebra Appl., 354, 53--83. ISSN 0024-3795, doi:10.1016/S0024-3795(01)00475-X .

Boshnakov GN, Iqelan BM (2009). “Generation of time series models with given spectral properties.” J. Time Series Anal., 30(3), 349--368. ISSN 0143-9782, doi:10.1111/j.1467-9892.2009.00617.x .

See also

MultiFilter and the examples there, mcStable

Examples

## simulate a 3x3 2-companion matrix
##  and turn it into a multi-filter
(m <- mCompanion("sim", dim=3, mo=2))
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]       [,2]       [,3]
#> [1,] -1.167474 0.08311389 -0.7866420
#> [2,]  0.539589 0.30928074 -0.6270878
#> [3,]  1.000000 0.00000000  0.0000000
(flt <- new("MultiFilter", mc = m ))
#> An object of class "MultiFilter"
#> Slot "mc":
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]       [,2]       [,3]
#> [1,] -1.167474 0.08311389 -0.7866420
#> [2,]  0.539589 0.30928074 -0.6270878
#> [3,]  1.000000 0.00000000  0.0000000
#> 
#> Slot "coef":
#>          [,1]       [,2]       [,3]
#> [1,] 0.539589  0.3092807 -0.6270878
#> [2,] 1.254437 -1.8443546 -0.3048592
#> 
#> Slot "order":
#> [1] 3 3
#> 
#> Slot "sign":
#> [1] 1
#> 
mf_period(flt)
#> [1] 2
mf_poles(flt)
#> [1]  0.2757203+0.0000000i -0.5669570+0.6098526i -0.5669570-0.6098526i
abs(mf_poles(flt))
#> [1] 0.2757203 0.8326826 0.8326826
mf_VSform(flt,form="U")
#> $Phi0
#>      [,1]      [,2]
#> [1,]    1 -1.254437
#> [2,]    0  1.000000
#> 
#> $Phi
#>           [,1]       [,2]       [,3] [,4]
#> [1,] -1.844355 -0.3048592  0.0000000    0
#> [2,]  0.539589  0.3092807 -0.6270878    0
#> 
mf_VSform(flt,form="L")
#> $Phi0
#> 2 x 2 Matrix of class "dgeMatrix"
#>           [,1] [,2]
#> [1,]  1.000000    0
#> [2,] -1.254437    1
#> 
#> $Phi
#>            [,1]      [,2] [,3]       [,4]
#> [1,]  0.3092807  0.539589    0 -0.6270878
#> [2,] -0.3048592 -1.844355    0  0.0000000
#> 
mf_VSform(flt,form="I")
#> $Phi0
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> 
#> $Phi
#>           [,1]       [,2]       [,3] [,4]
#> [1,] -1.167474 0.08311389 -0.7866420    0
#> [2,]  0.539589 0.30928074 -0.6270878    0
#> 
#> $Phi0inv
#>      [,1]     [,2]
#> [1,]    1 1.254437
#> [2,]    0 1.000000
#> 

## simulate a pc filter (2 seasons)
## and turn it into a multi-filter object
(rfi <- sim_pcfilter(2, 3))
#> $eigval
#> [1] 0.2239588+0.0000000i 0.1121855+0.5753133i 0.1121855-0.5753133i
#> 
#> $len.block
#> [1] 1 1 1
#> 
#> $mo
#> [1] 2
#> 
#> $eigvec
#>               [,1]                  [,2]                  [,3]
#> [1,] 0.03482878+0i -0.2503675-0.0836292i -0.2503675+0.0836292i
#> [2,] 0.27134751+0i -0.2227620+0.8053278i -0.2227620-0.8053278i
#> [3,] 0.15551428+0i -0.2217899+0.3919358i -0.2217899-0.3919358i
#> 
#> $co
#>              [,1]                  [,2]                  [,3]
#> [1,] 0.2713475+0i -0.2227620+0.8053278i -0.2227620-0.8053278i
#> [2,] 0.1555143+0i -0.2217899+0.3919358i -0.2217899-0.3919358i
#> 
#> $mo.col
#> [1] 3
#> 
#> $mat
#>           [,1]          [,2]          [,3]
#> [1,]  8.537779  1.062345e+01 -2.039817e+01
#> [2,] -4.618236 -8.089450e+00  1.553986e+01
#> [3,]  1.000000 -5.236469e-18  3.393424e-29
#> 
#> $pcfilter
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860070
#> [2,] -1.312635  2.47572  0.004951508
#> 
(flt <- new("MultiFilter", coef = rfi$pcfilter))
#> An object of class "MultiFilter"
#> Slot "mc":
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]     [,2]      [,3]
#>       8.537779 10.62345 -20.39817
#> wrk2 -4.618236 -8.08945  15.53986
#>       1.000000  0.00000   0.00000
#> 
#> Slot "coef":
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860070
#> [2,] -1.312635  2.47572  0.004951508
#> 
#> Slot "order":
#> [1] 3 3
#> 
#> Slot "sign":
#> [1] 1
#> 
mf_period(flt)
#> [1] 2
mf_poles(flt)
#> [1] 0.1121855+0.5753133i 0.1121855-0.5753133i 0.2239588+0.0000000i
abs(mf_poles(flt))
#> [1] 0.5861493 0.5861493 0.2239588
mf_VSform(flt, form="U")
#> $Phi0
#>      [,1]     [,2]
#> [1,]    1 1.312635
#> [2,]    0 1.000000
#> 
#> $Phi
#>           [,1]         [,2]     [,3] [,4]
#> [1,]  2.475720  0.004951508  0.00000    0
#> [2,] -4.618236 -8.089449553 15.53986    0
#> 
mf_VSform(flt, form="I")
#> $Phi0
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> 
#> $Phi
#>           [,1]     [,2]      [,3] [,4]
#> [1,]  8.537779 10.62345 -20.39817    0
#> [2,] -4.618236 -8.08945  15.53986    0
#> 
#> $Phi0inv
#>      [,1]      [,2]
#> [1,]    1 -1.312635
#> [2,]    0  1.000000
#> 
mf_VSform(flt, form="L")
#> $Phi0
#> 2 x 2 Matrix of class "dgeMatrix"
#>          [,1] [,2]
#> [1,] 1.000000    0
#> [2,] 1.312635    1
#> 
#> $Phi
#>              [,1]      [,2] [,3]     [,4]
#> [1,] -8.089449553 -4.618236    0 15.53986
#> [2,]  0.004951508  2.475720    0  0.00000
#> 

## indexing can be used  to extract filter coefficients
flt[]
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860070
#> [2,] -1.312635  2.47572  0.004951508
flt[1,]
#>           [,1]     [,2]     [,3]
#> [1,] -4.618236 -8.08945 15.53986
## the rest are some checks of numerical performance.
rfi
#> $eigval
#> [1] 0.2239588+0.0000000i 0.1121855+0.5753133i 0.1121855-0.5753133i
#> 
#> $len.block
#> [1] 1 1 1
#> 
#> $mo
#> [1] 2
#> 
#> $eigvec
#>               [,1]                  [,2]                  [,3]
#> [1,] 0.03482878+0i -0.2503675-0.0836292i -0.2503675+0.0836292i
#> [2,] 0.27134751+0i -0.2227620+0.8053278i -0.2227620-0.8053278i
#> [3,] 0.15551428+0i -0.2217899+0.3919358i -0.2217899-0.3919358i
#> 
#> $co
#>              [,1]                  [,2]                  [,3]
#> [1,] 0.2713475+0i -0.2227620+0.8053278i -0.2227620-0.8053278i
#> [2,] 0.1555143+0i -0.2217899+0.3919358i -0.2217899-0.3919358i
#> 
#> $mo.col
#> [1] 3
#> 
#> $mat
#>           [,1]          [,2]          [,3]
#> [1,]  8.537779  1.062345e+01 -2.039817e+01
#> [2,] -4.618236 -8.089450e+00  1.553986e+01
#> [3,]  1.000000 -5.236469e-18  3.393424e-29
#> 
#> $pcfilter
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860070
#> [2,] -1.312635  2.47572  0.004951508
#> 
rfi$mat==0
#>       [,1]  [,2]  [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE

zapsmall(rfi$mat)
#>           [,1]     [,2]      [,3]
#> [1,]  8.537779 10.62345 -20.39817
#> [2,] -4.618236 -8.08945  15.53986
#> [3,]  1.000000  0.00000   0.00000
mCompanion(zapsmall(rfi$mat))
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]     [,2]      [,3]
#> [1,]  8.537779 10.62345 -20.39817
#> [2,] -4.618236 -8.08945  15.53986
#> [3,]  1.000000  0.00000   0.00000
unclass(mCompanion(zapsmall(rfi$mat)))
#> <S4 Type Object>
#> attr(,"xtop")
#>           [,1]     [,2]      [,3]
#> [1,]  8.537779 10.62345 -20.39817
#> [2,] -4.618236 -8.08945  15.53986
#> attr(,"mo")
#> [1] 2
#> attr(,"ido")
#> [1] 1
#> attr(,"mo.col")
#> [1] 3
#> attr(,"pad")
#> An object of class "objectPad"
#> [[1]]
#> function (x) 
#> {
#>     if (missing(x)) 
#>         sklad
#>     else sklad[[x]]
#> }
#> <bytecode: 0x562d3236e2d0>
#> <environment: 0x562d3a2390e8>
#> 
#> [[2]]
#> function (x, value) 
#> {
#>     sklad[[x]] <<- value
#> }
#> <bytecode: 0x562d32371db8>
#> <environment: 0x562d3a2390e8>
#> 
#> attr(,"x")
#> [1]   8.537779  -4.618236   1.000000  10.623448  -8.089450   0.000000 -20.398167
#> [8]  15.539860   0.000000
#> attr(,"Dim")
#> [1] 3 3
#> attr(,"Dimnames")
#> attr(,"Dimnames")[[1]]
#> NULL
#> 
#> attr(,"Dimnames")[[2]]
#> NULL
#> 
#> attr(,"factors")
#> list()
unclass(mCompanion(rfi$mat))
#> <S4 Type Object>
#> attr(,"xtop")
#>           [,1]          [,2]          [,3]
#> [1,]  8.537779  1.062345e+01 -2.039817e+01
#> [2,] -4.618236 -8.089450e+00  1.553986e+01
#> [3,]  1.000000 -5.236469e-18  3.393424e-29
#> attr(,"mo")
#> [1] 3
#> attr(,"ido")
#> [1] 0
#> attr(,"mo.col")
#> [1] 3
#> attr(,"pad")
#> An object of class "objectPad"
#> [[1]]
#> function (x) 
#> {
#>     if (missing(x)) 
#>         sklad
#>     else sklad[[x]]
#> }
#> <bytecode: 0x562d3236e2d0>
#> <environment: 0x562d3a2daab0>
#> 
#> [[2]]
#> function (x, value) 
#> {
#>     sklad[[x]] <<- value
#> }
#> <bytecode: 0x562d32371db8>
#> <environment: 0x562d3a2daab0>
#> 
#> attr(,"x")
#> [1]  8.537779e+00 -4.618236e+00  1.000000e+00  1.062345e+01 -8.089450e+00
#> [6] -5.236469e-18 -2.039817e+01  1.553986e+01  3.393424e-29
#> attr(,"Dim")
#> [1] 3 3
#> attr(,"Dimnames")
#> attr(,"Dimnames")[[1]]
#> NULL
#> 
#> attr(,"Dimnames")[[2]]
#> NULL
#> 
#> attr(,"factors")
#> list()

flt1 <- new("MultiFilter", mc = mCompanion(zapsmall(rfi$mat)))
flt2 <- flt

flt1[]
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860000
#> [2,] -1.312635  2.47572  0.004951306
flt2[]
#>           [,1]     [,2]         [,3]
#> [1,] -4.618236 -8.08945 15.539860070
#> [2,] -1.312635  2.47572  0.004951508
flt1[] - flt2[]
#>              [,1]          [,2]          [,3]
#> [1,] 7.655759e-09 -4.466931e-07 -7.011723e-08
#> [2,] 7.352960e-09 -2.523764e-07 -2.018943e-07
rfi$pcfilter - rfi$mat[1:2,]
#>            [,1]      [,2]      [,3]
#> [1,] -13.156015 -18.71290  35.93803
#> [2,]   3.305601  10.56517 -15.53491

mf_poles(flt1)
#> [1] 0.1121897+0.5753125i 0.1121897-0.5753125i 0.2239496+0.0000000i
abs(mf_poles(flt1))
#> [1] 0.5861493 0.5861493 0.2239496

svd(rfi$mat)
#> $d
#> [1] 30.465795602  1.710668365  0.001476407
#> 
#> $u
#>             [,1]       [,2]       [,3]
#> [1,] -0.80477392 -0.4892232 -0.3361541
#> [2,]  0.59349091 -0.6730752 -0.4412916
#> [3,] -0.01036694 -0.5546444  0.8320229
#> 
#> $v
#>            [,1]       [,2]         [,3]
#> [1,] -0.3158372 -0.9488126  0.001228405
#> [2,] -0.4382124  0.1447219 -0.887144571
#> [3,]  0.8415562 -0.2807315 -0.461489980
#> 
rcond(rfi$mat)
#> [1] 3.656592e-05
Matrix::rcond(Matrix::Matrix(rfi$mat),"O")
#> [1] 3.656592e-05
1/Matrix::rcond(Matrix::Matrix(rfi$mat),"O")
#> [1] 27347.87