dmeasure_spec: dmeasure specification

dmeasure_specR Documentation

dmeasure specification


Specification of the measurement model density function, dmeasure.


The measurement model is the link between the data and the unobserved state process. It can be specified either by using one or both of the rmeasure and dmeasure arguments.

Suppose you have a procedure to compute the probability density of an observation given the value of the latent state variables. Then you can furnish

   dmeasure = f

to pomp algorithms, where f is a C snippet or R function that implements your procedure.

Using a C snippet is much preferred, due to its much greater computational efficiency. See Csnippet for general rules on writing C snippets. The goal of a dmeasure C snippet is to fill the variable lik with the either the probability density or the log probability density, depending on the value of the variable give_log.

In writing a dmeasure C snippet, observe that:

  1. In addition to the states, parameters, covariates (if any), and observables, the variable t, containing the time of the observation will be defined in the context in which the snippet is executed.

  2. Moreover, the Boolean variable give_log will be defined.

  3. The goal of a dmeasure C snippet is to set the value of the lik variable to the likelihood of the data given the state, if give_log == 0. If give_log == 1, lik should be set to the log likelihood.

If dmeasure is to be provided instead as an R function, this is accomplished by supplying

  dmeasure = f

to pomp, where f is a function. The arguments of f should be chosen from among the observables, state variables, parameters, covariates, and time. It must also have the arguments ..., and log. It can take additional arguments via the userdata facility. f must return a single numeric value, the probability density (or log probability density if log = TRUE) of y given x at time t.

Important note

It is a common error to fail to account for both log = TRUE and log = FALSE when writing the dmeasure C snippet or function.

Default behavior

If dmeasure is left unspecified, calls to dmeasure will return missing values (NA).

Note for Windows users

Some Windows users report problems when using C snippets in parallel computations. These appear to arise when the temporary files created during the C snippet compilation process are not handled properly by the operating system. To circumvent this problem, use the cdir and cfile options to cause the C snippets to be written to a file of your choice, thus avoiding the use of temporary files altogether.

See Also


More on implementing POMP models: Csnippet, accumvars, basic_components, betabinomial, covariates, dinit_spec, dprocess_spec, emeasure_spec, eulermultinom, parameter_trans(), pomp-package, pomp_constructor, prior_spec, rinit_spec, rmeasure_spec, rprocess_spec, skeleton_spec, transformations, userdata, vmeasure_spec


  ## We start with the pre-built Ricker example:
  ricker() -> po

  ## To change the measurement model density, dmeasure,
  ## we use the 'dmeasure' argument in any 'pomp'
  ## elementary or estimation function.
  ## Here, we pass the dmeasure specification to 'pfilter'
  ## as an R function.

  po |>
      dmeasure=function (y, N, phi, ..., log) {
    ) -> pf

  ## We can also pass it as a C snippet:

  po |>
      dmeasure=Csnippet("lik = dpois(y,phi*N,give_log);"),
    ) -> pf

pomp documentation built on July 1, 2024, 5:06 p.m.