Extract properties of multi-filters
mf_VSform.RdExtract 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- Phi0invis 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.
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,] -0.8724184  0.002926448 -0.003320518
#> [2,] -0.5854078 -0.002629503 -0.003003257
#> [3,]  1.0000000  0.000000000  0.000000000
(flt <- new("MultiFilter", mc = m ))
#> An object of class "MultiFilter"
#> Slot "mc":
#> 3 x 3 Matrix of class "MultiCompanion"
#>            [,1]         [,2]         [,3]
#> [1,] -0.8724184  0.002926448 -0.003320518
#> [2,] -0.5854078 -0.002629503 -0.003003257
#> [3,]  1.0000000  0.000000000  0.000000000
#> 
#> Slot "coef":
#>            [,1]         [,2]         [,3]
#> [1,] -0.5854078 -0.002629503 -0.003003257
#> [2,]  1.1056390 -0.225168749  0.005833729
#> 
#> Slot "order":
#> [1] 3 3
#> 
#> Slot "sign":
#> [1] 1
#> 
mf_period(flt)
#> [1] 2
mf_poles(flt)
#> [1] -0.866615703+0.000000000i -0.004216109+0.001562437i
#> [3] -0.004216109-0.001562437i
abs(mf_poles(flt))
#> [1] 0.866615703 0.004496308 0.004496308
mf_VSform(flt,form="U")
#> $Phi0
#>      [,1]      [,2]
#> [1,]    1 -1.105639
#> [2,]    0  1.000000
#> 
#> $Phi
#>            [,1]         [,2]         [,3] [,4]
#> [1,] -0.2251687  0.005833729  0.000000000    0
#> [2,] -0.5854078 -0.002629503 -0.003003257    0
#> 
mf_VSform(flt,form="L")
#> $Phi0
#> 2 x 2 Matrix of class "dgeMatrix"
#>           [,1] [,2]
#> [1,]  1.000000    0
#> [2,] -1.105639    1
#> 
#> $Phi
#>              [,1]       [,2] [,3]         [,4]
#> [1,] -0.002629503 -0.5854078    0 -0.003003257
#> [2,]  0.005833729 -0.2251687    0  0.000000000
#> 
mf_VSform(flt,form="I")
#> $Phi0
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> 
#> $Phi
#>            [,1]         [,2]         [,3] [,4]
#> [1,] -0.8724184  0.002926448 -0.003320518    0
#> [2,] -0.5854078 -0.002629503 -0.003003257    0
#> 
#> $Phi0inv
#>      [,1]     [,2]
#> [1,]    1 1.105639
#> [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.8561322+0.000000i -0.6694317-0.528399i -0.6694317+0.528399i
#> 
#> $len.block
#> [1] 1 1 1
#> 
#> $mo
#> [1] 2
#> 
#> $eigvec
#>               [,1]                   [,2]                   [,3]
#> [1,]  0.2116522+0i  0.2609460+0.08516489i  0.2609460-0.08516489i
#> [2,]  0.4848028+0i  0.4015332+0.86408690i  0.4015332-0.86408690i
#> [3,] -0.2472191+0i -0.3020393+0.11118738i -0.3020393-0.11118738i
#> 
#> $co
#>               [,1]                  [,2]                  [,3]
#> [1,]  0.4848028+0i  0.4015332+0.8640869i  0.4015332-0.8640869i
#> [2,] -0.2472191+0i -0.3020393+0.1111874i -0.3020393-0.1111874i
#> 
#> $mo.col
#> [1] 3
#> 
#> $mat
#>           [,1]          [,2]          [,3]
#> [1,]  1.258119 -4.651031e-01  8.979999e-01
#> [2,] 15.299873 -3.453115e+00  8.005966e+00
#> [3,]  1.000000  1.848893e-32 -8.439850e-32
#> 
#> $pcfilter
#>            [,1]       [,2]        [,3]
#> [1,] 15.2998730 -3.4531148  8.00596581
#> [2,]  0.1121663 -0.4580115 -0.07777985
#> 
(flt <- new("MultiFilter", coef = rfi$pcfilter))
#> An object of class "MultiFilter"
#> Slot "mc":
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]       [,2]      [,3]
#>       1.258119 -0.4651031 0.8979999
#> wrk2 15.299873 -3.4531148 8.0059658
#>       1.000000  0.0000000 0.0000000
#> 
#> Slot "coef":
#>            [,1]       [,2]        [,3]
#> [1,] 15.2998730 -3.4531148  8.00596581
#> [2,]  0.1121663 -0.4580115 -0.07777985
#> 
#> Slot "order":
#> [1] 3 3
#> 
#> Slot "sign":
#> [1] 1
#> 
mf_period(flt)
#> [1] 2
mf_poles(flt)
#> [1] -0.8561322+0.000000i -0.6694317+0.528399i -0.6694317-0.528399i
abs(mf_poles(flt))
#> [1] 0.8561322 0.8528448 0.8528448
mf_VSform(flt, form="U")
#> $Phi0
#>      [,1]       [,2]
#> [1,]    1 -0.1121663
#> [2,]    0  1.0000000
#> 
#> $Phi
#>            [,1]        [,2]     [,3] [,4]
#> [1,] -0.4580115 -0.07777985 0.000000    0
#> [2,] 15.2998730 -3.45311477 8.005966    0
#> 
mf_VSform(flt, form="I")
#> $Phi0
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> 
#> $Phi
#>           [,1]       [,2]      [,3] [,4]
#> [1,]  1.258119 -0.4651031 0.8979999    0
#> [2,] 15.299873 -3.4531148 8.0059658    0
#> 
#> $Phi0inv
#>      [,1]      [,2]
#> [1,]    1 0.1121663
#> [2,]    0 1.0000000
#> 
mf_VSform(flt, form="L")
#> $Phi0
#> 2 x 2 Matrix of class "dgeMatrix"
#>            [,1] [,2]
#> [1,]  1.0000000    0
#> [2,] -0.1121663    1
#> 
#> $Phi
#>             [,1]       [,2] [,3]     [,4]
#> [1,] -3.45311477 15.2998730    0 8.005966
#> [2,] -0.07777985 -0.4580115    0 0.000000
#> 
## indexing can be used  to extract filter coefficients
flt[]
#>            [,1]       [,2]        [,3]
#> [1,] 15.2998730 -3.4531148  8.00596581
#> [2,]  0.1121663 -0.4580115 -0.07777985
flt[1,]
#>          [,1]      [,2]     [,3]
#> [1,] 15.29987 -3.453115 8.005966
## the rest are some checks of numerical performance.
rfi
#> $eigval
#> [1] -0.8561322+0.000000i -0.6694317-0.528399i -0.6694317+0.528399i
#> 
#> $len.block
#> [1] 1 1 1
#> 
#> $mo
#> [1] 2
#> 
#> $eigvec
#>               [,1]                   [,2]                   [,3]
#> [1,]  0.2116522+0i  0.2609460+0.08516489i  0.2609460-0.08516489i
#> [2,]  0.4848028+0i  0.4015332+0.86408690i  0.4015332-0.86408690i
#> [3,] -0.2472191+0i -0.3020393+0.11118738i -0.3020393-0.11118738i
#> 
#> $co
#>               [,1]                  [,2]                  [,3]
#> [1,]  0.4848028+0i  0.4015332+0.8640869i  0.4015332-0.8640869i
#> [2,] -0.2472191+0i -0.3020393+0.1111874i -0.3020393-0.1111874i
#> 
#> $mo.col
#> [1] 3
#> 
#> $mat
#>           [,1]          [,2]          [,3]
#> [1,]  1.258119 -4.651031e-01  8.979999e-01
#> [2,] 15.299873 -3.453115e+00  8.005966e+00
#> [3,]  1.000000  1.848893e-32 -8.439850e-32
#> 
#> $pcfilter
#>            [,1]       [,2]        [,3]
#> [1,] 15.2998730 -3.4531148  8.00596581
#> [2,]  0.1121663 -0.4580115 -0.07777985
#> 
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,]  1.258119 -0.465103 0.898000
#> [2,] 15.299873 -3.453115 8.005966
#> [3,]  1.000000  0.000000 0.000000
mCompanion(zapsmall(rfi$mat))
#> 3 x 3 Matrix of class "MultiCompanion"
#>           [,1]      [,2]     [,3]
#> [1,]  1.258119 -0.465103 0.898000
#> [2,] 15.299873 -3.453115 8.005966
#> [3,]  1.000000  0.000000 0.000000
unclass(mCompanion(zapsmall(rfi$mat)))
#> <S4 Type Object>
#> attr(,"xtop")
#>           [,1]      [,2]     [,3]
#> [1,]  1.258119 -0.465103 0.898000
#> [2,] 15.299873 -3.453115 8.005966
#> 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: 0x556ac6802690>
#> <environment: 0x556ac516d238>
#> 
#> [[2]]
#> function (x, value) 
#> {
#>     sklad[[x]] <<- value
#> }
#> <bytecode: 0x556ac6802348>
#> <environment: 0x556ac516d238>
#> 
#> attr(,"x")
#> [1]  1.258119 15.299873  1.000000 -0.465103 -3.453115  0.000000  0.898000
#> [8]  8.005966  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,]  1.258119 -4.651031e-01  8.979999e-01
#> [2,] 15.299873 -3.453115e+00  8.005966e+00
#> [3,]  1.000000  1.848893e-32 -8.439850e-32
#> 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: 0x556ac6802690>
#> <environment: 0x556ac4fddbd0>
#> 
#> [[2]]
#> function (x, value) 
#> {
#>     sklad[[x]] <<- value
#> }
#> <bytecode: 0x556ac6802348>
#> <environment: 0x556ac4fddbd0>
#> 
#> attr(,"x")
#> [1]  1.258119e+00  1.529987e+01  1.000000e+00 -4.651031e-01 -3.453115e+00
#> [6]  1.848893e-32  8.979999e-01  8.005966e+00 -8.439850e-32
#> 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,] 15.2998730 -3.4531150  8.00596600
#> [2,]  0.1121664 -0.4580119 -0.07777969
flt2[]
#>            [,1]       [,2]        [,3]
#> [1,] 15.2998730 -3.4531148  8.00596581
#> [2,]  0.1121663 -0.4580115 -0.07777985
flt1[] - flt2[]
#>               [,1]          [,2]         [,3]
#> [1,] -3.226337e-08 -2.294150e-07 1.939486e-07
#> [2,]  1.112971e-08 -4.308878e-07 1.610511e-07
rfi$pcfilter - rfi$mat[1:2,]
#>           [,1]      [,2]      [,3]
#> [1,]  14.04175 -2.988012  7.107966
#> [2,] -15.18771  2.995103 -8.083746
mf_poles(flt1)
#> [1] -0.8561319+0.0000000i -0.6694320+0.5283973i -0.6694320-0.5283973i
abs(mf_poles(flt1))
#> [1] 0.8561319 0.8528440 0.8528440
svd(rfi$mat)
#> $d
#> [1] 17.70301434  0.55721813  0.06312601
#> 
#> $u
#>             [,1]         [,2]       [,3]
#> [1,] -0.08995939  0.461967934  0.8823225
#> [2,] -0.99473536  0.001981062 -0.1024580
#> [3,] -0.04908024 -0.886894415  0.4593576
#> 
#> $v
#>            [,1]       [,2]        [,3]
#> [1,] -0.8688681 -0.4941936  0.02899742
#> [2,]  0.1963946 -0.3978757 -0.89617192
#> [3,] -0.4544198  0.7729603 -0.44275845
#> 
rcond(rfi$mat)
#> [1] 0.003094968
Matrix::rcond(Matrix::Matrix(rfi$mat),"O")
#> [1] 0.003094968
1/Matrix::rcond(Matrix::Matrix(rfi$mat),"O")
#> [1] 323.1051