You asked about the behavior of KalmanSmooth(...)$var with missing
values. I also got very counterintuitive results from your excellent,
reproducible example using R 2.2.0 under Windows XP:
* With no missing values, KalmanSmooth(...)$var = 2, independent of
the data and even the number of observations, at least in the few
simulations I did.
* With observations 6:14 missing, KalmanSmooth(...)$var drops
precipitously from 2 to almost 1 on the first missing value, then
increases not quite linearly to somewhere between 3 and 10 in the first
nonmissing observation after the missing period. The exact numbers
seemed to depend on the data outside the missing range (but not as far
as I could tell on whether I used 20 or 100 observations).
If I had more time to work on this, I would dig into the code and
compare the computations with Durbin and Koopman (2001) referenced in
"?KalmanSmooth". The KalmanSmooth function basically consists of
'.Call("KalmanSmooth",...)'. If I had more time for this, I
could study
that code.
Earlier this year, I started reading Durbin and Koopman (2001). I
was able to reproduce their Figure 2.1 but failed to reproduce their
Figure 2.2 illustrating "state smoothing recursion". That latter
figure
includes a plot of the "smoothed state variance", the title of which
sounds similar to "KalmanSmooth(...)$var". However, the former
roughly
doubles near both ends of the series, while the latter is totally
constant independent of the data (except in the presence of missing
values), at least from what I've seen.
Perhaps someone else will be able to enlighten both of us.
Thanks for raising this question.
Spencer Graves
Kjetil Brinchmann Halvorsen wrote:
> I am trying to use KalmanSmooth to smooth a time series
> fitted by arima (and with missing values), but the $smooth component
> of the output baffles me. Look at the following example:
>
> testts <- arima.sim(list(ar=0.9),n=100)
> testts[6:14] <- NA
> testmod <- arima(testts, c(1,0,0))
> testsmooth <- KalmanSmooth(testts, testmod$model)
> par(mfrow=c(2,1))
> plot(testsmooth$smooth, type="l")
> plot(testsmooth$var, type="l")
>
> Look at the lower panel plot, how the uncertainty of the
> smoothed values first is lowered, then being the highest
> at the end ( of the smoothed part, indexes 6:14).
> Anybody can explain this,or is this an error?
>
>
> Kjetil Halvorsen
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915