Title: | Inference for Spatiotemporal Partially Observed Markov Processes |
---|---|
Description: | Inference on panel data using spatiotemporal partially-observed Markov process (SpatPOMP) models. The 'spatPomp' package extends 'pomp' to include algorithms taking advantage of the spatial structure in order to assist with handling high dimensional processes. See Asfaw et al. (2024) <doi:10.48550/arXiv.2101.01157> for further description of the package. |
Authors: | Kidus Asfaw [aut], Edward Ionides [cre, aut], Aaron A. King [aut], Allister Ho [ctb], Joonha Park [ctb], Jesse Wheeler [ctb], Jifan Li [ctb], Ning Ning [ctb], Haogao Gu [ctb] |
Maintainer: | Edward Ionides <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-11-15 07:29:39 UTC |
Source: | https://github.com/spatpomp-org/spatpomp |
The spatPomp package provides facilities for inference on panel data using spatiotemporal partially-observed Markov process (SpatPOMP) models. To do so, it relies on and extends a number of facilities that the pomp package provides for inference on time series data using partially-observed Markov process (POMP) models.
The spatPomp package concerns models consisting of a collection of interacting units. The methods in spatPomp may be applicable whether or not these units correspond to spatial locations.
The first step in using spatPomp is to encode one's model(s) and data
in objects of class spatPomp
.
This can be done via a call to the spatPomp
constructor
function.
spatPomp extends to panel data the general interface to the components of POMP models provided by pomp. In doing so, it contributes to the goal of the pomp project of facilitating the development of new algorithms in an environment where they can be tested and compared on a growing body of models and datasets.
spatPomp is described by Asfaw et al. (2020)
spatPomp is provided under the MIT License.
Kidus Asfaw, Joonha Park, Allister Ho, Edward Ionides, Aaron A. King
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
An algorithm for estimating the likelihood of a spatiotemporal partially-observed Markov process model.
Running abf
causes the algorithm to run bootstrap replicate jobs which each yield an imperfect adapted simulation. Simulating from the "adapted filter"
distribution runs into a curse of dimensionality (COD) problem, which is mitigated by keeping particles in each replicate close to each other through resampling down
to one particle per replicate at each observation time point.
The adapted simulations are then weighted in a way that mitigates COD by making a weak coupling assumption to get an approximate filter distribution.
As a by-product, we also get an estimate of the likelihood of the data.
## S4 method for signature 'spatPomp' abf( object, Nrep, Np, nbhd, params, tol = 1e-100, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'abfd_spatPomp' abf( object, Nrep, Np, nbhd, tol, ..., verbose = getOption("spatPomp_verbose", FALSE) )
## S4 method for signature 'spatPomp' abf( object, Nrep, Np, nbhd, params, tol = 1e-100, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'abfd_spatPomp' abf( object, Nrep, Np, nbhd, tol, ..., verbose = getOption("spatPomp_verbose", FALSE) )
object |
A |
Nrep |
The number of bootstrap replicates for the adapted simulations. |
Np |
The number of particles used within each replicate for the adapted simulations. |
nbhd |
A neighborhood function with three arguments: |
params |
Parameter vector, required if not available from the spatPomp model object. |
tol |
If the resampling weight for a particle is zero due to floating-point precision issues, it is set to the value of |
... |
Additional arguments can be used to replace model components. |
verbose |
logical; if |
Upon successful completion, abf()
returns an object of class
‘abfd_spatPomp’ containing the algorithmic parameters used to run abf()
and the estimated likelihood.
The following methods are available for such an object:
logLik
yields an estimate of the log-likelihood of the data under the model.
Kidus Asfaw
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
likelihood maximization algorithms: ienkf()
, igirf
, iubf
, ibpf
Other likelihood evaluation algorithms:
abfir()
,
bpfilter()
,
enkf()
,
girf()
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Create a neighborhood function mapping a point in space-time # to a list of neighboring points in space-time bm_nbhd <- function(object, time, unit) { nbhd_list = list() if(time > 1 && unit > 1){ nbhd_list = c(nbhd_list, list(c(unit-1, time-1))) } return(nbhd_list) } # Run ABF specified number of Monte Carlo replicates and particles per replicate abfd_bm <- abf(b, Nrep=2, Np=10, nbhd=bm_nbhd) # Get the likelihood estimate from ABF logLik(abfd_bm) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Create a neighborhood function mapping a point in space-time # to a list of neighboring points in space-time bm_nbhd <- function(object, time, unit) { nbhd_list = list() if(time > 1 && unit > 1){ nbhd_list = c(nbhd_list, list(c(unit-1, time-1))) } return(nbhd_list) } # Run ABF specified number of Monte Carlo replicates and particles per replicate abfd_bm <- abf(b, Nrep=2, Np=10, nbhd=bm_nbhd) # Get the likelihood estimate from ABF logLik(abfd_bm) ## End(Not run)
An algorithm for estimating the filter distribution and likelihood of a spatiotemporal partially-observed Markov process model.
Running abfir
causes the algorithm to run Monte Carlo replicated jobs which
each carry out an adapted simulation using intermediate resampling.
Adapted simulation is an easier task than filtering, since particles in each replicate
remain close to each other. Intermediate resampling further assists against
the curse of dimensionality (COD) problem for importance sampling.
The adapted simulations are then weighted in a way that mitigates COD by
making a weak coupling assumption to get an approximate filter distribution.
As a by-product, we also get an approximation to the likelihood of the data.
## S4 method for signature 'spatPomp' abfir( object, Np, Nrep, nbhd, Ninter, tol = (1e-100), params, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'abfird_spatPomp' abfir(object, Np, Nrep, nbhd, Ninter, tol, params, ...)
## S4 method for signature 'spatPomp' abfir( object, Np, Nrep, nbhd, Ninter, tol = (1e-100), params, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'abfird_spatPomp' abfir(object, Np, Nrep, nbhd, Ninter, tol, params, ...)
object |
A |
Np |
The number of particles used within each replicate for the adapted simulations. |
Nrep |
The number of bootstrap replicates for the adapted simulations. |
nbhd |
A neighborhood function with three arguments: |
Ninter |
the number of intermediate resampling time points. By default, this is set equal to the number of units. |
tol |
If the resampling weight for a particle is zero due to floating-point precision issues, it is set to the value of |
params |
Parameter vector, required if not available from the spatPomp model object. |
... |
Additional arguments can be used to replace model components. |
verbose |
logical; if |
Upon successful completion, abfir()
returns an object of class
‘abfird_spatPomp’ containing the algorithmic parameters used to run abfir()
and the estimated likelihood.
The following methods are available for such an object:
logLik
yields a biased estimate of the log-likelihood of the data under the model.
Kidus Asfaw
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
likelihood maximization algorithms: ienkf()
, igirf()
, iubf()
, ibpf()
Other likelihood evaluation algorithms:
abf()
,
bpfilter()
,
enkf()
,
girf()
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Create a neighborhood function mapping a point in space-time # to a list of ``neighboring points" in space-time bm_nbhd <- function(object, time, unit) { nbhd_list = list() if(time > 1 && unit > 1){ nbhd_list = c(nbhd_list, list(c(unit-1, time-1))) } return(nbhd_list) } # Run ABFIR with specified number of Monte Carlo replicates and particles # per replicate abfird_bm <- abfir(b, Nrep = 2, Np=10, nbhd = bm_nbhd, Ninter = length(unit_names(b))) # Get the likelihood estimate from ABFIR logLik(abfird_bm) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Create a neighborhood function mapping a point in space-time # to a list of ``neighboring points" in space-time bm_nbhd <- function(object, time, unit) { nbhd_list = list() if(time > 1 && unit > 1){ nbhd_list = c(nbhd_list, list(c(unit-1, time-1))) } return(nbhd_list) } # Run ABFIR with specified number of Monte Carlo replicates and particles # per replicate abfird_bm <- abfir(b, Nrep = 2, Np=10, nbhd = bm_nbhd, Ninter = length(unit_names(b))) # Get the likelihood estimate from ABFIR logLik(abfird_bm) ## End(Not run)
Fits independent log-ARMA models for each unit, and calculates the conditional log-likelihood for each observation, as well as log-likelihood for each unit and total log-likelihood. A simple tool, but one with practical applicability, as demonstrated by King et al (2008) and Wheeler et al (2023). This function is designed for non-negative data, and adds 1 to each observation to avoid log(0).
arma_benchmark(spo, order = c(2, 0, 1))
arma_benchmark(spo, order = c(2, 0, 1))
spo |
A spatPomp object |
order |
A triple (p,d,q) for the ARIMA model fitted to the data. It is intended that d=0 |
Edward L. Ionides
King, A. A., Ionides, E. L., Pascual, M. and Bouma, M. J. (2008). Inapparent infections and cholera dynamics. Nature 454 877-880.
Wheeler, J., Rosengart, A. L., Jiang, Z., Tan, K., Treutle, N. and Ionides, E. L. (2023). Informing policy via dynamic models: Cholera in Haiti. arxiv:2301.08979.
Other utilities:
expand_params()
# Complete examples are provided in the package tests ## Not run: m <- he10(U = 5) arma_benchmark(m) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: m <- he10(U = 5) arma_benchmark(m) ## End(Not run)
spatPomp objects can be recast as data frames.
## S3 method for class 'spatPomp' as.data.frame(x, ...)
## S3 method for class 'spatPomp' as.data.frame(x, ...)
x |
a |
... |
additional arguments to be passed to or from methods. |
When object
is a simple ‘spatPomp’ object,
as(object,"data.frame")
or as.data.frame(object)
results in a
data frame with the times, units, observables, states (if known), and
interpolated covariates (if any).
A ‘data.frame’ with columns for time, spatial unit and observations.
Generate a class ‘spatPomp’ object representing a U
-dimensional
Brownian motion with spatial correlation decaying geometrically with
distance around a circle. The model is defined in continuous time
though in this case an Euler approximation is exact at the evaluation
times.
bm(U = 5, N = 100, delta_t = 0.1)
bm(U = 5, N = 100, delta_t = 0.1)
U |
A length-one numeric signifying dimension of the process. |
N |
A length-one numeric signifying the number of observation time steps to evolve the process. |
delta_t |
Process simulations are performed every |
An object of class ‘spatPomp’ representing a simulation from a U
-dimensional
Brownian motion
Edward L. Ionides
Other spatPomp model generators:
bm2()
,
gbm()
,
he10()
,
lorenz()
,
measles()
# Complete examples are provided in the package tests ## Not run: b <- bm(U=4, N=20) # See all the model specifications of the object spy(b) # Examples of methodologies applied to this model # are provided in the tests directory ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=4, N=20) # See all the model specifications of the object spy(b) # Examples of methodologies applied to this model # are provided in the tests directory ## End(Not run)
Computes the exact likelihood for a model constructed using bm
,
using the Kalman filter. This model is useful for testing methods
in a situation where an exact answer is available
bm_kalman_logLik(bm_object, params = coef(bm_object))
bm_kalman_logLik(bm_object, params = coef(bm_object))
bm_object |
A spatPomp model built using |
params |
A parameter vector at which to evaluate the log-likelihood. whereas observations occur every one time unit |
A numeric value for the log-likelihood.
Edward L. Ionides
# Further examples are provided in the tests directory ## Not run: b <- bm() bm_kalman_logLik(b) ## End(Not run)
# Further examples are provided in the tests directory ## Not run: b <- bm() bm_kalman_logLik(b) ## End(Not run)
An extension of bm
allowing for shared or unit-specific parameters.
Generate a class ‘spatPomp’ object representing a U
-dimensional
Brownian motion with spatial correlation decaying geometrically with
distance around a circle. The model is defined in continuous time
though in this case an Euler approximation is exact at the evaluation
times.
bm2( U = 5, N = 100, delta_t = 0.1, unit_specific_names = "rho", shared_names = NULL, unit_params = c(rho = 0.4, sigma = 1, tau = 1, X_0 = 0) )
bm2( U = 5, N = 100, delta_t = 0.1, unit_specific_names = "rho", shared_names = NULL, unit_params = c(rho = 0.4, sigma = 1, tau = 1, X_0 = 0) )
U |
A length-one numeric signifying dimension of the process. |
N |
A length-one numeric signifying the number of observation time steps to evolve the process. |
delta_t |
Process simulations are performed every |
unit_specific_names |
determines which parameters take a different value for each unit. Cannot be specified if shared_names is specified. each unit. Other parameters are considered shared between all units. |
shared_names |
identifies parameters that have common shared value for all units, which by default is all parameters. |
unit_params |
parameter values used to build the object, copied across each unit for unit-specific parameters |
An object of class ‘spatPomp’ representing a simulation from a
U
-dimensional Brownian motion
Edward L. Ionides
Other spatPomp model generators:
bm()
,
gbm()
,
he10()
,
lorenz()
,
measles()
# Complete examples are provided in the package tests ## Not run: b <- bm2(U=4, N=20,shared_names="rho",unit_specific_names=c("sigma","tau")) # See all the model specifications of the object spy(b) # Examples of methodologies applied to this model # are provided in the tests directory ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm2(U=4, N=20,shared_names="rho",unit_specific_names=c("sigma","tau")) # See all the model specifications of the object spy(b) # Examples of methodologies applied to this model # are provided in the tests directory ## End(Not run)
Computes the exact likelihood for a model constructed using bm2
,
using the Kalman filter. This model is useful for testing methods
for models with unit-specific parameters, or method such as ibpf
which require a unit-specific extension of shared parameters.
bm2_kalman_logLik(bm2_object, params = coef(bm2_object))
bm2_kalman_logLik(bm2_object, params = coef(bm2_object))
bm2_object |
A spatPomp model built using |
params |
A parameter vector at which to evaluate the log-likelihood. whereas observations occur every one time unit |
A numeric value for the log-likelihood.
Edward L. Ionides
# Further examples are provided in the tests directory ## Not run: b <- bm2() bm2_kalman_logLik(b) ## End(Not run)
# Further examples are provided in the tests directory ## Not run: b <- bm2() bm2_kalman_logLik(b) ## End(Not run)
An implementation of the block particle filter algorithm of Rebeschini and van Handel (2015), which is used to estimate the filter distribution
of a spatiotemporal partially-observed Markov process.
bpfilter
requires a partition of the spatial units which can be provided by either the block_size
or the block_list
argument.
The elements of the partition are called blocks. We perform resampling for each block independently based on sample weights within the block.
Each resampled block only contains latent states for the spatial components within the block which allows for a “cross-pollination" of
particles where the highest weighted segments of each particle are more likely to be resampled and get combined with resampled components of
other particles. The method mitigates the curse of dimensionality by resampling locally.
## S4 method for signature 'missing' bpfilter(object, ...) ## S4 method for signature 'ANY' bpfilter(object, ...) ## S4 method for signature 'spatPomp' bpfilter( object, Np, block_size, block_list, save_states, filter_traj, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'bpfilterd_spatPomp' bpfilter( object, Np, block_size, block_list, save_states, filter_traj, ..., verbose = getOption("spatPomp_verbose", FALSE) )
## S4 method for signature 'missing' bpfilter(object, ...) ## S4 method for signature 'ANY' bpfilter(object, ...) ## S4 method for signature 'spatPomp' bpfilter( object, Np, block_size, block_list, save_states, filter_traj, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'bpfilterd_spatPomp' bpfilter( object, Np, block_size, block_list, save_states, filter_traj, ..., verbose = getOption("spatPomp_verbose", FALSE) )
object |
A |
... |
If a |
Np |
The number of particles used within each replicate for the adapted simulations. |
block_size |
The number of spatial units per block. If this is provided, the method subdivides units approximately evenly
into blocks with size |
block_list |
List that specifies an exact partition of the spatial units. Each partition element, or block, is an integer vector of neighboring units. |
save_states |
logical. If True, the state-vector for each particle and block is saved. |
filter_traj |
logical; if |
verbose |
logical; if |
Upon successful completion, bpfilter()
returns an object of class
‘bpfilterd_spatPomp’ containing the algorithmic parameters used to run bpfilter()
and the estimated likelihood.
Only one of block_size
or block_list
should be specified.
If both or neither is provided, an error is triggered.
The following methods are available for such an object:
logLik
yields an estimate of the log-likelihood of the data under the model.
Kidus Asfaw
Rebeschini, P., & Van Handel, R. (2015). Can local particle filters beat the curse of dimensionality?. The Annals of Applied Probability, 25(5), 2809-2866.
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
likelihood maximization algorithms: ienkf()
, igirf()
, iubf()
, ibpf()
Other likelihood evaluation algorithms:
abf()
,
abfir()
,
enkf()
,
girf()
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=4, N=2) # Run BPF with the specified number of units per block bpfilterd_b1 <- bpfilter(b, Np = 10, block_size = 2) # Run BPF with the specified partition bpfilterd_b2 <- bpfilter(b, Np = 10, block_list = list(c(1,2),c(3,4)) ) # Get a likelihood estimate logLik(bpfilterd_b2) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=4, N=2) # Run BPF with the specified number of units per block bpfilterd_b1 <- bpfilter(b, Np = 10, block_size = 2) # Run BPF with the specified partition bpfilterd_b2 <- bpfilter(b, Np = 10, block_list = list(c(1,2),c(3,4)) ) # Get a likelihood estimate logLik(bpfilterd_b2) ## End(Not run)
Population and birth information about cities in England and Wales during the measles pre-vaccine era.
Data includes births and population at bi-weekly observations from 40 cities and towns.
a ‘data.frame’ of the 40 largest cities and towns in the UK and Wales, their latitude, longitude and mean population during the measles pre-vaccine period.
Dalziel, Benjamin D. et al. (2016) Persistent chaos of measles epidemics in the prevaccination United States caused by a small change in seasonal transmission patterns. PLoS Computational Biology, 12(2), e1004655. doi:10.5061/dryad.r4q34
Other datasets:
measlesUK
Concatenate two or more ‘pomp’ objects into a list-like ‘listie’.
## S3 method for class 'SpatPomp' c(...)
## S3 method for class 'SpatPomp' c(...)
... |
elements to be recursively combined into a ‘listie’ |
concat
applied to one or more ‘pomp’ objects or lists of ‘pomp’ objects converts the list into a ‘listie’.
In particular, concat(A,B,C)
is equivalent to do.call(c,unlist(list(A,B,C)))
.
dunit_measure
evaluates the unit measurement density of a unit's observation given the entire statedunit_measure
dunit_measure
evaluates the unit measurement density of a unit's observation given the entire state
## S4 method for signature 'spatPomp' dunit_measure(object, y, x, unit, time, params, log = TRUE, ...)
## S4 method for signature 'spatPomp' dunit_measure(object, y, x, unit, time, params, log = TRUE, ...)
object |
An object of class |
y |
A U by 1 matrix of observations for all units |
x |
A state vector for all units |
unit |
The unit for which to evaluate the unit measurement density |
time |
The time for which to evaluate the unit measurement density |
params |
parameters at which to evaluate the unit measurement density |
log |
logical; should the density be returned on log scale? |
... |
additional arguments will be ignored |
A class ‘matrix’ with the unit measurement density for spatial unit unit
corresponding to the corresponding measurement in y
and states in x
.
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] dunit_measure(b, y=o, x=s, unit=1, time=1, params=p) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] dunit_measure(b, y=o, x=s, unit=1, time=1, params=p) ## End(Not run)
A function to perform filtering using the ensemble Kalman filter of Evensen, G. (1994). This function is generalized to allow for an measurement covariance matrix that varies over time. This is useful if the measurement model varies with the state.
## S4 method for signature 'spatPomp' enkf(data, Np, ..., verbose = getOption("spatPomp_verbose", FALSE))
## S4 method for signature 'spatPomp' enkf(data, Np, ..., verbose = getOption("spatPomp_verbose", FALSE))
data |
A |
Np |
The number of Monte Carlo particles used to approximate the filter distribution. |
... |
Additional arguments can be used to replace model components. |
verbose |
logical; if |
An object of class ‘enkfd_spatPomp’ that contains the estimate of the log likelihood
(via the loglik
attribute), algorithmic parameters used to run enkf()
. Also included
are estimated filter means, prediction means and forecasts that are generated during an enkf()
run.
G. Evensen. Sequential data assimilation with a nonlinear quasi-geostrophic model using Monte Carlo methods to forecast error statistics. Journal of Geophysical Research: Oceans 99, 10143–10162, 1994.
G. Evensen. Data assimilation: the ensemble Kalman filter. Springer-Verlag, 2009.
J.L. Anderson. An Ensemble Adjustment Kalman Filter for Data Assimilation. Monthly Weather Review 129, 2884–2903, 2001.
ienkf()
, igirf
, iubf
, ibpf
Other likelihood evaluation algorithms:
abf()
,
abfir()
,
bpfilter()
,
girf()
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Run EnKF enkfd_bm <- enkf(b, Np = 20) # Get a likelihood estimate logLik(enkfd_bm) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Run EnKF enkfd_bm <- enkf(b, Np = 20) # Get a likelihood estimate logLik(enkfd_bm) ## End(Not run)
eunit_measure
evaluates the expectation of a unit's observation given the entire state
## S4 method for signature 'spatPomp' eunit_measure(object, x, unit, time, params, Np = 1, log = FALSE)
## S4 method for signature 'spatPomp' eunit_measure(object, x, unit, time, params, Np = 1, log = FALSE)
object |
An object of class |
x |
A state vector for all units |
unit |
The unit for which to evaluate the expectation |
time |
The time for which to evaluate the expectation |
params |
parameters at which to evaluate the unit expectation |
Np |
numeric; defaults to 1 and the user need not change this |
log |
logical; should the density be returned on log scale? |
A class ‘matrix’ with the unit expected observation for spatial unit unit
corresponding to the corresponding states in x
.
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] eunit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] eunit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)
Iterated block particle filters require shared parameters to be expanded into having a value at each unit. expand_params, contract_params and mean_by_unit provide tools for moving between representations. For a unit-specific expansion of a shared parameter, all the values for different units should be the same, and mean_by_unit ensures this by taking an average.
expand_params(params, expandedParNames, U) contract_params(params, expandedParNames, U, average = FALSE) mean_by_unit(params, expandedParNames, U)
expand_params(params, expandedParNames, U) contract_params(params, expandedParNames, U, average = FALSE) mean_by_unit(params, expandedParNames, U)
params |
Input parameter vector |
expandedParNames |
character vector of parameters that are, or should be, expanded. These names should have no numerical suffix 1:U. |
U |
Number of units |
average |
Logical value for whether contract_params should average unequal values |
These functions assume that expanded parameters have names ending in "1" through "U", where U is the number of units. Contracted parameters, meaning any parameter that is not expanded, should have a name ending in "1". This numerical suffix convention is useful for writing model-building code that allows parameters to be either expanded or contracted.
Other utilities:
arma_benchmark()
Generate a spatPomp object representing a U
-dimensional
geometric Brownian motion with spatial correlation decaying geometrically with
distance around a circle. The model is defined in continuous time, but
an Euler approximation is used for this numerical implementation.
gbm(U = 5, N = 100, delta_t = 0.1, IVP_values = 1, delta_obs = 1)
gbm(U = 5, N = 100, delta_t = 0.1, IVP_values = 1, delta_obs = 1)
U |
A length-one numeric signifying dimension of the process. |
N |
A length-one numeric signifying the number of time steps to evolve the process. |
delta_t |
process simulations are performed every |
IVP_values |
initial value parameters for the latent states |
delta_obs |
observations occur every |
An object of class ‘spatPomp’ representing a simulation from a U
-dimensional
geometric Brownian motion
Kidus Asfaw
Asfaw, K. T. (2021). Simulation-based Inference for Partially Observed Markov Process Models with Spatial Coupling. University of Michigan Doctoral dissertation. doi:10.7302/2751
Other spatPomp model generators:
bm()
,
bm2()
,
he10()
,
lorenz()
,
measles()
# Complete examples are provided in the package tests ## Not run: g <- gbm(U=4, N=20) # See all the model specifications of the object spy(g) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: g <- gbm(U=4, N=20) # See all the model specifications of the object spy(g) ## End(Not run)
An implementation of the algorithm of Park and Ionides (2020), following the pseudocode in Asfaw et al. (2020).
## S4 method for signature 'missing' girf(object, ...) ## S4 method for signature 'ANY' girf(object, ...) ## S4 method for signature 'spatPomp' girf( object, Np, Ninter, lookahead = 1, Nguide, kind = c("bootstrap", "moment"), tol, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'girfd_spatPomp' girf( object, Np, Ninter, lookahead, Nguide, kind = c("bootstrap", "moment"), tol, ... )
## S4 method for signature 'missing' girf(object, ...) ## S4 method for signature 'ANY' girf(object, ...) ## S4 method for signature 'spatPomp' girf( object, Np, Ninter, lookahead = 1, Nguide, kind = c("bootstrap", "moment"), tol, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'girfd_spatPomp' girf( object, Np, Ninter, lookahead, Nguide, kind = c("bootstrap", "moment"), tol, ... )
object |
A |
... |
Additional arguments can be used to replace model components. |
Np |
The number of particles used within each replicate for the adapted simulations. |
Ninter |
the number of intermediate resampling time points. By default, this is set equal to the number of units. |
lookahead |
The number of future observations included in the guide function. |
Nguide |
The number of simulations used to estimate state process uncertainty for each particle. |
kind |
One of two types of guide function construction. Defaults to |
tol |
If all of the guide function evaluations become too small (beyond floating-point precision limits), we set them to this value. |
verbose |
logical; if |
Upon successful completion, girf()
returns an object of class
‘girfd_spatPomp’ which contains the algorithmic parameters that were used to
run girf()
and the resulting log likelihood estimate.
The following methods are available for such an object:
logLik
yields an unbiased estimate of the log-likelihood of the data under the model.
Kidus Asfaw
Park, J. and Ionides, E. L. (2020) Inference on high-dimensional implicit dynamic models using a guided intermediate resampling filter. Statistics and Computing, doi:10.1007/s11222-020-09957-3
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
likelihood maximization algorithms: ienkf()
, igirf()
, iubf()
, ibpf()
Other likelihood evaluation algorithms:
abf()
,
abfir()
,
bpfilter()
,
enkf()
# Complete examples are provided in the package tests ## Not run: # # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Run GIRF girfd_bm <- girf(b, Np = 10, Ninter = length(unit_names(b)), lookahead = 1, Nguide = 10 ) # Get the likelihood estimate from GIRF logLik(girfd_bm) # Compare with the likelihood estimate from particle filter pfd_bm <- pfilter(b, Np = 10) logLik(pfd_bm) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # # Create a simulation of a Brownian motion b <- bm(U=2, N=5) # Run GIRF girfd_bm <- girf(b, Np = 10, Ninter = length(unit_names(b)), lookahead = 1, Nguide = 10 ) # Get the likelihood estimate from GIRF logLik(girfd_bm) # Compare with the likelihood estimate from particle filter pfd_bm <- pfilter(b, Np = 10) logLik(pfd_bm) ## End(Not run)
Generate a spatPomp object for measles adding spatial coupling to The model and data from He et al. (2010) with gravity transport as in Park and Ionides (2020). Other transport models may be added in future. The data in the object matches He et al. (2010). The model matches that analysis in the specific case where there is no coupling and all parameters are unit-specific.
he10( U = 6, dt = 2/365, Tmax = 1964, expandedParNames = c("alpha", "iota", "R0", "cohort", "amplitude", "gamma", "sigma", "sigmaSE", "rho", "psi", "g", "S_0", "E_0", "I_0"), basic_params = c(alpha = 1, iota = 0, R0 = 30, cohort = 0, amplitude = 0.5, gamma = 52, sigma = 52, mu = 0.02, sigmaSE = 0.15, rho = 0.5, psi = 0.15, g = 400, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05), towns_selected = NULL )
he10( U = 6, dt = 2/365, Tmax = 1964, expandedParNames = c("alpha", "iota", "R0", "cohort", "amplitude", "gamma", "sigma", "sigmaSE", "rho", "psi", "g", "S_0", "E_0", "I_0"), basic_params = c(alpha = 1, iota = 0, R0 = 30, cohort = 0, amplitude = 0.5, gamma = 52, sigma = 52, mu = 0.02, sigmaSE = 0.15, rho = 0.5, psi = 0.15, g = 400, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05), towns_selected = NULL )
U |
A length-one numeric signifying the number of cities to be represented in the spatPomp object. Default U=20 gives all the towns studied by He et al., the 10 largest and 10 selected smaller towns. |
dt |
a numeric (in unit of years) that is used as the Euler time-increment for simulating measles data. |
Tmax |
Upper time for the window used to construct the object. The lower time is fixed at 1950.0. The default value matches He et al (2010). |
expandedParNames |
specifies the names of parameters which take unit-specific values. Remaining parameters take a single, shared value for all units. |
basic_params |
A candidate parameter vector in the basic format, i.e., no unit-specific parameters or unit-related name extensions. |
towns_selected |
A numeric vector of towns to be modeled. Defaults to 1:U, with cities ranked by decreasing population and 1 being London. |
The code for this spatPomp has duplication with measles(), but in future the two models may diverge. The measles() spatPomp is a simplified situation useful for testing some methods. However, measles() does not permit unit-specific parameters, which he10() allows. Also, the structure of this spatPomp is compatible with the spatiotemporal iterated filtering algorithm ibpf(). This requires shared parameters to be represented with a value for each unit, which should be the same for each unit in a valid model instance but may vary between units while optimizing.
An object of class ‘spatPomp’ representing a U
-dimensional spatially coupled measles POMP model.
The model generator he10()
differs from measles()
in some details necessitated to reproduce the results of He et al (2010).
The measles()
model follows the decision of Park and Ionides (2020) and Ionides et al (2021) to apply the mixing exponent to
rather than just to
.
he10()
does this for the infections arising from individuals traveling to another town (which don't arise for the panel model of He et al (2010)).
However, for infections arising within a city, in order to reproduce the results of He et al (2010), he10()
uses .
This is not fully documented in the text of Ionides et al (2022).
Models fitted to data have
close to
, so this issue may be negligible in practice.
Another discrepancy between the he10()
code and the mathematical model written by Ionides et al (2022) arises in whether individuals traveling from to
use mixing exponent
or
.
Ionides et al (2022) wrote
but the code used implemented
.
The implementation in
he10()
matches the implementation of Ionides et al (2022) and so uses .
It might seem surprising that immigrant infections affect only the first term in the expression for in Ionides et al (2022), and in the corresponding
he10()
code.
This immigration term is needed in the first term to make the model of He et al (2010) a proper sub-model, when coupling is removed by setting the gravitational constant parameter equal to zero.
When this constant is allowed to be positive, the role of immigrant infections transmitting to traveling individuals is anticipated to be a negligible, second-order effect which has been omitted from the model.
This function goes through a typical workflow of constructing
a typical spatPomp object (1-4 below). This allows the user to have a
file that replicates the exercise of model building as well as function
that creates a typical nonlinear model in epidemiology in case they want
to test a new inference methodology. We purposely do not modularize this
function because it is not an operational piece of the package and is
instead useful as an example.
1. Getting a measurements data.frame with columns for times,
spatial units and measurements.
2. Getting a covariates data.frame with columns for times,
spatial units and covariate data.
3. Constructing model components (latent state initializer,
latent state transition simulator and measurement model). Depending
on the methods used, the user may have to supply a vectorfield to
be integrated that represents the deterministic skeleton of the latent
process.
4. Bringing all the data and model components together to form a
spatPomp object via a call to spatPomp().
Edward L. Ionides
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
Ionides, E. L., Ning, N., and Wheeler, J. (2022). An iterated block particle filter for inference on coupled dynamic systems with shared and unit-specific parameters. Statistica Sinica, to appear. doi:10.48550/arXiv.2206.03837
Park, J. and Ionides, E. L. (2020) Inference on high-dimensional implicit dynamic models using a guided intermediate resampling filter. Statistics and Computing, doi:10.1007/s11222-020-09957-3
he10coordinates
, he10measles
, he10mle
, he10demography
Other spatPomp model generators:
bm()
,
bm2()
,
gbm()
,
lorenz()
,
measles()
# Complete examples are provided in the package tests ## Not run: m <- he10(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: m <- he10(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
Longitude and lattitude for the 20 towns in England and Wales studied by He et al (2010).
a ‘data.frame’ of longitude and lattitude for each town.
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Other datasets he10:
he10demography
,
he10measles
,
he10mle
Population and birth information for some towns in England and Wales during the measles pre-vaccine era.
Data are annual statistics for the 20 towns analyzed by He et al (2010).
a ‘data.frame’ of with variables town, year, pop and births.
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Other datasets he10:
he10coordinates
,
he10measles
,
he10mle
Measles case data from various cities and towns in England and Wales during the pre-vaccine era.
Data are weekly case counts for the 20 towns analyzed by He et al (2010).
a ‘data.frame’ of reported measles cases for 20 towns, analyzed by He et al (2010).
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Other datasets he10:
he10coordinates
,
he10demography
,
he10mle
Maximum likelihood estimate for fitting a susceptible-exposed-infected- recovered model to the measles case report data analyzed by He et al (2010). The values are similar, but not identical, to those reported by He et al.
a ‘data.frame’ containing the estimated parameters.
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Other datasets he10:
he10coordinates
,
he10demography
,
he10measles
An iterated block particle filter, for both shared and unit-specific parameters. We require that the spatPomp has been constructed to have a unit-specific parameter "thetau" for unit u corresponding to an estimated parameter "theta", whether theta is shared or unit-specific. This permits IBPF to implement a spatiotemporal random walk to estimate theta. We require that rw.sd is positive for, and only for, all parameters of the form "thetau" if "theta" is listed in sharedParNames or unitParNames.
## S4 method for signature 'missing' ibpf(data, ...) ## S4 method for signature 'ANY' ibpf(data, ...) ## S4 method for signature 'spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'ibpfd_spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'bpfilterd_spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) )
## S4 method for signature 'missing' ibpf(data, ...) ## S4 method for signature 'ANY' ibpf(data, ...) ## S4 method for signature 'spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'ibpfd_spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'bpfilterd_spatPomp' ibpf( data, Nbpf, Np, rw.sd, sharedParNames, unitParNames, cooling.type = "geometric", cooling.fraction.50, block_size, block_list, spat_regression, ..., verbose = getOption("spatPomp_verbose", FALSE) )
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, |
... |
If a |
Nbpf |
the number of iterations of perturbed BPF. |
Np |
The number of particles used within each replicate for the adapted simulations. |
rw.sd |
specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters.
Parameters that are to be estimated should have positive perturbations specified here.
The specification is given using the ifelse(time==time[1],s,0). Likewise, ifelse(time==time[lag],s,0). See below for some examples. The perturbations that are applied are normally distributed with the specified s.d. If parameter transformations have been supplied, then the perturbations are applied on the transformed (estimation) scale. |
sharedParNames |
estimated parameters that are equal for each unit. |
unitParNames |
estimated parameters that are different for each unit. |
cooling.type , cooling.fraction.50
|
specifications for the cooling schedule,
i.e., the manner and rate with which the intensity of the parameter perturbations is reduced with successive filtering iterations.
|
block_size |
The number of spatial units per block. If this is provided, the method subdivides units approximately evenly
into blocks with size |
block_list |
List that specifies an exact partition of the spatial units. Each partition element, or block, is an integer vector of neighboring units. |
spat_regression |
fraction of each extended parameter regressed toward the unit mean. Not required when all parameters are unit-specific. |
verbose |
logical; if |
Upon successful completion, ibpf
returns an object of class
‘ibpfd_spatPomp’.
The following methods are available for such an object:
coef
gives the Monte Carlo estimate of the maximum likelihood.
Edward L. Ionides
Ionides, E. L., Ning, N., and Wheeler, J. (2022). An iterated block particle filter for inference on coupled dynamic systems with shared and unit-specific parameters. Statistica Sinica, to appear. doi:10.48550/arXiv.2206.03837
likelihood evaluation algorithms: girf()
, enkf()
, bpfilter()
, abf()
, abfir()
Other likelihood maximization algorithms:
ienkf()
,
igirf()
,
iubf()
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion, for an extended model with # unit-specific parameters for all estimated, even if the parameter # takes the same shared value for each unit. U <- 4 b2 <- bm2(U=U,N=5,unit_specific_names="rho") # Run ibpf with two blocks of two units each. estimating rho as a # shared parameter with all other parameters being fixed. b2_ibpf <- ibpf(b2, sharedParNames="rho", unitParNames=NULL, Nbpf=5, spat_regression=0.1, Np=50, rw.sd=do.call(rw_sd,setNames(rep(list(0.01),times=U),paste0("rho",1:U))), cooling.fraction.50=0.5, block_size=2 ) # Get a likelihood estimate logLik(b2_ibpf) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Create a simulation of a Brownian motion, for an extended model with # unit-specific parameters for all estimated, even if the parameter # takes the same shared value for each unit. U <- 4 b2 <- bm2(U=U,N=5,unit_specific_names="rho") # Run ibpf with two blocks of two units each. estimating rho as a # shared parameter with all other parameters being fixed. b2_ibpf <- ibpf(b2, sharedParNames="rho", unitParNames=NULL, Nbpf=5, spat_regression=0.1, Np=50, rw.sd=do.call(rw_sd,setNames(rep(list(0.01),times=U),paste0("rho",1:U))), cooling.fraction.50=0.5, block_size=2 ) # Get a likelihood estimate logLik(b2_ibpf) ## End(Not run)
An implementation of a parameter estimation algorithm that uses the ensemble Kalman filter (Evensen, G. (1994)) to perform the filtering step in the parameter-perturbed iterated filtering scheme of Ionides et al. (2015) following the pseudocode in Asfaw, et al. (2020).
## S4 method for signature 'spatPomp' ienkf( data, Nenkf = 1, rw.sd, cooling.type = c("geometric", "hyperbolic"), cooling.fraction.50, Np, ..., verbose = getOption("spatPomp_verbose", FALSE) )
## S4 method for signature 'spatPomp' ienkf( data, Nenkf = 1, rw.sd, cooling.type = c("geometric", "hyperbolic"), cooling.fraction.50, Np, ..., verbose = getOption("spatPomp_verbose", FALSE) )
data |
an object of class |
Nenkf |
number of iterations of perturbed EnKF. |
rw.sd |
specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters.
Parameters that are to be estimated should have positive perturbations specified here.
The specification is given using the ifelse(time==time[1],s,0). Likewise, ifelse(time==time[lag],s,0). See below for some examples. The perturbations that are applied are normally distributed with the specified s.d. If parameter transformations have been supplied, then the perturbations are applied on the transformed (estimation) scale. |
cooling.type , cooling.fraction.50
|
specifications for the cooling schedule,
i.e., the manner and rate with which the intensity of the parameter perturbations is reduced with successive filtering iterations.
|
Np |
The number of particles used within each replicate for the adapted simulations. |
... |
Additional arguments can be used to replace model components. |
verbose |
logical; if |
Upon successful completion, ienkf
returns an object of class
‘ienkfd_spatPomp’. This object contains the convergence record of the iterative algorithm with
respect to the likelihood and the parameters of the model (which can be accessed using the traces
attribute) as well as a final parameter estimate, which can be accessed using the coef()
.
The following methods are available for such an object:
coef
gives the Monte Carlo estimate of the maximum likelihood.
Kidus Asfaw
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
Evensen, G. (1994) Sequential data assimilation with a nonlinear quasi-geostrophic model using Monte Carlo methods to forecast error statistics Journal of Geophysical Research: Oceans 99:10143–10162
Evensen, G. (2009) Data assimilation: the ensemble Kalman filter Springer-Verlag.
Anderson, J. L. (2001) An Ensemble Adjustment Kalman Filter for Data Assimilation Monthly Weather Review 129:2884–2903
likelihood evaluation algorithms: girf()
, enkf()
, bpfilter()
, abf()
, abfir()
Other likelihood maximization algorithms:
ibpf()
,
igirf()
,
iubf()
An implementation of a parameter estimation algorithm combining the intermediate resampling scheme of the guided intermediate resampling filter of Park and Ionides (2020) and the parameter perturbation scheme of Ionides et al. (2015) following the pseudocode in Asfaw, et al. (2020).
## S4 method for signature 'missing' igirf(data, ...) ## S4 method for signature 'ANY' igirf(data, ...) ## S4 method for signature 'spatPomp' igirf( data, Ngirf, Np, rw.sd, cooling.type, cooling.fraction.50, Ninter, lookahead = 1, Nguide, kind = c("bootstrap", "moment"), tol = 1e-100, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'igirfd_spatPomp' igirf( data, Ngirf, Np, rw.sd, cooling.type, cooling.fraction.50, Ninter, lookahead, Nguide, kind = c("bootstrap", "moment"), tol, ..., verbose = getOption("spatPomp_verbose", FALSE) )
## S4 method for signature 'missing' igirf(data, ...) ## S4 method for signature 'ANY' igirf(data, ...) ## S4 method for signature 'spatPomp' igirf( data, Ngirf, Np, rw.sd, cooling.type, cooling.fraction.50, Ninter, lookahead = 1, Nguide, kind = c("bootstrap", "moment"), tol = 1e-100, ..., verbose = getOption("spatPomp_verbose", FALSE) ) ## S4 method for signature 'igirfd_spatPomp' igirf( data, Ngirf, Np, rw.sd, cooling.type, cooling.fraction.50, Ninter, lookahead, Nguide, kind = c("bootstrap", "moment"), tol, ..., verbose = getOption("spatPomp_verbose", FALSE) )
data |
an object of class |
... |
Additional arguments can be used to replace model components. |
Ngirf |
the number of iterations of parameter-perturbed GIRF. |
Np |
The number of particles used within each replicate for the adapted simulations. |
rw.sd |
specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters.
Parameters that are to be estimated should have positive perturbations specified here.
The specification is given using the ifelse(time==time[1],s,0). Likewise, ifelse(time==time[lag],s,0). See below for some examples. The perturbations that are applied are normally distributed with the specified s.d. If parameter transformations have been supplied, then the perturbations are applied on the transformed (estimation) scale. |
cooling.type , cooling.fraction.50
|
specifications for the cooling schedule,
i.e., the manner and rate with which the intensity of the parameter perturbations is reduced with successive filtering iterations.
|
Ninter |
the number of intermediate resampling time points. By default, this is set equal to the number of units. |
lookahead |
The number of future observations included in the guide function. |
Nguide |
The number of simulations used to estimate state process uncertainty for each particle. |
kind |
One of two types of guide function construction. Defaults to |
tol |
If all of the guide function evaluations become too small (beyond floating-point precision limits), we set them to this value. |
verbose |
logical; if |
Upon successful completion, igirf()
returns an object of class
‘igirfd_spatPomp’. This object contains the convergence record of the iterative algorithm with
respect to the likelihood and the parameters of the model (which can be accessed using the traces
attribute) as well as a final parameter estimate, which can be accessed using the coef()
. The
algorithmic parameters used to run igirf()
are also included.
The following methods are available for such an object:
coef
gives the Monte Carlo maximum likelihood parameter estimate.
Kidus Asfaw
Park, J. and Ionides, E. L. (2020) Inference on high-dimensional implicit dynamic models using a guided intermediate resampling filter. Statistics and Computing, doi:10.1007/s11222-020-09957-3
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
likelihood evaluation algorithms: girf()
, enkf()
, bpfilter()
, abf()
, abfir()
Other likelihood maximization algorithms:
ibpf()
,
ienkf()
,
iubf()
# Complete examples are provided in the package tests ## Not run: igirf(bm(U=2,N=4),Ngirf=2, rw.sd = rw_sd(rho=0.02,X1_0=ivp(0.02)), cooling.type="geometric",cooling.fraction.50=0.5, Np=10,Ninter=2,lookahead=1,Nguide=5) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: igirf(bm(U=2,N=4),Ngirf=2, rw.sd = rw_sd(rho=0.02,X1_0=ivp(0.02)), cooling.type="geometric",cooling.fraction.50=0.5, Np=10,Ninter=2,lookahead=1,Nguide=5) ## End(Not run)
An algorithm for estimating the parameters of a spatiotemporal partially-observed Markov process.
Running iubf
causes the algorithm to perform a specified number of iterations of unadapted simulations with parameter perturbation and parameter resamplings.
At each iteration, unadapted simulations are performed on a perturbed version of the model, in which the parameters to be estimated are subjected to random perturbations at each observation.
After cycling through the data, each replicate's weight is calculated and is used to rank the bootstrap replictates. The highest ranking replicates are recycled into the next iteration.
This extra variability introduced through parameter perturbation effectively smooths the likelihood surface and combats particle depletion by introducing diversity into particle population.
As the iterations progress, the magnitude of the perturbations is diminished according to a user-specified cooling schedule.
## S4 method for signature 'spatPomp' iubf( object, Nubf = 1, Nrep_per_param, Nparam, nbhd, prop, rw.sd, cooling.type = c("geometric", "hyperbolic"), cooling.fraction.50, tol = (1e-18)^17, verbose = getOption("spatPomp_verbose"), ... )
## S4 method for signature 'spatPomp' iubf( object, Nubf = 1, Nrep_per_param, Nparam, nbhd, prop, rw.sd, cooling.type = c("geometric", "hyperbolic"), cooling.fraction.50, tol = (1e-18)^17, verbose = getOption("spatPomp_verbose"), ... )
object |
A |
Nubf |
The number of iterations to perform |
Nrep_per_param |
The number of replicates used to estimate the likelihood at a parameter |
Nparam |
The number of parameters that will undergo the iterated perturbation |
nbhd |
A neighborhood function with three arguments: |
prop |
A numeric between 0 and 1. The top |
rw.sd |
specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters.
Parameters that are to be estimated should have positive perturbations specified here.
The specification is given using the ifelse(time==time[1],s,0). Likewise, ifelse(time==time[lag],s,0). See below for some examples. The perturbations that are applied are normally distributed with the specified s.d. If parameter transformations have been supplied, then the perturbations are applied on the transformed (estimation) scale. |
cooling.type , cooling.fraction.50
|
specifications for the cooling schedule,
i.e., the manner and rate with which the intensity of the parameter perturbations is reduced with successive filtering iterations.
|
tol |
If the resampling weight for a particle is zero due to floating-point precision issues, it is set to the value of |
verbose |
logical; if |
... |
additional arguments are passed to |
Upon successful completion, iubf()
returns an object of class
‘iubfd_spatPomp’. This object contains the convergence record of the iterative algorithm with
respect to the likelihood and the parameters of the model (which can be accessed using the traces
attribute) as well as a final parameter estimate, which can be accessed using the coef()
. The
algorithmic parameters used to run iubf()
are also included.
The following methods are available for such an object:
coef
extracts the point estimate
Kidus Asfaw
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
likelihood evaluation algorithms: girf()
, enkf()
, bpfilter()
, abf()
, abfir()
Other likelihood maximization algorithms:
ibpf()
,
ienkf()
,
igirf()
Extracts the estimated log likelihood from a fitted model
## S4 method for signature 'girfd_spatPomp' logLik(object) ## S4 method for signature 'bpfilterd_spatPomp' logLik(object) ## S4 method for signature 'abfd_spatPomp' logLik(object) ## S4 method for signature 'iubfd_spatPomp' logLik(object) ## S4 method for signature 'abfird_spatPomp' logLik(object) ## S4 method for signature 'igirfd_spatPomp' logLik(object)
## S4 method for signature 'girfd_spatPomp' logLik(object) ## S4 method for signature 'bpfilterd_spatPomp' logLik(object) ## S4 method for signature 'abfd_spatPomp' logLik(object) ## S4 method for signature 'iubfd_spatPomp' logLik(object) ## S4 method for signature 'abfird_spatPomp' logLik(object) ## S4 method for signature 'igirfd_spatPomp' logLik(object)
object |
fitted model object |
a numeric which is the estimated log likelihood
Generate a spatPomp object representing a U
-dimensional stochastic Lorenz '96 process with
N
measurements made at times , simulated using an Euler method
with time increment
delta_t
.
lorenz( U = 5, N = 100, delta_t = 0.01, delta_obs = 0.5, regular_params = c(F = 8, sigma = 1, tau = 1) )
lorenz( U = 5, N = 100, delta_t = 0.01, delta_obs = 0.5, regular_params = c(F = 8, sigma = 1, tau = 1) )
U |
A length-one numeric signifying the number of spatial units for the process. |
N |
A length-one numeric signifying the number of observations. |
delta_t |
A length-one numeric giving the Euler time step for the numerical solution. |
delta_obs |
A length-one numeric giving the time between observations. |
regular_params |
A named numeric vector containing the values of the |
An object of class ‘spatPomp’ representing a simulation from a U
-dimensional
Lorenz 96 model
Edward L. Ionides
Lorenz, E. N. (1996) Predictability: A problem partly solved. Proceedings of the seminar on predictability
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
Other spatPomp model generators:
bm()
,
bm2()
,
gbm()
,
he10()
,
measles()
# Complete examples are provided in the package tests ## Not run: l <- lorenz(U=5, N=100, delta_t=0.01, delta_obs=1) # See all the model specifications of the object spy(l) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: l <- lorenz(U=5, N=100, delta_t=0.01, delta_obs=1) # See all the model specifications of the object spy(l) ## End(Not run)
Generate a spatPomp object for measles in the top-U
most populous cities in England and Wales.
The model is adapted from He et al. (2010) with gravity transport following Park and Ionides (2020).
The data are from Dalziel et al (2016).
measles( U = 6, dt = 2/365, fixed_ivps = TRUE, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05 )
measles( U = 6, dt = 2/365, fixed_ivps = TRUE, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05 )
U |
A length-one numeric signifying the number of cities to be represented in the spatPomp object. |
dt |
a numeric (in unit of years) that is used as the Euler time-increment for simulating measles data. |
fixed_ivps |
a logical. If |
S_0 |
a numeric. If |
E_0 |
a numeric. If |
I_0 |
a numeric. If |
An object of class ‘spatPomp’ representing a U
-dimensional spatially coupled measles POMP model.
This model was used to generate the results of Ionides et al (2021). However, their equation (6) is not exactly correct for the Binomial Gamma infinitesimal model used in the code, as shown by Proposition 5 of Breto and Ionides, 2011. If Poisson Gamma infinitesimal increments were used (Proposition 4 of Breto and Ionides, 2011) then (6) would be correct, but the resulting unbounded increments could break the non-negativity requirement for compartment membership. The same issue arises with the description in Park and Ionides (2020), though that analysis was based on a different model implementation since the spatPomp package was not yet available.
A difference between (6) of Ionides et al (2021) and (2.1) of He et al (2010) is that in (6) the mixing exponent is applied to
rather than just to
.
In the context of He et al (2010) this changes the parameterization but has negligible effect on the model itself since
is approximately constant and so changing its power can be compensated by a corresponding change in the transmission rate,
.
In practice, models fitted to data have
close to
, so this issue may be moot and this modeling mechanism may not be an effective empirical way to carry out the goal of making allowance for heterogeneous mixing.
The code here includes a cohort effect, , following He et al (2010), that was not included by Ionides et al (2021).
This effect leads to a non-differentiability of expected increments which is problematic for the spatPomp implementation of GIRF.
For the results of Ionides et al (2021), this was set to
.
The analysis of He et al (2010), and the model generated by he10()
, use weekly aggregated cases.
Weekly reports were not available beyond the 20 cites studied by He et al (2010) so measles()
relies on the biweekly reports used by Ionides et al (2021) and Ionides & Park (2020).
It turns out to be an important detail of the model by He et al (2010) that a delay is included between birth and entry into the susceptible compartment.
He et al (2010) found a 4 year delay fits the data.
This value is fixed to be the variable birth_delay
in the code for measles()
.
The code for Ionides et al (2021) uses a 3 year delay, and the delay is not explained in the abbreviated model description.
In measles()
we have reverted to the 4 year delay identified by He et al (2010).
This function goes through a typical workflow of constructing
a typical spatPomp object (1-4 below). This allows the user to have a
file that replicates the exercise of model building as well as function
that creates a typical nonlinear model in epidemiology in case they want
to test a new inference methodology. We purposely do not modularize this
function because it is not an operational piece of the package and is
instead useful as an example.
1. Getting a measurements data.frame with columns for times,
spatial units and measurements.
2. Getting a covariates data.frame with columns for times,
spatial units and covariate data.
3. Constructing model components (latent state initializer,
latent state transition simulator and measurement model). Depending
on the methods used, the user may have to supply a vectorfield to
be integrated that represents the deterministic skeleton of the latent
process.
4. Bringing all the data and model components together to form a
spatPomp object via a call to spatPomp().
Edward L. Ionides
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
Dalziel, Benjamin D. et al. (2016) Persistent chaos of measles epidemics in the prevaccination United States caused by a small change in seasonal transmission patterns. PLoS Computational Biology, 12(2), e1004655. doi:10.5061/dryad.r4q34
Park, J. and Ionides, E. L. (2020) Inference on high-dimensional implicit dynamic models using a guided intermediate resampling filter. Statistics and Computing, doi:10.1007/s11222-020-09957-3
Breto, C. and Ionides, E.L. (2011) Compound Markov counting processes and their applications to modeling infinitesimally over-dispersed systems. Stochastic Processes and their Applications 121, 2571-2591. doi:10.1016/j.spa.2011.07.005
measles_UK
, city_data_UK
Other spatPomp model generators:
bm()
,
bm2()
,
gbm()
,
he10()
,
lorenz()
# Complete examples are provided in the package tests ## Not run: m <- measles(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: m <- measles(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
Generate a spatPomp object for measles in the top-U
most populous cities in England and Wales.
The model is adapted from He et al. (2010) with gravity transport following Park and Ionides (2019).
The structure of this spatPomp is designed to accommodate shared and unit-specific parameters.
If carrying out spatiotemporal iterated filtering for shared parameters via ibpf, it is necessary to
have a unit-specific expansion and so these parameters should be included in expandedParNames.
This model and data correspond to the biweekly analysis of Park and Ionides (2020) and
Ionides et al (2021). There are small differences with the weekly model and data of
He et al (2010) and Ionides, Ning and Wheeler (2022).
measles2( U = 6, dt = 2/365, N = 391, expandedParNames = c("R0", "c", "A", "muIR", "muEI", "sigmaSE", "rho", "psi", "g", "S_0", "E_0", "I_0"), contractedParNames = NULL, simulated = FALSE, basic_params = c(alpha = 0.98, iota = 0.1, R0 = 30, c = 0.3, A = 0.5, muIR = 52, muEI = 52, muD = 0.02, sigmaSE = 0.15, rho = 0.5, psi = 0.15, g = 400, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05) )
measles2( U = 6, dt = 2/365, N = 391, expandedParNames = c("R0", "c", "A", "muIR", "muEI", "sigmaSE", "rho", "psi", "g", "S_0", "E_0", "I_0"), contractedParNames = NULL, simulated = FALSE, basic_params = c(alpha = 0.98, iota = 0.1, R0 = 30, c = 0.3, A = 0.5, muIR = 52, muEI = 52, muD = 0.02, sigmaSE = 0.15, rho = 0.5, psi = 0.15, g = 400, S_0 = 0.032, E_0 = 5e-05, I_0 = 4e-05) )
U |
An integer from 1 to 40 specifying the number of cities to be represented in the spatPomp object. |
dt |
a numeric (in unit of years) that is used as the Euler time-increment for simulating measles data |
N |
An integer from 1 to 391 specifying the number of time points. |
expandedParNames |
specifies parameters that are defined for each unit. This also allows unit perturbations for a parameter with a value shared across units. |
contractedParNames |
specifies parameters having a shared value across units. Remaining parameters that are neither expanded nor contracted are considered fixed, and will not have a transformation defined for them. |
simulated |
determines whether to return a simulation from the model or the UK measles data |
basic_params |
A named vector used to specify shared parameters or unit-specific parameters having common values for each unit. |
An object of class ‘spatPomp’ representing a U
-dimensional spatially coupled measles POMP model.
He, D., Ionides, E. L., and King, A. A. (2010). Plug-and-play inference for disease dynamics: measles in large and small populations as a case study. Journal of the Royal Society Interface, 7(43), 271-283. doi:10.1098/rsif.2009.0151
Park, J. and Ionides, E. L. (2020) Inference on high-dimensional implicit dynamic models using a guided intermediate resampling filter. Statistics and Computing, doi:10.1007/s11222-020-09957-3
Ionides, E. L., Asfaw, K., Park, J., and King, A. A. (2021). Bagged filters for partially observed interacting systems. Journal of the American Statistical Association, doi:10.1080/01621459.2021.1974867
Ionides, E. L., Ning, N., and Wheeler, J. (2022). An iterated block particle filter for inference on coupled dynamic systems with shared and unit-specific parameters. Statistica Sinica, to appear. doi:10.48550/arXiv.2206.03837
# Complete examples are provided in the package tests ## Not run: m <- measles2(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: m <- measles2(U = 5) # See all the model specifications of the object spy(m) ## End(Not run)
Measles case data from various cities and towns in England and Wales during the pre-vaccine era.
Data includes bi-weekly case counts as well as births and population from 40 cities and towns.
a ‘data.frame’ of the 40 largest cities and towns in the UK and Wales, their latitude, longitude and bi-weekly measles case counts, population and birthrates.
Dalziel, Benjamin D. et al. (2016) Persistent chaos of measles epidemics in the prevaccination United States caused by a small change in seasonal transmission patterns. PLoS Computational Biology, 12(2), e1004655. doi:10.5061/dryad.r4q34
Other datasets:
city_data_UK
munit_measure
returns a moment-matched parameter set given an empirically calculated measurement variance and latent states.
This is used in girf()
and igirf()
when they are run with kind='moment'
.
## S4 method for signature 'spatPomp' munit_measure(object, x, vc, unit, time, params, Np = 1)
## S4 method for signature 'spatPomp' munit_measure(object, x, vc, unit, time, params, Np = 1)
object |
An object of class |
x |
A state vector for all units |
vc |
The empirically calculated variance used to perform moment-matching |
unit |
The unit for which to obtain a moment-matched parameter set |
time |
The time for which to obtain a moment-matched parameter set |
params |
parameters to use to obtain a moment-matched parameter set |
Np |
Number of particle replicates for which to get parameter sets |
An array with dimensions dim(array.params)[1]
by dim(x)[2]
by length(unit)
bylength(time)
representing the moment-matched parameter set(s) corresponding to the variance of the measurements, vc
, and the states, x
.
Kidus Asfaw
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] array.params <- array(p, dim = c(length(p), length(unit_names(b)), 1, 1), dimnames = list(params = rownames(p))) vc <- c(4, 9, 16); dim(vc) <- c(length(vc), 1, 1) munit_measure(b, x=s, vc=vc, Np=1, unit = 1, time=1, params=array.params) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] array.params <- array(p, dim = c(length(p), length(unit_names(b)), 1, 1), dimnames = list(params = rownames(p))) vc <- c(4, 9, 16); dim(vc) <- c(length(vc), 1, 1) munit_measure(b, x=s, vc=vc, Np=1, unit = 1, time=1, params=array.params) ## End(Not run)
spatPomp
objectsVisualize data in a spatPomp
object or a derived class.
This gives a quick view; the data can be extracted from
the object to make a customized plot.
## S4 method for signature 'spatPomp' plot(x, type = c("l", "h"), log = FALSE, plot_unit_names = TRUE, ...) ## S4 method for signature 'igirfd_spatPomp' plot(x, params = names(coef(x)), ncol = 3)
## S4 method for signature 'spatPomp' plot(x, type = c("l", "h"), log = FALSE, plot_unit_names = TRUE, ...) ## S4 method for signature 'igirfd_spatPomp' plot(x, params = names(coef(x)), ncol = 3)
x |
a |
type |
for visualizing an object of class |
log |
should the data be transformed to |
plot_unit_names |
allows suppression of unit names when making a heat map for a large number of units |
... |
for visualizing an object of class |
params |
allows selection of a subset of parameters when making a diagnostic plot for a model with many parameters |
ncol |
the number of columns in the grid plot |
a ggplot
plot of class ‘gg’ and ‘ggplot’.
Prints its argument.
## S4 method for signature 'spatPomp' print(x)
## S4 method for signature 'spatPomp' print(x)
x |
a |
An object of class ‘spatPomp’ is returned *invisibly*. The user is notified on the console only the class of the object.
Use spy()
to see model components of x
instead.
runit_measure
simulates a unit's observation given the entire state
## S4 method for signature 'spatPomp' runit_measure(object, x, unit, time, params, log = FALSE)
## S4 method for signature 'spatPomp' runit_measure(object, x, unit, time, params, log = FALSE)
object |
An object of class |
x |
A state vector for all units |
unit |
The unit for which to simulate an observation |
time |
The time for which to simulate an observation |
params |
parameters to use to simulate an observation |
log |
logical; should the density be returned on log scale? |
A matrix with the simulated observation corresponding to state
x
and unit unit
with parameter set params
.
Kidus Asfaw
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] runit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] runit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)
simulate
generates simulations of the latent and measurement
processes.
## S4 method for signature 'spatPomp' simulate( object, nsim = 1, seed = NULL, format = c("spatPomps", "data.frame"), include.data = FALSE, ... )
## S4 method for signature 'spatPomp' simulate( object, nsim = 1, seed = NULL, format = c("spatPomps", "data.frame"), include.data = FALSE, ... )
object |
optional; if present, it should be a data frame or a ‘pomp’ object. |
nsim |
number of simulations. |
seed |
optional integer;
if set, the pseudorandom number generator (RNG) will be initialized with |
format |
the format of the simulated results. If the argument is
set to |
include.data |
if |
... |
additional arguments are passed to |
if format='spatPomps'
and nsim=1
an object of class ‘spatPomp’ representing a simulation from the model in object
is returned.
If format='spatPomps'
and nsim>1
a list of class ‘spatPomp’ objects is returned.
If format='data.frame'
then a class ‘data.frame’ object is returned.
Kidus Asfaw
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
# Complete examples are provided in the package tests ## Not run: # Get a spatPomp object b <- bm(U=2, N=5) # Get 2 simulations from same model as data.frame sims <- simulate(b, nsim=2, format='data.frame') ## End(Not run)
# Complete examples are provided in the package tests ## Not run: # Get a spatPomp object b <- bm(U=2, N=5) # Get 2 simulations from same model as data.frame sims <- simulate(b, nsim=2, format='data.frame') ## End(Not run)
This function constructs a class ‘spatPomp’ object, encoding a spatiotemporal partially observed Markov process (SpatPOMP) model together with a uni- or multi-variate time series on a collection of units.
Users will typically develop a POMP model for a single unit before embarking on a coupled SpatPOMP analysis.
Consequently, we assume some familiarity with pomp and its description by King, Nguyen and Ionides (2016).
The spatPomp
class inherits from pomp
with the additional unit structure being a defining feature of the resulting models and inference algorithms.
spatPomp( data, units, times, covar, t0, ..., eunit_measure, munit_measure, vunit_measure, dunit_measure, runit_measure, rprocess, rmeasure, dprocess, dmeasure, skeleton, rinit, rprior, dprior, unit_statenames, unit_accumvars, shared_covarnames, globals, paramnames, params, cdir, cfile, shlib.args, PACKAGE, partrans, compile = TRUE, verbose = getOption("spatPomp_verbose", FALSE) )
spatPomp( data, units, times, covar, t0, ..., eunit_measure, munit_measure, vunit_measure, dunit_measure, runit_measure, rprocess, rmeasure, dprocess, dmeasure, skeleton, rinit, rprior, dprior, unit_statenames, unit_accumvars, shared_covarnames, globals, paramnames, params, cdir, cfile, shlib.args, PACKAGE, partrans, compile = TRUE, verbose = getOption("spatPomp_verbose", FALSE) )
data |
either a dataframe holding the spatiotemporal data,
or an object of class ‘spatPomp’, i.e., the output of another spatPomp calculation.
If dataframe, the user must provide the name of the times column using the |
units |
when |
times |
the sequence of observation times.
|
covar |
An optional dataframe for supplying covariate information. If provided, there must be two
columns that provide the observation time and the observation spatial unit with the same names and arrangement as the |
t0 |
The zero-time, i.e., the time of the initial state.
This must be no later than the time of the first observation, i.e., |
... |
If there are arguments that the user would like to pass to pomp's basic constructor function's ... argument, this argument passes them along. Not recommended for this version of spatPomp. |
eunit_measure |
Evaluator of the expected measurement given the latent states and model parameters. The |
munit_measure |
Evaluator of a moment-matched parameter set (like the standard deviation parameter of a normal distribution or the size parameter of a negative binomial distribution) given an empirical variance estimate, the latent states and all model parameters.
Only Csnippets are accepted. The Csnippet should assign the scalar approximation to the measurement variance parameter to the pre-defined variable corresponding to that parameter, which has been predefined with a |
vunit_measure |
Evaluator of the theoretical measurement variance given the latent states and model parameters. The |
dunit_measure |
Evaluator of the unit measurement model density given the measurement, the latent states and model parameters. The |
runit_measure |
Simulator of the unit measurement model given the latent states and the model parameters.
The |
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 R function, or the name of a pre-compiled native routine available in a dynamically loaded library.
Setting |
dprocess |
evaluator of the probability density of transitions of the unobserved state process.
Setting |
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 |
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 |
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 |
rprior |
optional; prior distribution sampler, specified either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library.
For more information, see prior specification.
Setting |
dprior |
optional; prior distribution density evaluator, specified either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library.
For more information, see prior specification.
Setting |
unit_statenames |
The names of the components of the latent state. E.g. if the user is constructing an joint SIR model
over many spatial units, |
unit_accumvars |
a subset of the |
shared_covarnames |
If |
globals |
optional character or C snippet;
arbitrary C code that will be hard-coded into the shared-object library created when C snippets are provided.
If no C snippets are used, |
paramnames |
optional character vector;
names of model parameters.
It is typically only necessary to supply |
params |
optional; named numeric vector of parameters.
This will be coerced internally to storage mode |
cdir |
optional character variable.
|
cfile |
optional character variable.
|
shlib.args |
optional character variables.
Command-line arguments to the |
PACKAGE |
optional character;
the name (without extension) of the external, dynamically loaded library in which any native routines are to be found.
This is only useful if one or more of the model components has been specified using a precompiled dynamically loaded library;
it is not used for any component specified using C snippets.
|
partrans |
optional parameter transformations, constructed using 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 |
compile |
logical;
if |
verbose |
logical; if |
One implements a SpatPOMP model by specifying some or all of its basic components, including:
the simulator from the distribution of the latent state process at the zero-time;
the transition simulator of the latent state process;
the evaluator of the conditional density at a unit's measurement given the unit's latent state;
the evaluator of the expectation of a unit's measurement given the unit's latent state;
the evaluator of the moment-matched parameter set given a unit's latent state and some empirical measurement variance;
the evaluator of the variance of a unit's measurement given the unit's latent state;
the simulator of a unit's measurement conditional on the unit's latent state;
the evaluator of the density for transitions of the latent state process;
the simulator of the measurements conditional on the latent state;
the evaluator of the conditional density of the measurements given the latent state;
the simulator from a prior distribution on the parameters;
the evaluator of the prior density;
which computes the deterministic skeleton of the unobserved state process;
which performs parameter transformations.
The basic structure and its rationale are described in Asfaw et al. (2020).
Each basic component is supplied via an argument of the same name to spatPomp()
.
The five unit-level model components must be provided via C snippets. The remaining components, whose behaviors are inherited from
pomp may be furnished using C snippets, R functions, or pre-compiled native routine available in user-provided dynamically loaded libraries.
An object of class ‘spatPomp’ representing observations and model components from the spatiotemporal POMP model.
Kidus Asfaw, Edward L. Ionides, Aaron A. King
Asfaw, K., Park, J., Ho, A., King, A. A., and Ionides, E. L. (2020) Partially observed Markov processes with spatial structure via the R package spatPomp. ArXiv: 2101.01157. doi:10.48550/arXiv.2101.01157
King, A. A., Nguyen, D. and Ionides, E. L. (2016) Statistical Inference for Partially Observed Markov Processes via the R Package pomp. Journal of Statistical Software, 69(12), 1–43. doi:10.18637/jss.v069.i12
spatPomp_Csnippet()
is used to provide snippets of C
code that specify model components. It functions similarly to Csnippet()
from
the pomp package; in fact, the output of spatPomp_Csnippet
is an object
of class Csnippet
. It additionally provides some arguments that allow the user
to stay focused on model development in the spatiotemporal context where
model size grows.
## S4 method for signature 'character' spatPomp_Csnippet( code, method = "", unit_statenames, unit_obsnames, unit_covarnames, unit_ivpnames, unit_paramnames, unit_vfnames )
## S4 method for signature 'character' spatPomp_Csnippet( code, method = "", unit_statenames, unit_obsnames, unit_covarnames, unit_ivpnames, unit_paramnames, unit_vfnames )
code |
encodes a component of a spatiotemporal POMP model using C code |
method |
a character string matching the name of the |
unit_statenames |
a subset of the |
unit_obsnames |
a subset of the |
unit_covarnames |
if the model has covariate information for each unit, the names of the covariates for each unit can be supplied to this argument. This allows the user to get variables that can be indexed conveniently to use incorporate the covariate information in a loop. See examples for more details. |
unit_ivpnames |
This argument is particularly useful when specifying the
|
unit_paramnames |
This argument is particularly useful when there are non-initial value parameters that are unit-specific. |
unit_vfnames |
This argument is particularly useful when specifying the
|
An object of class ‘Csnippet’ which represents a model specification in C code.
Kidus Asfaw
# Set initial states for Brownian motion bm_rinit <- spatPomp_Csnippet( method = "rinit", unit_statenames = c("X"), unit_ivpnames = c("X"), code = " for (int u = 0; u < U; u++) { X[u]=X_0[u]; } " ) # Skeleton for Brownian motion bm_skel <- spatPomp_Csnippet( method = "skeleton", unit_statenames = c("X"), unit_vfnames = c("X"), code = " for (int u = 0 ; u < U ; u++) { DX[u] = 0; } " )
# Set initial states for Brownian motion bm_rinit <- spatPomp_Csnippet( method = "rinit", unit_statenames = c("X"), unit_ivpnames = c("X"), code = " for (int u = 0; u < U; u++) { X[u]=X_0[u]; } " ) # Skeleton for Brownian motion bm_skel <- spatPomp_Csnippet( method = "skeleton", unit_statenames = c("X"), unit_vfnames = c("X"), code = " for (int u = 0 ; u < U ; u++) { DX[u] = 0; } " )
An S4 class to represent a spatiotemporal POMP model and data.
unit_names
A vector containing the spatial units of a spatiotemporal POMP.
unit_statenames
A vector containing the state names such that appending the unit indices to the unit statenames will result in the each unit's corresponding states.
unit_obsnames
A vector of observation types for a spatial unit.
eunit_measure
A pomp_fun representing the expected measurement for each spatial unit given its states.
dunit_measure
A pomp_fun representing the unit measurement density for each spatial unit.
runit_measure
A pomp_fun representing the unit observation simulator.
unit_names
outputs the contents of the unit_names
slot
of a spatPomp
object. The order in which the units
appear in the output vector determines the order in which latent
states and observations for the spatial units are stored.
## S4 method for signature 'spatPomp' unit_names(x)
## S4 method for signature 'spatPomp' unit_names(x)
x |
a |
A character vector with the unit names used to create the ‘spatPomp’ object.
Evaluate the unit measurement model density function for each unit. This method is used primarily as part of likelihood evaluation and parameter inference algorithms.
## S4 method for signature 'spatPomp' vec_dmeasure(object, y, x, units, times, params, log = FALSE, ...)
## S4 method for signature 'spatPomp' vec_dmeasure(object, y, x, units, times, params, log = FALSE, ...)
object |
a |
y |
numeric; measurements whose densities given the latent states are evaluated |
x |
numeric; state at which conditional measurement densities are evaluated |
units |
numeric; units at which measurement densities are evaluated |
times |
numeric; time at which measurement densities are evaluated |
params |
numeric; parameter set at which measurement densities is evaluated |
log |
logical; should the outputted measurement densities be on log scale? |
... |
additional parameters will be ignored |
An array of dimension length(unit_names(object))
by dim(x)[2]
by dim(x)[3]
representing each unit's measurement density assessed for each replicate in x
for each observation time.
Kidus Asfaw
runit_measure
Simulate from the unit measurement model density function for each unit
## S4 method for signature 'spatPomp' vec_rmeasure(object, x, times, params, ...)
## S4 method for signature 'spatPomp' vec_rmeasure(object, x, times, params, ...)
object |
a |
x |
numeric; state at which measurements are simulated |
times |
numeric; time at which measurements are simulated |
params |
numeric; parameter set at which measurements are simulated |
... |
additional parameters will be ignored |
An array of dimension length(unit_names(object))
by dim(x)[2]
by dim(x)[3]
representing each unit's simulated measurement assessed for each replicate in x
for each observation time.
Kidus Asfaw
vunit_measure
evaluates the variance of a unit's observation given the entire state
## S4 method for signature 'spatPomp' vunit_measure(object, x, unit, time, params, Np = 1)
## S4 method for signature 'spatPomp' vunit_measure(object, x, unit, time, params, Np = 1)
object |
An object of class |
x |
A state vector for all units |
unit |
The unit for which to evaluate the variance |
time |
The time for which to evaluate the variance |
params |
parameters at which to evaluate the unit variance |
Np |
numeric; defaults to 1 and the user need not change this |
A matrix with the unit measurement variance implied by the state, x
,
and the parameter set params
for unit unit
.
Kidus Asfaw
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] vunit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)
# Complete examples are provided in the package tests ## Not run: b <- bm(U=3) s <- states(b)[,1,drop=FALSE] rownames(s) -> rn dim(s) <- c(3,1,1) dimnames(s) <- list(variable=rn, rep=NULL) p <- coef(b); names(p) -> rnp dim(p) <- c(length(p),1); dimnames(p) <- list(param=rnp) o <- obs(b)[,1,drop=FALSE] vunit_measure(b, x=s, unit=2, time=1, params=p) ## End(Not run)