Skip to content

Commit ced7561

Browse files
committed
change userdata interface
1 parent f2928af commit ced7561

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+277
-295
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: pomp
22
Type: Package
33
Title: Statistical Inference for Partially Observed Markov Processes
4-
Version: 5.8.3.0
5-
Date: 2024-05-22
4+
Version: 5.8.4.0
5+
Date: 2024-05-24
66
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
77
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
88
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),

R/abc.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
##' @family MCMC methods
1515
##' @family Bayesian methods
1616
##' @concept approximate Bayesian computation
17-
##'
18-
##' @inheritParams pomp
1917
##' @inheritParams probe
2018
##' @inheritParams pmcmc
19+
##' @inheritParams pomp
2120
##' @param Nabc the number of ABC iterations to perform.
2221
##' @param scale named numeric vector of scales.
2322
##' @param epsilon ABC tolerance.

R/blowflies.R

+11-7
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ blowflies1 <- function (
117117
),
118118
paramnames=c("P","N0","delta","sigma.P","sigma.d","sigma.y"),
119119
statenames=c("N1","R","S","e","eps"),
120-
y.init=with( ## initial data
121-
dat,
122-
approx(x=day,y=y,xout=seq(from=0,to=14,by=1),rule=2)$y
120+
userdata=list(
121+
y.init=with( ## initial data
122+
dat,
123+
approx(x=day,y=y,xout=seq(from=0,to=14,by=1),rule=2)$y
124+
)
123125
),
124126
## y.init=c(948, 948, 942, 930, 911, 885, 858, 833.7, 801, 748.3, 676, 589.8, 504, 434.9, 397),
125127
rinit=function (params, t0, y.init, ...) {
@@ -173,11 +175,13 @@ blowflies2 <- function (
173175
partrans=parameter_trans(
174176
log=c("P","delta","N0","sigma.P","sigma.d","sigma.y")
175177
),
176-
y.init=with( ## initial data
177-
dat,
178-
approx(x=day,y=y,xout=seq(from=0,to=14,by=2),rule=2)$y
178+
userdata=list(
179+
y.init=with( ## initial data
180+
dat,
181+
approx(x=day,y=y,xout=seq(from=0,to=14,by=2),rule=2)$y
182+
)
183+
## y.init=c(948, 942, 911, 858, 801, 676, 504, 397),
179184
),
180-
## y.init=c(948, 942, 911, 858, 801, 676, 504, 397),
181185
paramnames=c("P","N0","delta","sigma.P","sigma.d","sigma.y"),
182186
statenames=c("N1","R","S","e","eps"),
183187
rinit=function (params, t0, y.init, ...) {

R/bsmc2.R

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,23 @@
1818
##' @family full-information methods
1919
##' @family particle filter methods
2020
##' @family estimation methods
21-
##'
2221
##' @importFrom mvtnorm rmvnorm
2322
##' @importFrom stats median cov
24-
##'
25-
##' @inheritParams pomp
2623
##' @inheritParams pfilter
27-
##'
24+
##' @inheritParams pomp
2825
##' @param smooth Kernel density smoothing parameter.
2926
##' The compensating shrinkage factor will be \code{sqrt(1-smooth^2)}.
3027
##' Thus, \code{smooth=0} means that no noise will be added to parameters.
3128
##' The general recommendation is that the value of \code{smooth} should be chosen close to 0 (e.g., \code{shrink} ~ 0.1).
32-
##'
3329
##' @return
3430
##' An object of class \sQuote{bsmcd_pomp}.
3531
##' The following methods are avaiable:
3632
##' \describe{
3733
##' \item{\code{\link[=plot,bsmcd_pomp-method]{plot}}}{produces diagnostic plots}
3834
##' \item{\code{\link{as.data.frame}}}{puts the prior and posterior samples into a data frame}
3935
##' }
40-
##'
4136
##' @inheritSection pomp Note for Windows users
42-
##'
4337
##' @author Michael Lavine, Matthew Ferrari, Aaron A. King, Edward L. Ionides
44-
##'
4538
##' @references
4639
##'
4740
##' \Liu2001b

R/kalman.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
##' @family particle filter methods
1515
##' @family elementary algorithms
1616
##' @inheritSection pomp Note for Windows users
17-
##'
17+
##' @inheritParams pfilter
1818
##' @inheritParams pomp
1919
##' @param Np integer; the number of particles to use, i.e., the size of the ensemble.
2020
##'
2121
##' @return
2222
##' An object of class \sQuote{kalmand_pomp}.
23-
##'
2423
##' @references
2524
##'
2625
##' \Evensen1994

R/mif2.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
##' This extra variability effectively smooths the likelihood surface and combats particle depletion by introducing diversity into particle population.
77
##' As the iterations progress, the magnitude of the perturbations is diminished according to a user-specified cooling schedule.
88
##' The algorithm is presented and justified in Ionides et al. (2015).
9-
##'
109
##' @name mif2
1110
##' @rdname mif2
1211
##' @include pfilter.R workhorses.R pomp_class.R safecall.R continue.R
@@ -17,8 +16,8 @@
1716
##' @family estimation methods
1817
##' @family methods based on maximization
1918
##' @importFrom utils head
20-
##' @inheritParams pomp
2119
##' @inheritParams pfilter
20+
##' @inheritParams pomp
2221
##' @param Nmif The number of filtering iterations to perform.
2322
##' @param rw.sd specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters.
2423
##' Parameters that are to be estimated should have positive perturbations specified here.

R/pfilter.R

+1-10
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,21 @@
2222
##' \code{Np(1)}, from \code{timezero(object)} to \code{time(object)[1]},
2323
##' and so on,
2424
##' while when \code{T=length(time(object))}, \code{Np(T)} is the number of particles to sample at the end of the time-series.
25-
##'
2625
##' @param pred.mean logical; if \code{TRUE}, the prediction means are calculated for the state variables and parameters.
27-
##'
2826
##' @param pred.var logical; if \code{TRUE}, the prediction variances are calculated for the state variables and parameters.
29-
##'
3027
##' @param filter.mean logical; if \code{TRUE}, the filtering means are calculated for the state variables and parameters.
31-
##'
3228
##' @param filter.traj logical; if \code{TRUE}, a filtered trajectory is returned for the state variables and parameters.
3329
##' See \code{\link{filter_traj}} for more information.
34-
##'
3530
##' @param save.states character;
3631
##' If \code{save.states="unweighted"}, the state-vector for each unweighted particle at each time is saved.
3732
##' If \code{save.states="weighted"}, the state-vector for each weighted particle at each time is saved, along with the corresponding weight.
3833
##' If \code{save.states="no"}, information on the latent states is not saved.
3934
##' \code{"FALSE"} is a synonym for \code{"no"} and \code{"TRUE"} is a synonym for \code{"unweighted"}.
4035
##' To retrieve the saved states, applying \code{\link{saved_states}} to the result of the \code{pfilter} computation.
41-
##'
36+
##' @param ... additional arguments are passed to \code{\link{pomp}}.
4237
##' @return
4338
##' An object of class \sQuote{pfilterd_pomp}, which extends class \sQuote{pomp}.
4439
##' Information can be extracted from this object using the methods documented below.
45-
##'
4640
##' @section Methods:
4741
##' \describe{
4842
##' \item{\code{\link{logLik}}}{ the estimated log likelihood }
@@ -59,15 +53,12 @@
5953
##' \item{\code{\link{as.data.frame}}}{coerce to a data frame}
6054
##' \item{\code{\link{plot}}}{diagnostic plots}
6155
##' }
62-
##'
6356
##' @references
6457
##'
6558
##' \Arulampalam2002
6659
##'
6760
##' \Bhadra2016
68-
##'
6961
##' @example examples/pfilter.R
70-
##'
7162
NULL
7263

7364
setClass(

R/pmcmc.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
##' @family Bayesian methods
1818
##'
1919
##' @importFrom stats runif
20-
##' @inheritParams pomp
2120
##' @inheritParams pfilter
21+
##' @inheritParams pomp
2222
##' @param Nmcmc The number of PMCMC iterations to perform.
2323
##' @param proposal optional function that draws from the proposal
2424
##' distribution. Currently, the proposal distribution must be symmetric for

R/pomp.R

+48-29
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
##' One implements the \acronym{POMP} model by specifying some or all of its \emph{basic components}.
66
##' These comprise:
77
##' \describe{
8-
##' \item{rinit,}{which samples from the distribution of the state process at the zero-time;}
9-
##' \item{dinit,}{which evaluates the density of the state process at the zero-time;}
10-
##' \item{rprocess,}{the simulator of the unobserved Markov state process;}
11-
##' \item{dprocess,}{the evaluator of the probability density function for transitions of the unobserved Markov state process;}
12-
##' \item{rmeasure,}{the simulator of the observed process, conditional on the unobserved state;}
13-
##' \item{dmeasure,}{the evaluator of the measurement model probability density function;}
14-
##' \item{emeasure,}{the expectation of the measurements, conditional on the latent state;}
15-
##' \item{vmeasure,}{the covariance matrix of the measurements, conditional on the latent state;}
16-
##' \item{rprior,}{which samples from a prior probability distribution on the parameters;}
17-
##' \item{dprior,}{which evaluates the prior probability density function;}
18-
##' \item{skeleton,}{which computes the deterministic skeleton of the unobserved state process;}
19-
##' \item{partrans,}{which performs parameter transformations.}
8+
##' \item{rinit}{which samples from the distribution of the state process at the zero-time;}
9+
##' \item{dinit}{which evaluates the density of the state process at the zero-time;}
10+
##' \item{rprocess}{the simulator of the unobserved Markov state process;}
11+
##' \item{dprocess}{the evaluator of the probability density function for transitions of the unobserved Markov state process;}
12+
##' \item{rmeasure}{the simulator of the observed process, conditional on the unobserved state;}
13+
##' \item{dmeasure}{the evaluator of the measurement model probability density function;}
14+
##' \item{emeasure}{the expectation of the measurements, conditional on the latent state;}
15+
##' \item{vmeasure}{the covariance matrix of the measurements, conditional on the latent state;}
16+
##' \item{rprior}{which samples from a prior probability distribution on the parameters;}
17+
##' \item{dprior}{which evaluates the prior probability density function;}
18+
##' \item{skeleton}{which computes the deterministic skeleton of the unobserved state process;}
19+
##' \item{partrans}{which performs parameter transformations.}
2020
##' }
2121
##' The basic structure and its rationale are described in the \emph{Journal of Statistical Software} paper, an updated version of which is to be found on the \href{https://kingaa.github.io/pomp/}{package website}.
2222
##'
@@ -118,12 +118,11 @@
118118
##' @param accumvars optional character vector;
119119
##' contains the names of accumulator variables.
120120
##' See \link{accumvars} for a definition and discussion of accumulator variables.
121-
##' @param ... additional arguments supply new or modify existing model characteristics or components.
122-
##' See \code{\link{pomp}} for a full list of recognized arguments.
123-
##'
124-
##' When named arguments not recognized by \code{\link{pomp}} are provided, these are made available to all basic components via the so-called \dfn{userdata} facility.
121+
##' @param userdata optional list; the elements of this list will be available to basic model components.
125122
##' This allows the user to pass information to the basic components outside of the usual routes of covariates (\code{covar}) and model parameters (\code{params}).
126123
##' See \link[=userdata]{userdata} for information on how to use this facility.
124+
##' @param ... additional arguments will be added to the \code{userdata} list, with a warning.
125+
##' In a future release, this warning will become an error.
127126
##' @param verbose logical; if \code{TRUE}, diagnostic messages will be printed to the console.
128127
##' @return
129128
##' The \code{pomp} constructor function returns an object, call it \code{P}, of class \sQuote{pomp}.
@@ -159,6 +158,7 @@ pomp <- function (data, times, t0, ...,
159158
covar, params, accumvars,
160159
obsnames, statenames, paramnames, covarnames,
161160
nstatevars, PACKAGE, globals, on_load,
161+
userdata,
162162
cdir = getOption("pomp_cdir", NULL), cfile,
163163
shlib.args, compile = TRUE,
164164
verbose = getOption("verbose", FALSE)) {
@@ -180,7 +180,7 @@ pomp <- function (data, times, t0, ...,
180180
missing(rprior) && missing(dprior) && missing(partrans) &&
181181
missing(covar) && missing(params) && missing(accumvars) &&
182182
missing(nstatevars) &&
183-
...length() == 0
183+
missing(userdata) && ...length() == 0
184184
)
185185
return(as(data,"pomp"))
186186

@@ -197,7 +197,7 @@ pomp <- function (data, times, t0, ...,
197197
params=params,covar=covar,accumvars=accumvars,
198198
obsnames=obsnames,statenames=statenames,paramnames=paramnames,
199199
covarnames=covarnames,nstatevars=nstatevars,PACKAGE=PACKAGE,
200-
globals=globals,on_load=on_load,
200+
globals=globals,on_load=on_load,userdata=userdata,
201201
cdir=cdir,cfile=cfile,shlib.args=shlib.args,
202202
compile=compile,verbose=verbose
203203
),
@@ -284,11 +284,14 @@ setMethod(
284284
setMethod(
285285
"construct_pomp",
286286
signature=signature(data="array", times="numeric"),
287-
definition = function (data, times, ...,
287+
definition = function (
288+
data, times,
289+
..., userdata,
288290
rinit, dinit, rprocess, dprocess,
289291
rmeasure, dmeasure, emeasure, vmeasure,
290292
skeleton, rprior, dprior,
291-
partrans, params, covar) {
293+
partrans, params, covar
294+
) {
292295

293296
if (missing(rinit)) rinit <- NULL
294297
if (missing(dinit)) dinit <- NULL
@@ -318,6 +321,7 @@ setMethod(
318321
if (is.list(params)) params <- unlist(params)
319322

320323
if (missing(covar)) covar <- covariate_table()
324+
if (missing(userdata)) userdata <- list()
321325

322326
pomp_internal(
323327
data=data,
@@ -336,6 +340,7 @@ setMethod(
336340
partrans=partrans,
337341
params=params,
338342
covar=covar,
343+
userdata=userdata,
339344
...
340345
)
341346

@@ -354,11 +359,14 @@ setMethod(
354359
setMethod(
355360
"construct_pomp",
356361
signature=signature(data="pomp", times="NULL"),
357-
definition = function (data, times, t0, timename, ...,
362+
definition = function (
363+
data, times, t0, timename,
364+
..., userdata,
358365
rinit, dinit, rprocess, dprocess,
359366
rmeasure, dmeasure, emeasure, vmeasure,
360367
skeleton, rprior, dprior, partrans, params, covar,
361-
accumvars, nstatevars, cfile) {
368+
accumvars, nstatevars, cfile
369+
) {
362370

363371
times <- data@times
364372
if (missing(t0)) t0 <- data@t0
@@ -392,6 +400,8 @@ setMethod(
392400
if (missing(nstatevars)) nstatevars <- data@nstatevars
393401
else nstatevars <- max(nstatevars[1L],data@nstatevars,na.rm=TRUE)
394402

403+
if (missing(userdata)) userdata <- list()
404+
395405
if (missing(cfile)) cfile <- NULL
396406
if (!is.null(cfile)) {
397407
cfile <- as.character(cfile)
@@ -421,6 +431,7 @@ setMethod(
421431
covar=covar,
422432
accumvars=accumvars,
423433
nstatevars=nstatevars,
434+
userdata=userdata,
424435
params=params,
425436
.solibs=data@solibs,
426437
.userdata=data@userdata,
@@ -431,15 +442,20 @@ setMethod(
431442
}
432443
)
433444

434-
pomp_internal <- function (data, times, t0, timename, ...,
445+
pomp_internal <- function (
446+
data, times, t0, timename,
447+
...,
435448
rinit, dinit, rprocess, dprocess,
436449
rmeasure, dmeasure, emeasure, vmeasure,
437450
skeleton, rprior, dprior,
438451
partrans, params, covar, accumvars, obsnames, statenames,
439452
paramnames, covarnames, nstatevars,
440453
PACKAGE, globals, on_load, cdir, cfile, shlib.args,
441-
compile, .userdata, .solibs = list(),
442-
verbose = getOption("verbose", FALSE)) {
454+
compile,
455+
userdata = list(), .userdata = list(),
456+
.solibs = list(),
457+
verbose = getOption("verbose", FALSE)
458+
) {
443459

444460
## check times
445461
if (missing(times) || !is.numeric(times) || !all(is.finite(times)) ||
@@ -459,17 +475,20 @@ pomp_internal <- function (data, times, t0, timename, ...,
459475
else
460476
timename <- as.character(timename)
461477

462-
if (missing(.userdata)) .userdata <- list()
463478
added.userdata <- list(...)
464-
if (length(added.userdata)>0) {
465-
pMess_("The provided ",
479+
if (length(added.userdata)>0L) {
480+
pWarn_("The provided ",
466481
ngettext(length(added.userdata),"object","objects")," ",
467482
paste(sQuote(names(added.userdata)),collapse=","),
468483
ngettext(length(added.userdata)," is"," are"),
469-
" available for use by POMP basic components."
484+
" available for use by POMP basic components.\n",
485+
"This option is deprecated: use ",sQuote("userdata"),
486+
" to specify the list of such objects explicitly.\n",
487+
"In a future release, this warning will become an error."
470488
)
471489
.userdata[names(added.userdata)] <- added.userdata
472490
}
491+
.userdata[names(userdata)] <- userdata
473492

474493
if (!is(rprocess,"rprocPlugin")) {
475494
pStop_(sQuote("rprocess"),

R/probe.R

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,20 @@
2323
##' @concept synthetic likelihood
2424
##' @family elementary algorithms
2525
##' @family summary statistic-based methods
26-
##'
2726
##' @inheritSection pomp Note for Windows users
28-
##'
2927
##' @include pomp_class.R pomp_fun.R pomp.R
3028
##' @importFrom stats quantile
31-
##'
3229
##' @param probes a single probe or a list of one or more probes.
3330
##' A probe is simply a scalar- or vector-valued function of one argument that can be applied to the data array of a \sQuote{pomp}.
3431
##' A vector-valued probe must always return a vector of the same size.
3532
##' A number of useful probes are provided with the package:
3633
##' see \link[=basic_probes]{basic probes}.
3734
##' @param nsim the number of model simulations to be computed.
38-
##' @param seed optional integer;
39-
##' if non-\code{NULL}, the random number generator will be initialized with this seed for simulations.
40-
##' See \code{\link{simulate}}.
35+
##' @inheritParams pfilter
36+
##' @inheritParams simulate
4137
##' @inheritParams pomp
42-
##'
4338
##' @return
4439
##' \code{probe} returns an object of class \sQuote{probed_pomp}, which contains the data and the model, together with the results of the \code{probe} calculation.
45-
##'
4640
##' @section Methods:
4741
##' The following methods are available.
4842
##' \describe{

0 commit comments

Comments
 (0)