Learn R Programming

pmhtutorial (version 1.0.0)

sm: Fully-adapted particle filter for state estimate in a linear Gaussian state space model

Description

Estimates the filtered state and the log-likelihood for a linear Gaussian state space model of the form \( x_{t} = \phi x_{t-1} + \sigma_v v_t \) and \( y_t = x_t + \sigma_e e_t \), where \(v_t\) and \(e_t\) denote independent standard Gaussian random variables, i.e.\(N(0,1)\).

Usage

sm(y, phi, sigmav, sigmae, nPart, T, x0)

Arguments

y

Observations from the model for \(t=1,...,T\).

phi

The persistence of the state process \(\phi\).

sigmav

The standard deviation of the state process \(\sigma_v\).

sigmae

The standard deviation of the observation process \(\sigma_e\).

nPart

The number of particles to use in the filter.

T

The number of observations.

x0

The initial state.

Value

The function returns a list with the elements:

  • xh: The estimate of the filtered state at time \(t=1,...,T\).

  • ll: The estimate of the log-likelihood.

  • p: The particle system at each time point.

  • w: The particle weights at each time point.

References

Dahlin, J. & Schoen, T. B. "Getting started with particle Metropolis-Hastings for inference in nonlinear dynamical models." pre-print, arXiv:1511.01707, 2015.

Examples

Run this code
# NOT RUN {
## Generates T=500 observations from a linear state space model with
## ( phi, sigma_e, sigma_v ) = ( 0.5, 1.0, 0.1 ) and zero initial state.

d  <- generateData(phi=0.5, sigmav=1.0, sigmae=0.1, T=500, x0=0.0) 

## Estimate the filtered state
xhatf <- sm(d$y, phi=0.5, sigmav=1.0, sigmae=0.1, nPart=20, 
T=500, x0=0.0)$xh

## Plot the estimate and the true state
par(mfrow=c(1,1))
plot(d$x, type="l", xlab="time", ylab="state")
lines(xhatf, lty="dashed",col="red")
# }

Run the code above in your browser using DataLab