dmeasure_spec | R Documentation |

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:

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.Moreover, the Boolean variable

`give_log`

will be defined.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`

.

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

If `dmeasure`

is left unspecified, calls to `dmeasure`

will return missing values (`NA`

).

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.

`dmeasure`

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 |>
pfilter(
dmeasure=function (y, N, phi, ..., log) {
dpois(y,lambda=phi*N,log=log)
},
Np=100
) -> pf
## We can also pass it as a C snippet:
po |>
pfilter(
dmeasure=Csnippet("lik = dpois(y,phi*N,give_log);"),
paramnames="phi",
statenames="N",
Np=100
) -> pf
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.