x_n = a x_{n-1} + N(0, q), y_n = c x_n + N(0, r),
starting at (m0, p0). Provided so the particle filter can
be checked against the exact answer.
Usage
kalman_filter_1d(y, a, q, c, r, m0 = 0, p0 = 1)
Arguments
- y
Numeric vector of observations.
- a
Process coefficient.
- q
Process variance.
- c
Measurement coefficient.
- r
Measurement variance.
- m0
Initial state mean.
- p0
Initial state variance.
Value
A list with filtered_mean and loglik.
Examples
set.seed(15)
x <- cumsum(rnorm(30, sd = 0.3)); y <- x + rnorm(30, sd = 0.5)
k <- kalman_filter_1d(y, a = 1, q = 0.09, c = 1, r = 0.25)
c(k$loglik, tail(k$filtered_mean, 1))
#> [1] -29.398342 1.641274