plot.fkf: Plotting fkf Objects

Description Usage Arguments Details Value Author(s) See Also Examples

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, QQ-plot of the individual residuals, QQ-plot of the Mahalanobis distance, auto- as well as crosscorrelation function of the residuals.

Usage

1
2
3
## 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. By 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 QQ-plot for each residual-series invt.

qqchisq

A Chi-Squared QQ-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, I),

where d denotes the dimension of the data and n the number of observations.

Author(s)

David Luethi, Philipp Erb, Simon Otziger

See Also

fkf

Examples

 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
## Local level model for the treering width data.
## Transition equation:
## alpha[t+1] = alpha[t] + eta[t], eta[t] ~ N(0, HHt)          
## Measurement equation:
## y[t] = alpha[t] + eps[t], eps[t] ~  N(0, GGt)

y <- treering
y[c(3, 10)] <- NA  # NA values can be handled

## Set constant parameters:
dt <- ct <- matrix(0) 
Zt <- Tt <- matrix(1)
a0 <- y[1]            # Estimation of the first width
P0 <- matrix(100)     # Variance of 'a0'

## Estimate parameters:
fit.fkf <- optim(c(HHt = var(y, na.rm = TRUE) * .5,
                   GGt = var(y, na.rm = TRUE) * .5),
                 fn = function(par, ...)
                 -fkf(HHt = matrix(par[1]), GGt = matrix(par[2]), ...)$logLik,
                 yt = rbind(y), a0 = a0, P0 = P0, dt = dt, ct = ct,
                 Zt = Zt, Tt = Tt, check.input = FALSE)

## Filter Nile data with estimated parameters:
fkf.obj <- fkf(a0, P0, dt, ct, Tt, Zt, HHt = matrix(fit.fkf$par[1]),
               GGt = matrix(fit.fkf$par[2]), yt = rbind(y))

## Plot the width together with fitted local levels:
plot(y, main = "Treering data")
lines(ts(fkf.obj$att[1, ], start = start(y), frequency = frequency(y)), col = "blue")
legend("top", c("Treering data", "Local level"), col = c("black", "blue"), lty = 1)

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

## Test for autocorrelation:
plot(fkf.obj, type = "acf", na.action = na.pass)

FKF documentation built on May 2, 2019, 6:12 p.m.

Related to plot.fkf in FKF...