tsmooth {TSSS} | R Documentation |
Predict and interpolate time series based on state space model by Kalman filter.
tsmooth(y, f, g, h, q, r, x0 = NULL, v0 = NULL, filter.end = NULL, predict.end = NULL, minmax = c(-1.0e+30, 1.0e+30), missed = NULL, np = NULL, plot = TRUE, ...)
y |
a univariate time series y(n). |
f |
state transition matrix F(n). |
g |
matrix G(n). |
h |
matrix H(n). |
q |
system noise variance Q(n). |
r |
observational noise variance R. |
x0 |
initial state vector X(0|0). |
v0 |
initial state covariance matrix V(0|0). |
filter.end |
end point of filtering. |
predict.end |
end point of prediction. |
minmax |
lower and upper limits of observations. |
missed |
start position of missed intervals. |
np |
number of missed observations. |
plot |
logical. If |
... |
further arguments to be passed to |
The linear Gaussian state space model is
x(n) = F(n)x(n-1) + G(n)v(n),
y(n) = H(n)x(n) + w(n),
where y(n) is a univariate time series, x(n) is an m-dimensional state vector.
F(n), G(n) and H(n) are m * m, m * k matrices and a vector of length m , respectively. Q(n) is k * k matrix and R(n) is a scalar. v(n) is system noise and w(n) is observation noise, where we assume that E(v(n), w(n)) = 0, v(n) ~ N(0, Q(n)) and w(n) ~ N(0, R(n)). User should give all the matrices of a state space model and its parameters. In current version, F(n), G(n), H(n), Q(n), R(n) should be time invariant.
An object of class "smooth"
. It contains the following components:
mean.smooth |
mean vectors of the smoother. |
cov.smooth |
variance of the smoother. |
esterr |
estimation error. |
llkhood |
log-likelihood. |
aic |
AIC. |
Kitagawa, G. (2010) Introduction to Time Series Modeling. Chapman & Hall/CRC.
Kitagawa, G. and Gersch, W. (1996) Smoothness Priors Analysis of Time Series. Lecture Notes in Statistics, No.116, Springer-Verlag.
## Example of prediction (AR model : m=15, k=1) data(BLSALLFOOD) BLS120 <- BLSALLFOOD[1:120] z1 <- arfit(BLS120, plot = FALSE) tau2 <- z1$sigma2 arcoef <- z1$arcoef # in case m = 15 m1 <- z1$maice.order f <- matrix(0.0e0, m1, m1) f[1, ] <- arcoef[1:m1] if (m1 != 1) for (i in 2:m1) f[i, i-1] <- 1 g <- c(1, rep(0.0e0, m1-1)) h <- c(1, rep(0.0e0, m1-1)) q <- tau2[m1+1] r <- 0.0e0 x0 <- rep(0.0e0, m1) v0 <- NULL s1 <- tsmooth(BLS120, f, g, h, q, r, x0, v0, filter.end = 120, predict.end = 156) s1 plot(s1, BLSALLFOOD) ## Example of interpolation of missing values (AR model : m=15, k=1) z2 <- arfit(BLSALLFOOD, plot = FALSE) tau2 <- z2$sigma2 arcoef <- z2$arcoef # in case m2 = 15 m2 <- z2$maice.order f <- matrix(0.0e0, m2, m2) f[1, ] <- arcoef[1:m2] if (m2 != 1) for (i in 2:m2) f[i, i-1] <- 1 g <- c(1, rep(0.0e0, m2-1)) h <- c(1, rep(0.0e0, m2-1)) q <- tau2[m2+1] r <- 0.0e0 x0 <- rep(0.0e0, m2) v0 <- NULL tsmooth(BLSALLFOOD, f, g, h, q, r, x0, v0, missed = c(41, 101), np = c(30, 20))