Extract.SSModel: Extract or Replace Parts of a State Space Model

[<-.SSModelR Documentation

Extract or Replace Parts of a State Space Model

Description

S3 methods for getting and setting parts of object of class SSModel. These methods ensure that dimensions of system matrices are not altered.

Usage

## S3 replacement method for class 'SSModel'
x[element, states, etas, series, times, ...] <- value

## S3 method for class 'SSModel'
x[element, states, etas, series, times, drop = TRUE, ...]

Arguments

x

Object of class SSModel.

element

Which element(s) is chosen. Typical values are "y", "Z", "H", "T", "R", "Q", "a1", "P1", "P1inf", and "u". See details.

states

Which states are chosen. Either a numeric vector containing the indices of the states, or a character vector defining the types of the states. Possible choices are "all", "level", "slope", "trend", "regression", "arima", "custom", "cycle" or "seasonal", where "trend" extracts all states relating to trend. These can be combined. Default is "all".

etas

Which disturbances eta are chosen. Used for elements "R" and "Q". Either a numeric vector containing the indices of the etas, or a character vector defining the types of the etas. Possible choices are "all", "level", "slope", "trend", "regression", "arima", "custom", "cycle" or "seasonal", where "trend" extracts all etas relating to trend. These can be combined. Default is "all".

series

Numeric. Which series are chosen. Used for elements "y", "Z", and "u".

times

Numeric. Which time points are chosen.

...

Ignored.

value

A value to be assigned to x.

drop

Logical. If TRUE (default) the result is coerced to the lowest possible dimension.

Details

If element is not one of "y", "Z", "H", "T", "R", "Q", "a1", "P1", "P1inf", "u", the default single bracket list extraction and assignments (x[element] and x[element] <- value) are used (and other arguments are ignored).

If element is one of "y", "Z", "H", "T", "R", "Q", "a1", "P1", "P1inf", "u" and if the arguments states, etas, times and series are all missing, the double bracket list extraction x[[element]] and modified double bracket list assignment x[[element]][] <- value are used.

If neither of above holds, then for example in case of element = Z the extraction is of form x$Z[series, states, times, drop].

Value

A selected subset of the chosen element or a value.

Examples

set.seed(1)
model <- SSModel(rnorm(10) ~ 1)
model["H"]
model["H"] <- 10
# H is still an array:
model["H"]
logLik(model)
model$H <- 1
# model["H"] throws an error as H is now scalar:
model$H
logLik(model, check.model = TRUE) #with check.model = FALSE R crashes!

KFAS documentation built on Sept. 8, 2023, 5:56 p.m.