Learn R Programming

stsm.class (version 1.1)

stsm-transPars-methods: Parameterization of Models Defined in the Class stsm

Description

This method provides different transformations of the parameters of a structural time series model.

Usage

## S3 method for class 'generic':
transPars(x, 
    type = c("square", "StructTS", "exp", "exp10sq"),
    gradient = FALSE, hessian = FALSE, 
    rp, sclrho = 1.7, sclomega = 1.7, ftrans = NULL, ...)
## S3 method for class 'numeric':
transPars(x, 
    type = eval(formals(stsm.class::transPars)$type),
    gradient = FALSE, hessian = FALSE, 
    rp, sclrho = 1.7, sclomega = 1.7, ftrans = NULL, ...)
## S3 method for class 'stsm':
transPars(x, type = NULL,
    gradient = FALSE, hessian = FALSE, 
    rp, sclrho = 1.7, sclomega = 1.7, ftrans = NULL, ...)

Arguments

x
an object of class stsm.
type
a character string indicating the type of transformation. Ignored if x is of class stsm. See details.
gradient
logical. If TRUE, first order derivatives of the transformation function with respect to the parameters in the slot pars are returned.
hessian
logical. If TRUE, second order derivatives of the transformation function with respect to the parameters in the slot pars is returned.
rp
numeric value. Regularization parameter used with type = StrucTS. By default it is the variance of the data x@y divided by $100$.
sclrho
numeric value. Currently ignored.
sclomega
numeric value. Currently ignored.
ftrans
a function defining an alternative transformation of the parameters. Ignored if x is of class stsm. See example below.
...
additional arguments to be passed to ftrans.

Value

  • A list containing a named numeric vector with the values of the transformed parameters. If requested, the gradient and Hessian of the transformation function with respect to the parameters are returned.

code

cpar

eqn

$\theta^2$

dQuote

^var\d{1,2}$

emph

Note:

Details

Rather than using the standard parameterization of the model (in terms of variances and autoregressive coefficients if they are part of the model), it can be parameterized in terms of an auxiliar set of parameters $\theta$. This may be useful for example when the parameters of the model are selected by means of a numerical optimization algorithm. Choosing a suitable parameterization ensures that the solution returned by the algorithm meets some constraints such as positive variances or autoregressive coefficients within the region of stationarity.

The method transPars can be applied both on a named vector of parameters, e.g. x@pars or on a model of class stsm.

When the slot transPars is not null, the model is parameterized in terms of $\theta$. The following transformation of parameters can be considered:

  • "square": the variance parameters are the square of$\theta$.
"StructTS": transformation used in the function StructTS of the stats package. "exp": the variance parameters are the exponential of $\theta$. "exp10sq": the variance parameters are $(exp(-\theta)/10)^2$.

See Also

stsm-class, get.pars.

Examples

Run this code
# sample models with arbitrary parameter values

# model in standard parameterization
# ower bounds imposed on the variance parameters
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 15, "var3" = 30), transPars = NULL)
get.pars(m)
m@lower

# square transformation
# negative values are allowed in 'pars' since 
# the square will yield positive variances
# in fact no lower bounds need to be imposed on the auxiliar parameters
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = -2, "var2" = -5, "var3" = 10), transPars = "square")
validObject(m)
m@lower
m@pars
get.pars(m)

# 'ftrans', alternative transformation of parameters;
# the following parameterization is sometimes found:
# variance = exp(-theta) / 10
# the function 'ftrans' following the rules given in the details 
# above can be defined as follows:

ftrans <- function(x, gradient = FALSE, hessian = FALSE)
{
  tpars <- x
  p <- length(x)
  nmspars <- names(x)
  idvar <- grep("^var|P0\\d{1,2}$", nmspars, value = FALSE)

  if (gradient) {
    d1 <- rep(NA, p)
    names(d1) <- nmspars
  } else d1 <- NULL
  if (hessian) {
    d2 <- matrix(0, p, p)
    rownames(d2) <- colnames(d2) <- nmspars
  } else d2 <- NULL

  if (length(idvar) > 0) {
    tpars[idvar] <- exp(-x[idvar]) / 10
  } else warning("No changes done by 'transPars'.")

  if (gradient)
  {
    if (length(idvar) > 0)
      d1[idvar] <- -tpars[idvar]
  }
  if (hessian) {
    diag(d2)[idvar] <- tpars[idvar]
  }
  
  list(pars = tpars, gradient = d1, hessian = d2)
}

# now 'ftrans' can be passed to 'transPars' and be applied
# on a named vector of parameters or on a 'stsm' object
transPars(c("var1" = 2, "var2" = 15, "var3" = 30), 
  ftrans = ftrans, gradient = TRUE, hessian = TRUE)
m <- stsm.model(model = "llm+seas", y = JohnsonJohnson, 
  pars = c("var1" = 2, "var2" = 15, "var3" = 30), transPars = ftrans)
get.pars(m)

Run the code above in your browser using DataLab