Solved – Particle filter in R – trivial code example

I am looking for a simple code example of how to run a Particle Filter in R. The pomp package appears to support the state space math bit, but the examples are a little tricky to follow programmatically for a simple OO developer such as myself, particularly how to load the observed data into a pomp object.

Lets say I have a csv file with 1 column of noisy data as input, and I would like to run it through a Particle Filter in order to hopefully clean it up, with the output being the estimations, to another csv file.

 y <- read.csv("C:/Dev/VeryCleverStatArb/inputData.csv", header=FALSE)  #CSV to Pomp object ???  #Run Particle Filter  #Write estimates to csv. 

The main difficulty with the examples is loading csv data into a pomp object.

A very simple state space model should be good enough for now.

Any ideas for the R-curious?

EDIT: It seems that most particle filter packages are gone now. However, I have been playing with LaplacesDemon (a Bayesian MCMC package) and it does have the PMC (Population Monte Carlo) function which implements PMC, which is a type of particle filter. Maybe too much machinery for a quick particle filter kind of thing, but a package well worth learning.

You can find package and tutorials at CRAN.

ORIGINAL: To be honest, in the simplest case, pomp is hard to use. It's very flexible for anything you might want to do, but it's like using a space ship to go to the grocery store.

Have you tried looking at Kalman filters (if your data might satisfy assumptions of the Kalman filter), including base functions tsSmooth and StructTS (univariate only), and package dlm? I'd also take a look at loess and other smoothers.

I hope I'm wrong and someone hops on here with a quick, "Here's how to do it for simple univariate data such as you have with some modest assumptions." I'd love to be able to use the package myself.

Similar Posts:

Rate this post

Leave a Comment