Estimation of parameters by matching power spectra
# S4 method for data.frame
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend = c("none", "mean", "linear", "quadratic"),
params,
rinit,
rprocess,
rmeasure,
partrans,
...,
verbose = getOption("verbose", FALSE)
)# S4 method for pomp
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend = c("none", "mean", "linear", "quadratic"),
...,
verbose = getOption("verbose", FALSE)
)
# S4 method for spectd_pomp
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend,
...,
verbose = getOption("verbose", FALSE)
)
# S4 method for spect_match_objfun
spect_objfun(
data,
est,
weights,
fail.value,
seed = NULL,
...,
verbose = getOption("verbose", FALSE)
)
either a data frame holding the time series data, or an object of class ‘pomp’, i.e., the output of another pomp calculation.
character vector; the names of parameters to be estimated.
optional numeric or function.
The mismatch between model and data is measured by a weighted average of mismatch at each frequency.
By default, all frequencies are weighted equally.
weights
can be specified either as a vector (which must have length equal to the number of frequencies) or as a function of frequency.
If the latter, weights(freq)
must return a nonnegative weight for each frequency.
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).
optional; names of observed variables for which the power spectrum will be computed. By default, the spectrum will be computed for all observables.
width parameter for the smoothing kernel used for calculating the estimate of the spectrum.
the number of model simulations to be computed.
integer.
When fitting, it is often best to fix the seed of the random-number generator (RNG).
This is accomplished by setting seed
to an integer.
By default, seed = NULL
, which does not alter the RNG state.
function; this transformation will be applied to the observables prior to estimation of the spectrum, and prior to any detrending.
de-trending operation to perform. Options include no detrending, and subtraction of constant, linear, and quadratic trends from the data. Detrending is applied to each data series and to each model simulation independently.
optional; named numeric vector of parameters.
This will be coerced internally to storage mode double
.
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.
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.
simulator of the measurement model, 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 rmeasure=NULL
removes the measurement model simulator.
For more information, see ?rmeasure_spec.
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 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.
logical; if TRUE
, diagnostic messages will be printed to the console.
spect_objfun
constructs a stateful objective function for spectrum matching.
Specifically, spect_objfun
returns an object of class ‘spect_match_objfun’, which is a function suitable for use in an optim
-like optimizer.
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 (optionally weighted) \(L^2\) distance between the data spectrum and simulated spectra.
It is a stateful function:
Each time it is called, it will remember the values of the parameters and the discrepancy measure.
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.
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.
In spectrum matching, one attempts to minimize the discrepancy between a POMP model's predictions and data, as measured in the frequency domain by the power spectrum.
spect_objfun
constructs an objective function that measures the discrepancy.
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.
More on pomp estimation algorithms:
abc()
,
bsmc2()
,
estimation_algorithms
,
kalman
,
mif2()
,
nlf
,
pmcmc()
,
pomp-package
,
probe.match
# NOT RUN {
library(magrittr)
ricker() %>%
spect_objfun(
est=c("r","sigma","N_0"),
partrans=parameter_trans(log=c("r","sigma","N_0")),
paramnames=c("r","sigma","N_0"),
kernel.width=3,
nsim=100,
seed=5069977
) -> f
f(log(c(20,0.3,10)))
f %>% spect() %>% plot()
library(subplex)
subplex(fn=f,par=log(c(20,0.3,10)),control=list(reltol=1e-5)) -> out
f(out$par)
f %>% summary()
f %>% spect() %>% plot()
# }
Run the code above in your browser using DataLab