plot.fkf {FKF}R Documentation

Plotting fkf Objects

Description

Plotting method for objects of class fkf. This function provides tools for graphical analysis of the Kalman filter output: Visualization of the state vector, Q-Q plot of the individual residuals, Q-Q plot of the Mahalanobis distance, auto- as well as crosscorrelation function of the residuals.

Usage


## S3 method for class 'fkf':
plot(x, type = c("state", "resid.qq", "qqchisq", "acf"),
         CI = 0.95, at.idx = 1:nrow(x$at), att.idx = 1:nrow(x$att), ...)

Arguments

x The output of fkf.
type A string stating what shall be plotted (see Details).
CI The confidence interval in case type == "state". Set CI to NA if no confidence interval shall be plotted.
at.idx An vector giving the indexes of the predicted state variables which shall be plotted if type == "state".
att.idx An vector giving the indexes of the filtered state variables which shall be plotted if type == "state".
... Arguments passed to either plot, qqnorm, qqplot or acf.

Details

The argument type states what shall be plotted. type must partially match one of the following:

state
The state variables are plotted. Through the arguments at.idx and att.idx, the user can specify which of the predicted (at) and filtered (att) state variables will be drawn.
resid.qq
Draws a Q-Q plot for each row of the residuals vt.
qqchisq
A Chi-Squared Q-Q plot will be drawn to graphically test for multivariate normality of the residuals based on the Mahalanobis distance.
acf
Creates a pairs plot with the autocorrelation function (acf) on the diagonal panels and the crosscorrelation function (ccf) of the residuals on the off-diagnoal panels.

Value

Invisibly returns an list with components:
distance The Mahalanobis distance of the residuals as a vector of length n.
std.resid The standardized residuals as an d * n-matrix. It should hold that std.resid[i,j] iid N_d(0, 1),
where d denotes the dimension of the data and n the number of observations.

Author(s)

David Luethi, Philipp Erb

See Also

fkf

Examples

## This example shows how to filter a series by an AR(2) filter

ar1 <- -0.44
ar2 <- 0.4
sigma <- .4

## Sample from an AR(2) process and put it into the Kalman filter
a <- arima.sim(model = list(ar = c(ar1, ar2)),
               n = 60, innov = rnorm(60) * sigma)

## Set up the state space representation for an AR(2) model:
## Transition equation:
## alpha[, t + 1] = matrix(ar1, 1, ar2, 0, ncol = 2) * alpha[,t] + e[t]
## Measurement equation:
## y[,t] = c(1, 0) * a[,t] */
## Initial values:
## a0 = c(0, 0), P0 = diag(c(10, 10))

ans <- fkf(a0 = c(0, 0), P0 = diag(c(10, 10)),
           dt = rbind(0, 0), ct = matrix(0),
           Tt = matrix(c(ar1, 1, ar2, 0), ncol = 2),
           Zt = cbind(1, 0),
           HHt = matrix(c(sigma^2, 0, 0, 0), ncol = 2),
           GGt = matrix(0), yt = rbind(a))

## Compared the filtered series with the simulated AR(2) series:
plot(ans, att.idx = 1, at.idx = NA)
lines(a, lty = "dotted")

## Compared the predicted series with the simulated AR(2) series.
## Additionally, a 99
plot(ans, att.idx = NA, at.idx = 1, CI = .99)
lines(a, lty = "dotted")

## Check the residuals for normality
plot(ans, type = "resid.qq")

## Test for autocorrelation
plot(ans, type = "acf")


[Package FKF version 0.0.1 Index]