Skip to contents

Get the coefficients of an object, optionally specifying the expected format.

Usage

modelCoef(object, convention, component, ...)

Arguments

object

an object.

convention

the convention to use for the return value, a character string or any object from a supported class, see Details.

component

if not missing, specifies a component to extract, see Details.

...

not used, further arguments for methods.

Details

modelCoef is a generic function for extraction of coefficients of model objects. What `coeffcients' means depends on the class of object but it can be changed with the optional argument convention. In effect, modelCoef provides a very flexible and descriptive way of extracting coefficients from models in various forms.

The one-argument form, modelCoef(object), gives the coefficients of object. In effect it defines, for the purposes of modelCoef, the meaning of `coefficients' for class class(modelCoef).

Argument convention can be used to specify what kind of value to return.

If convention is not a character string, only its class is used. Conceptually, the value will have the format and meaning of the value that would be returned by a call to modelCoef(obj) with obj from class class(convention).

If convention is a character string, it is typically the name of a class. In this case modelCoef(object, "someclass") is equivalent to modelCoef(object, new("someclass")). Note that this is conceptual - argument convention can be the name of a virtual class, for example. Also, for some classes of object character values other than names of classes may be supported.

For example, if obj is from class "ArmaModel", modelCoef(obj) returns a list with components "ar" and "ma", which follow the "BD" convention. So, to get such a list of coefficients from an object from any class capable of representing ARMA models, set convention = "ArmaModel" in the call to modelCoef{}.

modelCoef() will signal an error if object is not compatible with target (e.g. if it contains unit roots). (see filterCoef if you need to expand any multiplicative filters). TODO: rethink this, it does not reflect current behaviour!

If there is no class which returns exactly what is needed some additional computation may be necessary. In the above "ArmaModel" example we might need the coefficients in the "BJ" convention, so we would need to change the signs of the MA coefficients to achieve this. Since this is a very common operation, a convenience feature is available. Setting convention = "BJ" requests ARMA coefficients with "BJ" convention. For completeness, the the settings "SP" (signal processing) and "BD" (Brockwell-Davis) are also available.

The methods for modelCoef() in package "sarima" return a list with components depending on argument "convention", as outlined above.

Value

a list, with components depending on the target class, as described in Details

Author

Georgi N. Boshnakov

Examples

## define a seasonal ARIMA model, it has a number of components
m1 <- new("SarimaModel", iorder = 1, siorder = 1, ma = -0.3, sma = -0.1, nseasons = 12)
m1
#> An object of class "SarimaModel"
#> Model: (1-B)(1-B^s)X(t) = Theta(B)Theta_s(B^s)e(t)
#> 
#> Intercept:  0 
#> SigmaSq:  NA 
#> Period:  12 
#> Order of differencing:  1 
#> Order of seasonal differencing:  1 
#> 
#> ar coefficients:    <None>
#> ma coefficients:   -0.3
#> seasonal ar coefficients:   <None>
#> seasonal ma coefficients:  -0.1
## Get the coefficients corresponding to a 'flat' ARMA model,
## obtained by multiplying out AR-like and MA-like terms. 
## A simple way is to use modelCoef() with a suitable convention:
modelCoef(m1, "ArmaModel")
#> $ar
#>  [1]  1  0  0  0  0  0  0  0  0  0  0  1 -1
#> 
#> $ma
#>  [1] -0.30  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 -0.10
#> [13]  0.03
#> 
modelCoef(m1, "ArmaFilter") ## same
#> $ar
#>  [1]  1  0  0  0  0  0  0  0  0  0  0  1 -1
#> 
#> $ma
#>  [1] -0.30  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 -0.10
#> [13]  0.03
#> 

## Here is another model
m1a <- new("SarimaModel", iorder = 1, siorder = 1,  ar = 0.6, nseasons = 12)
modelCoef(m1a, "ArmaModel")
#> $ar
#>  [1]  1.6 -0.6  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0 -1.6  0.6
#> 
#> $ma
#> numeric(0)
#> 
modelCoef(m1a, "ArmaFilter") ## same
#> $ar
#>  [1]  1.6 -0.6  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0 -1.6  0.6
#> 
#> $ma
#> numeric(0)
#> 

## if only AR-like terms are allowed in a computation,
## use convention = "ArModel" to state it explicitly.
##
## this works, since m1a contains only AR-like terms:
modelCoef(m1a, "ArModel")
#> $ar
#>  [1]  1.6 -0.6  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0 -1.6  0.6
#> 
#> $ma
#> numeric(0)
#> 
modelCoef(m1a, "ArFilter") ## same
#> $ar
#>  [1]  1.6 -0.6  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0 -1.6  0.6
#> 
#> $ma
#> numeric(0)
#> 
## ... but these would throw errors if evaluated,
## since model m1a contains both AR-like and MA-like terms,
if (FALSE) {
modelCoef(m1, "ArModel")
modelCoef(m1, "ArFilter")
modelCoef(m1, "MaModel")
modelCoef(m1, "MaFilter")
}