nlf {pomp} | R Documentation |

## Nonlinear forecasting

### Description

Parameter estimation by maximum simulated quasi-likelihood.

### Usage

```
## S4 method for signature 'data.frame'
nlf_objfun(
data,
est = character(0),
lags,
nrbf = 4,
ti,
tf,
seed = NULL,
transform.data = identity,
period = NA,
tensor = TRUE,
fail.value = NA_real_,
params,
rinit,
rprocess,
rmeasure,
...,
verbose = getOption("verbose")
)
## S4 method for signature 'pomp'
nlf_objfun(
data,
est = character(0),
lags,
nrbf = 4,
ti,
tf,
seed = NULL,
transform.data = identity,
period = NA,
tensor = TRUE,
fail.value = NA,
...,
verbose = getOption("verbose")
)
## S4 method for signature 'nlf_objfun'
nlf_objfun(
data,
est,
lags,
nrbf,
ti,
tf,
seed = NULL,
period,
tensor,
transform.data,
fail.value,
...,
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.
Internally, |

`est` |
character vector; the names of parameters to be estimated. |

`lags` |
A vector specifying the lags to use when constructing the nonlinear autoregressive prediction model. The first lag is the prediction interval. |

`nrbf` |
integer scalar; the number of radial basis functions to be used at each lag. |

`ti` , `tf` |
required numeric values.
NLF works by generating simulating long time series from the model.
The simulated time series will be from |

`seed` |
integer.
When fitting, it is often best to fix the seed of the random-number generator (RNG).
This is accomplished by setting |

`transform.data` |
optional function.
If specified, forecasting is performed using data and model simulations transformed by this function.
By default, |

`period` |
numeric; |

`tensor` |
logical; if FALSE, the fitted model is a generalized additive model with time mod period as one of the predictors, i.e., a gam with time-varying intercept. If TRUE, the fitted model is a gam with lagged state variables as predictors and time-periodic coefficients, constructed using tensor products of basis functions of state variables with basis functions of time. |

`fail.value` |
optional numeric scalar;
if non- |

`params` |
optional; named numeric vector of parameters.
This will be coerced internally to storage mode |

`rinit` |
simulator of the initial-state distribution.
This can be furnished either as a C snippet, an |

`rprocess` |
simulator of the latent state process, specified using one of the rprocess plugins.
Setting |

`rmeasure` |
simulator of the measurement model, specified either as a C snippet, an |

`...` |
additional arguments are passed to |

`verbose` |
logical; if |

### Details

Nonlinear forecasting (NLF) is an ‘indirect inference’ method. The NLF approximation to the log likelihood of the data series is computed by simulating data from a model, fitting a nonlinear autoregressive model to the simulated time series, and quantifying the ability of the resulting fitted model to predict the data time series. The nonlinear autoregressive model is implemented as a generalized additive model (GAM), conditional on lagged values, for each observation variable. The errors are assumed multivariate normal.

The NLF objective function constructed by `nlf_objfun`

simulates long time series (`nasymp`

is the number of observations in the simulated times series), perhaps after allowing for a transient period (`ntransient`

steps).
It then fits the GAM for the chosen lags to the simulated time series.
Finally, it computes the quasi-likelihood of the data under the fitted GAM.

NLF assumes that the observation frequency (equivalently the time between successive observations) is uniform.

### Value

`nlf_objfun`

constructs a stateful objective function for NLF estimation.
Specfically, `nlf_objfun`

returns an object of class ‘nlf_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 quasilikelihood.
It is a stateful function:
Each time it is called, it will remember the values of the parameters and its estimate of the log quasilikelihood.

### Periodically-forced systems (seasonality)

Unlike other pomp estimation methods, NLF cannot accommodate general time-dependence in the model via explicit time-dependence or dependence on time-varying covariates.
However, NLF can accommodate periodic forcing.
It does this by including forcing phase as a predictor in the nonlinear autoregressive model.
To accomplish this, one sets `period`

to the period of the forcing (a positive numerical value).
In this case, if `tensor = FALSE`

, the effect is to add a periodic intercept in the autoregressive model.
If `tensor = TRUE`

, by contrast, the fitted model includes time-periodic coefficients,
constructed using tensor products of basis functions of observables with
basis functions of time.

### 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.

### 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.

### Warning! Objective functions based on C snippets

If you use C snippets (see `Csnippet`

), a dynamically loadable library will be built.
As a rule, pomp functions load this library as needed and unload it when it is no longer needed.
The stateful objective functions are an exception to this rule.
For efficiency, calls to the objective function do not execute `pompLoad`

or `pompUnload`

:
rather, it is assumed that `pompLoad`

has been called before any call to the objective function.
When a stateful objective function using one or more C snippets is created, `pompLoad`

is called internally to build and load the library:
therefore, within a single **R** session, if one creates a stateful objective function, one can freely call that objective function and (more to the point) pass it to an optimizer that calls it freely, without needing to call `pompLoad`

.
On the other hand, if one retrieves a stored objective function from a file, or passes one to another **R** session, one must call `pompLoad`

before using it.
**Failure to do this will typically result in a segmentation fault (i.e., it will crash the R session).**

### Author(s)

Stephen P. Ellner, Bruce E. Kendall, Aaron A. King

### References

S.P. Ellner, B.A. Bailey, G.V. Bobashev, A.R. Gallant, B.T. Grenfell, and D.W. Nychka. Noise and nonlinearity in measles epidemics: combining mechanistic and statistical approaches to population modeling. *American Naturalist* **151**, 425–440, 1998. doi:10.1086/286130.

B.E. Kendall, C.J. Briggs, W.W. Murdoch, P. Turchin, S.P. Ellner, E. McCauley, R.M. Nisbet, and S.N. Wood. Why do populations cycle? A synthesis of statistical and mechanistic modeling approaches. *Ecology* **80**, 1789–1805, 1999. doi:10.2307/176658.

B.E. Kendall, S.P. Ellner, E. McCauley, S.N. Wood, C.J. Briggs, W.W. Murdoch, and P. Turchin. Population cycles in the pine looper moth (*Bupalus piniarius*): dynamical tests of mechanistic hypotheses. *Ecological Monographs* **75** 259–276, 2005. doi:10.1890/03-4056.

### See Also

More on pomp estimation algorithms:
`abc()`

,
`bsmc2()`

,
`estimation_algorithms`

,
`mif2()`

,
`pmcmc()`

,
`pomp-package`

,
`probe_match`

,
`spect_match`

More on methods based on summary statistics:
`abc()`

,
`basic_probes`

,
`probe()`

,
`probe_match`

,
`spect()`

,
`spect_match`

More on maximization-based estimation methods:
`mif2()`

,
`probe_match`

,
`spect_match`

,
`traj_match`

### Examples

```
if (require(subplex)) {
ricker() |>
nlf_objfun(est=c("r","sigma","N_0"),lags=c(4,6),
partrans=parameter_trans(log=c("r","sigma","N_0")),
paramnames=c("r","sigma","N_0"),
ti=100,tf=2000,seed=426094906L) -> m1
subplex(par=log(c(20,0.5,5)),fn=m1,control=list(reltol=1e-4)) -> out
m1(out$par)
coef(m1)
plot(simulate(m1))
}
```

*pomp*version 5.11.0.0 Index]