Get the model order and other properties of models
modelOrder.Rd
Get the model order and other properties of models.
Usage
modelOrder(object, convention, ...)
modelPoly(object, convention, ...)
modelPolyCoef(object, convention, lag_0 = TRUE, ...)
Arguments
- object
a model object.
- convention
convention.
- lag_0
if TRUE include lag_0 coef, otherwise drop it.
- ...
further arguments for methods.
Details
These functions return the requested quantity, optionally requesting
the returned value to follow a specific convention, see also
modelCoef
.
When called with one argument, these functions return corresponding property in the native format for the object's class.
Argument convention
requests the result in some other
format. The mental model is that the returned value is as if the
object was first converted to the class specified by convention
and then the property extracted or computed. Normally, the object is
not actually converted to that class. one obvious reason is efficiency
but it may also not be possible, for example if argument
convention
is the name of a virtual class.
For example, the order of a seasonal SARIMA model is specified by
several numbers. The call modelOrder(object)
returns it as a
list with components ar, ma, sar, sma, iorder, siorder and nseasons.
For some computations all that is needed are the overall AR and MA
orders obtained by multiplying out the AR-like and MA-like terms in
the model.
The result would be an ARMA filter and could be requested by
modelOrder(object, "ArmaFilter")
.
The above operation is valid for any ARIMA model, so will always
succeed. On the other hand, if further computation would work only if
there are no moving average terms in the model one could use
modelOrder(object, "ArFilter")
. Here, if object
contains
MA terms an error will be raised.
The concept is powerful and helps in writing expressive code. In this example a simple check on the returned value would do but even so, such a check may require additional care.
Examples
m1 <- new("SarimaModel", iorder = 1, siorder = 1, ma = -0.3, sma = -0.1, nseasons = 12)
modelOrder(m1)
#> $nseasons
#> [1] 12
#>
#> $iorder
#> [1] 1
#>
#> $siorder
#> [1] 1
#>
#> $ar
#> [1] 0
#>
#> $ma
#> [1] 1
#>
#> $sar
#> [1] 0
#>
#> $sma
#> [1] 1
#>
modelOrder(m1, "ArmaFilter")
#> $ar
#> [1] 13
#>
#> $ma
#> [1] 13
#>
modelOrder(m1, new("ArmaFilter"))
#> $ar
#> [1] 13
#>
#> $ma
#> [1] 13
#>
modelPoly(m1, "ArmaModel")
#> $ar
#> 1 - x - x^12 + x^13
#>
#> $ma
#> 1 - 0.3*x - 0.1*x^12 + 0.03*x^13
#>
modelPolyCoef(m1, "ArmaModel")
#> $ar
#> [1] 1 -1 0 0 0 0 0 0 0 0 0 0 -1 1
#>
#> $ma
#> [1] 1.00 -0.30 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
#> [13] -0.10 0.03
#>