Learn R Programming

KFAS (version 1.5.1)

coef.SSModel: Smoothed Estimates or One-step-ahead Predictions of States

Description

Compute smoothed estimates or one-step-ahead predictions of states of SSModel object or extract them from output of KFS. For non-Gaussian models without simulation (nsim = 0), these are the estimates of conditional modes of states. For Gaussian models and non-Gaussian models with importance sampling, these are the estimates of conditional means of states.

Usage

# S3 method for KFS
coef(
  object,
  start = NULL,
  end = NULL,
  filtered = FALSE,
  states = "all",
  last = FALSE,
  ...
)

# S3 method for SSModel coef( object, start = NULL, end = NULL, filtered = FALSE, states = "all", last = FALSE, nsim = 0, ... )

Value

Multivariate time series containing estimates states.

Arguments

object

An object of class KFS or SSModel.

start

The start time of the period of interest. Defaults to first time point of the object.

end

The end time of the period of interest. Defaults to the last time point of the object.

filtered

Logical, return filtered instead of smoothed estimates of state vector. Default is FALSE.

states

Which states to extract? Either a numeric vector containing the indices of the corresponding states, or a character vector defining the types of the corresponding 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".

last

If TRUE, extract only the last time point as numeric vector (ignoring start and end). Default is FALSE.

...

Additional arguments to KFS. Ignored in method for object of class KFS.

nsim

Only for method for for non-Gaussian model of class SSModel. The number of independent samples used in importance sampling. Default is 0, which computes the approximating Gaussian model by approxSSM and performs the usual Gaussian filtering/smoothing so that the smoothed state estimates equals to the conditional mode of \(p(\alpha_t|y)\). In case of nsim = 0, the mean estimates and their variances are computed using the Delta method (ignoring the covariance terms).

Examples

Run this code

model <- SSModel(log(drivers) ~ SSMtrend(1, Q = list(1)) +
 SSMseasonal(period = 12, sea.type = "trigonometric") +
 log(PetrolPrice) + law, data = Seatbelts, H = 1)

coef(model, states = "regression", last = TRUE)
coef(model, start = c(1983, 12), end = c(1984, 2))
out <- KFS(model)
coef(out, states = "regression", last = TRUE)
coef(out, start = c(1983, 12), end = c(1984, 2))

Run the code above in your browser using DataLab