RcppSMC allows for easier and more direct access from R to the computational core of the SMC algorithm.
Sequential Monte Carlo methods are a very general class of Monte Carlo methods for sampling from sequences of distributions. Simple examples of these algorithms are used very widely in the tracking and signal processing literature. Recent developments illustrate that these techniques have much more general applicability, and can be applied very effectively to statistical inference problems. Unfortunately, these methods are often perceived as being computationally expensive and difficult to implement. By combining the SMCTC with the 'glue' provided by Rcpp, a tighter integration with R is achieved. This allows the applied researcher interested in Sequential Monte Carlo and Particle Filter methods to more easily vary input data, summarize outputs, plot results and so on. As a concrete example, figure 5.1 of Johansen (2009) which illustrates a Particle Filter for a two-dimensional linear state space model with non-Gaussian observation error, is reproduced by
where we select the optional plot. Moreover, progress during the model fit can also be visualized (using callbacks into R from C++ which Rcpp provides) viares <- pfLineartBS(plot=TRUE)
whereres <- pfLineartBS(onlinePlot=pfLineartBSOnlinePlot)
pfLineartBSOnlinePlot()is a default plotting function provided for this example by the package. Two more 'classic' examples from the literature have been added to the package:
(which is part ofres <- pfLineartBS(plot=TRUE)
example(pfLineartBS)too) creates the following chart
Running the example for the function
pfNonlinBS(), that is
creates the following plot (which reproduces example 4.1 of Gordon, Salmon and Smith (1993) and their nonlinear model)sim <- simNonlin(len=50) res <- pfNonlinBS(sim$data,particles=500,plot=TRUE)
Note that the data is freshly simulated, so the chart will vary unless the RNG seed is fixed. Lastly, running
reproduces the example from Doucet, Briers and Senecal (2006):sim <- simGaussian(len=250) res <- blockpfGaussianOpt(sim$data,lag=5,plot=TRUE)
Information about SMCTC is also at this page.