Learn R Programming

pmhtutorial (version 1.5)

example1_lgss: State estimation in a linear Gaussian state space model

Description

Minimal working example of state estimation in a linear Gaussian state space model using Kalman filtering and a fully-adapted particle filter. The code estimates the bias and mean squared error (compared with the Kalman estimate) while varying the number of particles in the particle filter.

Usage

example1_lgss()

Arguments

Value

Returns a plot with the generated observations y and the difference in the state estimates obtained by the Kalman filter (the optimal solution) and the particle filter (with 20 particles). Furthermore, the function returns plots of the estimated bias and mean squared error of the state estimate obtained using the particle filter (while varying the number of particles) and the Kalman estimates.

The function returns a list with the elements:

  • y: The observations generated from the model.

  • x: The states generated from the model.

  • kfEstimate: The estimate of the state from the Kalman filter.

  • pfEstimate: The estimate of the state from the particle filter with 20 particles.

Details

The Kalman filter is a standard implementation without an input. The particle filter is fully adapted (i.e. takes the current observation into account when proposing new particles and computing the weights).

References

Dahlin, J. & Schon, T. B. "Getting Started with Particle Metropolis-Hastings for Inference in Nonlinear Dynamical Models." Journal of Statistical Software, Code Snippets, 88(2): 1--41, 2019.

Examples

Run this code
# NOT RUN {
example1_lgss()
# }

Run the code above in your browser using DataLab