Description Usage Arguments Details Value State space representation See Also Examples
This method returns the state space representation of time series models
defined in the class stsm
.
1 2 | ## S4 method for signature 'stsm'
char2numeric(x, P0cov = FALSE, rescale = FALSE)
|
x |
an object of class |
P0cov |
logical. If |
rescale |
logical. If |
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.
A list of class stsmSS
containing the following numeric matrices and vectors:
Z |
observation matrix. |
T |
transition matrix. |
H |
observation variance. |
R |
selection matrix. |
V |
state vector variance-covariance matrix. |
Q |
RVR'. |
a0 |
initial state vector. |
P0 |
initial 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.
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,…,n and a[1] \sim~ N(a0, P0). Z is a matrix of dimension 1xm; H is 1x1; T is mxm; R is mxr; V is rxr; a0 is mx1 and P0 is mxm, where m is the dimension of the state vector a and r is the number of variance parameters in the state vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # 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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.