pfilter {pomp} | R Documentation

## Particle filter

### Description

A plain vanilla sequential Monte Carlo (particle filter) algorithm. Resampling is performed at each observation.

### Usage

    ## S4 method for signature 'data.frame'
    pfilter(data, Np, tol = 1e-17, max.fail = Inf,
      params, rinit, rprocess, dmeasure, pred.mean = FALSE,
      pred.var = FALSE, filter.mean = FALSE, filter.traj = FALSE,
      save.states = FALSE, ..., verbose = getOption("verbose", FALSE))

    ## S4 method for signature 'pomp'
    pfilter(data, Np, tol = 1e-17, max.fail = Inf,
      pred.mean = FALSE, pred.var = FALSE, filter.mean = FALSE,
      filter.traj = FALSE, save.states = FALSE, ...,
      verbose = getOption("verbose", FALSE))

    ## S4 method for signature 'pfilterd_pomp'
    pfilter(data, Np, tol, ...,
      verbose = getOption("verbose", FALSE))

    ## S4 method for signature 'objfun'
    pfilter(data, ...)

### Arguments

`data` | either a data frame holding the time series data, or an object of class ‘pomp’, i.e., the output of another pomp calculation.

`Np`

the number of particles to use. This may be specified as a single positive integer, in which case the same number of particles will be used at each timestep. Alternatively, if one wishes the number of particles to vary across timesteps, one may specify `Np` either as a vector of positive integers of length

    length(time(object,t0=TRUE))

or as a function taking a positive integer argument. In the latter case, `Np(k)` must be a single positive integer, representing the number of particles to be used at the `k`-th timestep: `Np(0)` is the number of particles to use going from `timezero(object)` to `time(object)[1]`, `Np(1)`, from `timezero(object)` to `time(object)[1]`, and so on, while when `T=length(time(object,t0=TRUE))`, `Np(T)` is the number of particles to sample at the end of the time-series.

`tol` | positive numeric scalar; particles with likelihood less than `tol` are considered to be incompatible with the data. See the section on Filtering Failures for more information.
`max.fail` | integer; the maximum number of filtering failures allowed (see below). If the number of filtering failures exceeds this number, execution will terminate with an error. By default, `max.fail` is set to infinity, so no error can be triggered.
`params` | optional; named numeric vector of parameters. This will be coerced internally to storage mode `double`.
`rinit` | simulator of the initial-state distribution. This can be furnished either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library. Setting `rinit=NULL` sets the initial-state simulator to its default. For more information, see ?rinit_spec.
`rprocess` | simulator of the latent state process, specified using one of the rprocess plugins. Setting `rprocess=NULL` removes the latent-state simulator. For more information, see ?rprocess_spec for the documentation on these plugins.
`dmeasure` | evaluator of the measurement model density, specified either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library. Setting `dmeasure=NULL` removes the measurement density evaluator. For more information, see ?dmeasure_spec.
`pred.mean` | logical; if `TRUE`, the prediction means are calculated for the state variables and parameters.
`pred.var` | logical; if `TRUE`, the prediction variances are calculated for the state variables and parameters.
`filter.mean` | logical; if `TRUE`, the filtering means are calculated for the state variables and parameters.
`filter.traj` | logical; if `TRUE`, a filtered trajectory is returned for the state variables and parameters.
`save.states` | logical. If `save.states=TRUE`, the state-vector for each particle at each time is saved.

`...`

additional arguments supply new or modify existing model characteristics or components. See `pomp` for a full list of recognized arguments.

When named arguments not recognized by `pomp` are provided, these are made available to all basic components via the so-called userdata facility. This allows the user to pass information to the basic components outside of the usual routes of covariates (`covar`) and model parameters (`params`). See ?userdata for information on how to use this facility.

`verbose` | logical; if `TRUE`, diagnostic messages will be printed to the console.

### Value

An object of class ‘pfilterd_pomp’, which extends class ‘pomp’.

### Methods

logLik

  the estimated log likelihood

cond.logLik

  the estimated conditional log likelihood

eff.sample.size

  the (time-dependent) estimated effective sample size

pred.mean, pred.var

  the mean and variance of the approximate prediction distribution

filter.mean

  the mean of the filtering distribution

filter.traj

  retrieve one sample from the smoothing distribution

as.data.frame

  coerce to a data frame

plot

  diagnostic plots

### Filtering failures

If the degree of disagreement between model and data becomes sufficiently large, a “filtering failure” results. A filtering failure occurs when, at some time point, none of the `Np` particles is compatible with the data. In particular, if the conditional likelihood of a particle at any time is below the tolerance value `tol`, then that particle is considered to be uninformative and its likelihood is taken to be zero. A filtering failure occurs when this is the case for all particles. A warning is generated when this occurs unless the cumulative number of failures exceeds `max.fail`, in which case an error is generated.

### Author(s)

Aaron A. King

### References

M. S. Arulampalam, S. Maskell, N. Gordon, & T. Clapp. A Tutorial on Particle Filters for Online Nonlinear, Non-Gaussian Bayesian Tracking. IEEE Trans. Sig. Proc. 50:174–188, 2002.

### See Also

Other elementary POMP methods: `pomp-package`, `probe`, `simulate`, `spect`

Other particle filter methods: `bsmc2`, `cond.logLik`, `eff.sample.size`, `filter.mean`, `filter.traj`, `mif2`, `pmcmc`, `pred.mean`, `pred.var`

### Examples

    pf <- pfilter(gompertz(),Np=1000)	## use 1000 particles

    plot(pf)
    logLik(pf)
    cond.logLik(pf)			## conditional log-likelihoods
    eff.sample.size(pf)             ## effective sample size
    logLik(pfilter(pf))      	## run it again with 1000 particles

    ## run it again with 2000 particles
    pf <- pfilter(pf,Np=2000,filter.mean=TRUE,filter.traj=TRUE)
    fm <- filter.mean(pf)    	## extract the filtering means
    ft <- filter.traj(pf)    	## one draw from the smoothing distribution

[Package pomp version 2.3 Index]