stsm.class (version 1.3)

stsm-char2numeric-methods: State Space Representation of Objects of Class stsm

Description

This method returns the state space representation of time series models defined in the class stsm.

Usage

## S3 method for class 'stsm':
char2numeric(x, P0cov = FALSE, rescale = FALSE)

Arguments

x
an object of class stsm.
P0cov
logical. If TRUE the values of the elements outside the diagonal in the initial covariance matrix of the state vector are set equal to the values in the diagonal. Otherwise values outside the diagonal are set equal to zero.
rescale
logical. If TRUE, relative variance parameters are rescaled into absolute variances. Otherwise, relative variances are used. Ignored if x@cpar is null.

Value

  • A list of class stsmSS containing the following numeric matrices and vectors:
  • Zobservation matrix.
  • Ttransition matrix.
  • Hobservation variance.
  • Rselection matrix.
  • Vstate vector variance-covariance matrix.
  • QRVR'.
  • a0initial state vector.
  • P0initial state vector uncertainty matrix.
  • The list contains also two vectors, Vid and Qid, with the indices of those cells where the variance parameters are located respectively in the matrices $V$ and $Q$. The first element in a matrix is indexed as $0$.

State space representation

The general univariate linear Gaussian state space model is defined as follows: $$y[t] = Za[t] + e[t], e[t] \sim~ N(0, H)$$ $$a[t+1] = Ta[t] + Rw[t], w[t] \sim~ N(0, V)$$

for $t=1,\dots,n$ and $a[1] \sim~ N(a0, P0)$. $Z$ is a matrix of dimension $1\times m$; $H$ is $1\times 1$; $T$ is $m\times m$; $R$ is $m\times r$; $V$ is $r\times r$; $a0$ is $m\times 1$ and $P0$ is $m\times m$, where $m$ is the dimension of the state vector $a$ and $r$ is the number of variance parameters in the state vector.

Details

This method uses the information from the slots pars, nopars and cpar in order to build the numeric representation of the matrices.

For details about the argument rescale see the details section in stsm-get-methods and the examples below.

A previous version of this method employed the information in the slot ss. This slot contains the matrices of the state space form of the model but instead of inserting the parameter values, character strings indicating the location of the parameters are placed in the corresponding cells. This method performed the mapping from the character to the numeric matrices by means of a internal function called ss.fill. Currently the slot ss and the matrices are directly built depending on the model that was selected among those available in stsm.model. The current approach is straightforward and faster. The previous approach may still be interesting to allow the user to define additional models just by translating the notation of the model into character matrices. The usefulness of enhancing this approach will be assessed in future versions of the package.

See Also

stsm-class, stsm.model.

Examples

Run this code
# sample model with arbitrary parameter values
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 6), nopars = c("var3" = 12))
ss1 <- char2numeric(m)
c(get.pars(m), get.nopars(m), get.cpar(m))
# character notation of the covariance matrix of the state vector
m@ss$Q
# information from the slots 'pars', 'nopars' and 'cpar'
# is used to retrieve the numeric representation of 'm@ss$Q'
ss1$Q

# same as above but with P0cov=TRUE
# the only change is in the initial covariance matrix of
# the state vector 'P0'
ss2 <- char2numeric(m, P0cov = TRUE)
ss1$P0
ss2$P0

# if a non-standard parameterization is used, 
# the values in the slot 'pars' are transformed accordingly 
# and the actual variance parameters are returned;
# notice that the transformation of parameters applies only 
# to the parameters defined in the slot 'pars'
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 6), nopars = c("var3" = 12),
  transPars = "square")
c(get.pars(m), get.nopars(m), get.cpar(m))[1:3]
ss <- char2numeric(m)
ss$H
ss$Q

# model defined in terms of relative variances,
# the variances in 'pars' are relative to the scaling parameter 'cpar',
# in this example 'cpar' is chosen to be the variance 'var1'
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var2" = 3, "var3" = 6), cpar = c("var1" = 2),
  transPars = NULL)
# the state space representation can be done with 
# relative variances (no rescaling)
ss <- char2numeric(m, rescale = FALSE)
ss$H
ss$Q
# or with absolute variances (rescaling)
ss <- char2numeric(m, rescale = TRUE)
ss$H
ss$Q

# in a model where the parameters are the relative variances 
# and with non-null 'transPars', the transformation is applied to 
# the relative variances, not to the absolute variances, i.e., 
# the relative variances are first transformed and afterwards they are 
# rescaled back to absolute variances if requested
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var2" = 3, "var3" = 6), cpar = c("var1" = 2),
  transPars = "square")
# the state space representation can be done with 
# relative variances (no rescaling)
ss <- char2numeric(m, rescale = FALSE)
ss$H
ss$Q
# or with absolute variances (rescaling)
ss <- char2numeric(m, rescale = TRUE)
ss$H
ss$Q

Run the code above in your browser using DataLab