Last data update: 2014.03.03

R: Smoothed Estimates or One-step-ahead Predictions of States
coef.SSModelR Documentation

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 class 'KFS'
coef(object, start = NULL, end = NULL, filtered = FALSE,
  states = "all", last = FALSE, ...)

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

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.

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(α[t]|y). In case of nsim = 0, the mean estimates and their variances are computed using the Delta method (ignoring the covariance terms).

...

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

Value

Multivariate time series containing estimates states.

Examples


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))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(KFAS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/KFAS/coef.SSModel.Rd_%03d_medium.png", width=480, height=480)
> ### Name: coef.SSModel
> ### Title: Smoothed Estimates or One-step-ahead Predictions of States
> ### Aliases: coef.KFS coef.SSModel
> 
> ### ** Examples
> 
> 
> 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)
log(PetrolPrice)              law 
      -0.1956752       -0.2332047 
> coef(model, start = c(1983, 12), end = c(1984, 2))
         log(PetrolPrice)        law    level   sea_trig1 sea_trig*1
Dec 1983       -0.1956752 -0.2332047 6.946033  0.10939698 -0.0696719
Jan 1984       -0.1956752 -0.2332047 6.983564  0.05990461 -0.1150361
Feb 1984       -0.1956752 -0.2332047 6.986484 -0.00563915 -0.1295765
             sea_trig2  sea_trig*2   sea_trig3  sea_trig*3     sea_trig4
Dec 1983  0.0602264533 -0.03450591  0.02977791 -0.02020845  0.0228839865
Jan 1984  0.0002302297 -0.06941059 -0.02020845 -0.02977791 -0.0226747351
Feb 1984 -0.0599962235 -0.03490468 -0.02977791  0.02020845 -0.0002092515
          sea_trig*4     sea_trig5  sea_trig*5    sea_trig6
Dec 1983 -0.01297045  0.0259741178  0.01532238 -0.007098248
Jan 1984 -0.01333289 -0.0148330544 -0.02625663  0.007098248
Feb 1984  0.02630334 -0.0002825139  0.03015544 -0.007098248
> out <- KFS(model)
> coef(out, states = "regression", last = TRUE)
log(PetrolPrice)              law 
      -0.1956752       -0.2332047 
> coef(out, start = c(1983, 12), end = c(1984, 2))
         log(PetrolPrice)        law    level   sea_trig1 sea_trig*1
Dec 1983       -0.1956752 -0.2332047 6.946033  0.10939698 -0.0696719
Jan 1984       -0.1956752 -0.2332047 6.983564  0.05990461 -0.1150361
Feb 1984       -0.1956752 -0.2332047 6.986484 -0.00563915 -0.1295765
             sea_trig2  sea_trig*2   sea_trig3  sea_trig*3     sea_trig4
Dec 1983  0.0602264533 -0.03450591  0.02977791 -0.02020845  0.0228839865
Jan 1984  0.0002302297 -0.06941059 -0.02020845 -0.02977791 -0.0226747351
Feb 1984 -0.0599962235 -0.03490468 -0.02977791  0.02020845 -0.0002092515
          sea_trig*4     sea_trig5  sea_trig*5    sea_trig6
Dec 1983 -0.01297045  0.0259741178  0.01532238 -0.007098248
Jan 1984 -0.01333289 -0.0148330544 -0.02625663  0.007098248
Feb 1984  0.02630334 -0.0002825139  0.03015544 -0.007098248
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>