forecast: Forecasts a Gaussian state space model

Description Usage Arguments Value Author(s) See Also Examples

Description

Forecasting of a Gaussian state space model.

Usage

1
forecast(ss, k=10)

Arguments

ss

an object of class SS defining the state space model which has been smoothed.

k

an integer specifying the number of time steps to be forecasted.

Value

The object ss with updated components m, C and mu.

Author(s)

Anette Luther Christensen.

See Also

SS, smoother.

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
# Formulates Gaussian state space model
m1 <- SS(
     Fmat = function(tt,x,phi){matrix(cos(2*pi*tt/365))},
     Gmat = function(tt,x,phi){matrix(1)},
     Wmat = function(tt,x,phi){matrix(phi)},
     Vmat = function(tt,x,phi){matrix(0.1)},
     phi  = c(1e-1),
     m0   = matrix(1),
     C0   = matrix(100)
)

# Simulates observations
set.seed(984375)
m1 <- recursion(m1, 365)
plot(m1)

# Fits model
fit <- kfs(m1)
plot(fit)

# Change format of variances as these are time-invariant
fit$Wmat <- matrix(m1$phi)
fit$Vmat <- matrix(0.1)

# Estimates variances by use of EM algorithm
est.fit <- EMalgo(fit)


# Forecasting
fcast <- forecast(fit, k=100)

plot(fcast)

ClausDethlefsen/sspir documentation built on May 6, 2019, 7 p.m.