A forward Kalman pass followed by the backward recursion. With Q = 0 and F = I the state is constant, so every smoothed state equals the final filtered state – an exact identity the tests use.
Arguments
- y
Observation matrix, one row per time point.
- F
State transition matrix.
- H
Observation matrix.
- Q
State noise covariance.
- R
Observation noise covariance.
- x0
Initial state mean; zero by default.
- P0
Initial state covariance; the identity by default.
- ridge
Ridge added to the predicted covariance before solving.
Details
Formula: C = P_t F' P_{t+1|t}^{-1}; x_{t|n} = x_{t|t} + C (x_{t+1|n} - x_{t+1|t}); P_{t|n} = P_{t|t} + C (P_{t+1|n} - P_{t+1|t}) C'.
References
Rauch, Tung and Striebel (1965), Maximum likelihood estimates of linear dynamic systems, AIAA Journal 3(8):1445-1450. doi:10.2514/3.3166
Examples
set.seed(1)
y <- matrix(cumsum(rnorm(20)) + rnorm(20), 20, 1)
KalmS(y, F = matrix(1), H = matrix(1), Q = matrix(0.1), R = matrix(1))
#> $estimate
#> [1] 0.03446971
#>
#> $smoothed
#> $smoothed[[1]]
#> [1] 0.03446971
#>
#> $smoothed[[2]]
#> [1] 0.01179793
#>
#> $smoothed[[3]]
#> [1] -0.04362663
#>
#> $smoothed[[4]]
#> [1] 0.01697356
#>
#> $smoothed[[5]]
#> [1] 0.2465221
#>
#> $smoothed[[6]]
#> [1] 0.3741053
#>
#> $smoothed[[7]]
#> [1] 0.5621238
#>
#> $smoothed[[8]]
#> [1] 0.7906033
#>
#> $smoothed[[9]]
#> [1] 1.140055
#>
#> $smoothed[[10]]
#> [1] 1.488585
#>
#> $smoothed[[11]]
#> [1] 1.811977
#>
#> $smoothed[[12]]
#> [1] 1.897318
#>
#> $smoothed[[13]]
#> [1] 1.860304
#>
#> $smoothed[[14]]
#> [1] 1.710313
#>
#> $smoothed[[15]]
#> [1] 1.697961
#>
#> $smoothed[[16]]
#> [1] 1.841848
#>
#> $smoothed[[17]]
#> [1] 2.064648
#>
#> $smoothed[[18]]
#> [1] 2.38819
#>
#> $smoothed[[19]]
#> [1] 2.716947
#>
#> $smoothed[[20]]
#> [1] 2.885739
#>
#>
#> $smoothed_cov
#> $smoothed_cov[[1]]
#> [,1]
#> [1,] 0.2168904
#>
#> $smoothed_cov[[2]]
#> [,1]
#> [1,] 0.1885171
#>
#> $smoothed_cov[[3]]
#> [,1]
#> [1,] 0.1734042
#>
#> $smoothed_cov[[4]]
#> [,1]
#> [1,] 0.1653556
#>
#> $smoothed_cov[[5]]
#> [,1]
#> [1,] 0.1610714
#>
#> $smoothed_cov[[6]]
#> [,1]
#> [1,] 0.1587949
#>
#> $smoothed_cov[[7]]
#> [,1]
#> [1,] 0.1575929
#>
#> $smoothed_cov[[8]]
#> [,1]
#> [1,] 0.1569726
#>
#> $smoothed_cov[[9]]
#> [,1]
#> [1,] 0.1566795
#>
#> $smoothed_cov[[10]]
#> [,1]
#> [1,] 0.1565936
#>
#> $smoothed_cov[[11]]
#> [,1]
#> [1,] 0.1566795
#>
#> $smoothed_cov[[12]]
#> [,1]
#> [1,] 0.1569726
#>
#> $smoothed_cov[[13]]
#> [,1]
#> [1,] 0.1575929
#>
#> $smoothed_cov[[14]]
#> [,1]
#> [1,] 0.1587949
#>
#> $smoothed_cov[[15]]
#> [,1]
#> [1,] 0.1610714
#>
#> $smoothed_cov[[16]]
#> [,1]
#> [1,] 0.1653556
#>
#> $smoothed_cov[[17]]
#> [,1]
#> [1,] 0.1734042
#>
#> $smoothed_cov[[18]]
#> [,1]
#> [1,] 0.1885171
#>
#> $smoothed_cov[[19]]
#> [,1]
#> [1,] 0.2168904
#>
#> $smoothed_cov[[20]]
#> [,1]
#> [1,] 0.2701574
#>
#>
#> $filtered
#> $filtered[[1]]
#> [1] 0.1532266
#>
#> $filtered[[2]]
#> [1] 0.2247193
#>
#> $filtered[[3]]
#> [1] -0.2413166
#>
#> $filtered[[4]]
#> [1] -0.669023
#>
#> $filtered[[5]]
#> [1] -0.1172496
#>
#> $filtered[[6]]
#> [1] -0.148668
#>
#> $filtered[[7]]
#> [1] -0.06467182
#>
#> $filtered[[8]]
#> [1] -0.1612138
#>
#> $filtered[[9]]
#> [1] 0.1943665
#>
#> $filtered[[10]]
#> [1] 0.6128912
#>
#> $filtered[[11]]
#> [1] 1.581138
#>
#> $filtered[[12]]
#> [1] 1.997379
#>
#> $filtered[[13]]
#> [1] 2.265658
#>
#> $filtered[[14]]
#> [1] 1.743686
#>
#> $filtered[[15]]
#> [1] 1.309204
#>
#> $filtered[[16]]
#> [1] 1.239908
#>
#> $filtered[[17]]
#> [1] 1.190555
#>
#> $filtered[[18]]
#> [1] 1.50002
#>
#> $filtered[[19]]
#> [1] 2.260943
#>
#> $filtered[[20]]
#> [1] 2.885739
#>
#>
#> $loglik
#> [1] -39.83011
#>
#> $n
#> [1] 20
#>
#> $method
#> [1] "forward Kalman pass plus the RTS backward recursion, Rauch, Tung & Striebel (1965)"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
