Learn R Programming

RcppSMC (version 0.2.7)

pfLineartBS: Particle Filter Example

Description

The pfLineartBS function provides a simple example for RcppSMC. It is based on the first example in SMCTC and the discussion in Section 5.1 of Johansen (2009). A simple 'vehicle tracking' problem of 100 observations is solved with 1000 particles.

The pfLineartBSOnlinePlot function provides a simple default ‘online’ plotting function that is invoked during the estimation process.

The simLineart function simulates data from the model.

Usage

pfLineartBS(data, particles=1000, plot=FALSE, onlinePlot)
  pfLineartBSOnlinePlot(xm, ym)
  simLineart(len)

Value

The pfLineartBS function returns a data.frame containing as many rows as in the input data, and four columns corresponding to the estimated \(x\) and

\(y\) coordinates as well as the estimated velocity in these two directions.

The simLineart function returns a list containing the vector of states and the associated vector of observations.

Arguments

data

A two-column matrix or dataframe containing x and y values. The default data set from Johansen (2009) is used as the default if no data is supplied.

particles

An integer specifying the number of particles.

plot

A boolean variable describing whether plot should illustrate the estimated path along with the data.

onlinePlot

A user-supplied callback function which is called with the x and y position vectors during each iteration of the algorithm; see pfExOnlinePlot for a simple example.

xm

Vector with x position.

ym

Vector with y position.

len

Length of sequence to simulate

Author

Adam M. Johansen and Dirk Eddelbuettel

Details

The pfLineartBS function provides a simple example for RcppSMC. The model is linear with t-distributed innovations. It is based on the pf example in the SMCTC library, and discussed in the Section 5.1 of his corresponding paper (Johansen, 2009). simLineart simulates from the model.

Using the simple pfExOnlinePlot function illustrates how callbacks into R, for example for plotting, can be made during the operation of SMC algorithm.

References

A. M. Johansen. SMCTC: Sequential Monte Carlo in C++. Journal of Statistical Software, 30(6):1-41, April 2009, tools:::Rd_expr_doi("10.18637/jss.v030.i06").

See Also

The SMCTC paper and code at tools:::Rd_expr_doi("10.18637/jss.v030.i06").

Examples

Run this code
  res <- pfLineartBS(plot=TRUE)
  if (interactive()) ## if not running R CMD check etc
     res <- pfLineartBS(onlinePlot=pfLineartBSOnlinePlot)

Run the code above in your browser using DataLab