Learn R Programming

pomp (version 3.3)

traj.match: Trajectory matching

Description

Estimation of parameters for deterministic POMP models

Usage

# S4 method for data.frame
traj_objfun(
  data,
  est = character(0),
  fail.value = NA,
  ode_control = list(),
  params,
  rinit,
  skeleton,
  dmeasure,
  partrans,
  ...,
  verbose = getOption("verbose", FALSE)
)

# S4 method for pomp traj_objfun( data, est = character(0), fail.value = NA, ode_control = list(), ..., verbose = getOption("verbose", FALSE) )

# S4 method for traj_match_objfun traj_objfun( data, est, fail.value, ode_control, ..., verbose = getOption("verbose", FALSE) )

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.

est

character vector; the names of parameters to be estimated.

fail.value

optional numeric scalar; if non-NA, this value is substituted for non-finite values of the objective function. It should be a large number (i.e., bigger than any legitimate values the objective function is likely to take).

ode_control

optional list; the elements of this list will be passed to ode.

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.

skeleton

optional; the deterministic skeleton of the unobserved state process. Depending on whether the model operates in continuous or discrete time, this is either a vectorfield or a map. Accordingly, this is supplied using either the vectorfield or map fnctions. For more information, see ?skeleton_spec. Setting skeleton=NULL removes the deterministic skeleton.

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.

partrans

optional parameter transformations, constructed using parameter_trans.

Many algorithms for parameter estimation search an unconstrained space of parameters. When working with such an algorithm and a model for which the parameters are constrained, it can be useful to transform parameters. One should supply the partrans argument via a call to parameter_trans. For more information, see ?parameter_trans. Setting partrans=NULL removes the parameter transformations, i.e., sets them to the identity transformation.

additional arguments will modify the model structure

verbose

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

Value

traj_objfun constructs a stateful objective function for spectrum matching. Specifically, traj_objfun returns an object of class ‘traj_match_objfun’, which is a function suitable for use in an optim-like optimizer. In particular, this function takes a single numeric-vector argument that is assumed to contain the parameters named in est, in that order. When called, it will return the negative log likelihood. It is a stateful function: Each time it is called, it will remember the values of the parameters and its estimate of the log likelihood.

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 (described here) to cause the C snippets to be written to a file of your choice, thus avoiding the use of temporary files altogether.

Important Note

Since pomp cannot guarantee that the final call an optimizer makes to the function is a call at the optimum, it cannot guarantee that the parameters stored in the function are the optimal ones. Therefore, it is a good idea to evaluate the function on the parameters returned by the optimization routine, which will ensure that these parameters are stored.

Details

In trajectory matching, one attempts to minimize the discrepancy between a POMP model's predictions and data under the assumption that the latent state process is deterministic and all discrepancies between model and data are due to measurement error. The measurement model likelihood (dmeasure), or rather its negative, is the natural measure of the discrepancy.

Trajectory matching is a generalization of the traditional nonlinear least squares approach. In particular, if, on some scale, measurement errors are normal with constant variance, then trajectory matching is equivalent to least squares on that particular scale.

traj_objfun constructs an objective function that evaluates the likelihood function. It can be passed to any one of a variety of numerical optimization routines, which will adjust model parameters to minimize the discrepancies between the power spectrum of model simulations and that of the data.

See Also

trajectory, optim, subplex, nloptr

Examples

Run this code
# NOT RUN {
  library(magrittr)

  ricker() %>%
    traj_objfun(
      est=c("r","sigma","N_0"),
      partrans=parameter_trans(log=c("r","sigma","N_0")),
      paramnames=c("r","sigma","N_0"),
    ) -> f

  f(log(c(20,0.3,10)))

  library(subplex)
  subplex(fn=f,par=log(c(20,0.3,10)),control=list(reltol=1e-5)) -> out
  f(out$par)

  library(ggplot2)

  f %>%
    trajectory(format="data.frame") %>%
    ggplot(aes(x=time,y=N))+geom_line()+theme_bw()

# }

Run the code above in your browser using DataLab