Skip to content

Commit

Permalink
multiple lags can now be specified in 'ivp'
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Jan 5, 2025
1 parent e2a0fd5 commit 7f5f59f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pomp
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 6.0.4.1
Date: 2024-12-30
Version: 6.0.5.0
Date: 2025-01-05
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="[email protected]",comment=c(ORCID="0000-0001-6159-3207")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),
Expand Down
27 changes: 18 additions & 9 deletions R/mif2.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
##' @param 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 \code{\link{rw_sd}} function, which creates a list of unevaluated expressions.
##' The latter are evaluated in a context where the model time variable is defined (as \code{time}).
##' The latter are evaluated in a context where vector of observation times is visible (as \sQuote{\code{time}}).
##' The expression \code{ivp(s)} can be used in this context as shorthand for \preformatted{ifelse(time==time[1],s,0).}
##' Likewise, \code{ivp(s,lag)} is equivalent to \preformatted{ifelse(time==time[lag],s,0).}
##' See below for some examples.
Expand Down Expand Up @@ -55,17 +55,26 @@
##'
##' @section Specifying the perturbations:
##' The \code{rw_sd} function simply returns a list containing its arguments as unevaluated expressions.
##' These are then evaluated in a context containing the model \code{time} variable.
##' These are then evaluated in a context in which the vector of observation times is defined (as \sQuote{\code{time}}).
##' This allows for easy specification of the structure of the perturbations that are to be applied.
##' For example,
##' \preformatted{
##' rw_sd(a=0.05, b=ifelse(time==time[1],0.2,0),
##' c=ivp(0.2), d=ifelse(time==time[13],0.2,0),
##' e=ivp(0.2,lag=13), f=ifelse(time<23,0.02,0))
##' rw_sd(
##' a=0.05,
##' b=ifelse(time==time[1], 0.2, 0),
##' c=ivp(0.2),
##' d=ifelse(time==time[13], 0.2, 0),
##' e=ivp(0.2, lag=13),
##' f=ifelse(time<23, 0.02, 0),
##' g=ifelse(time>=23 & time<50, 0.02, 0),
##' h=ivp(0.1,lags=3:8)
##' )
##' }
##' results in perturbations of parameter \code{a} with s.d. 0.05 at every time step, while parameters \code{b} and \code{c} both get perturbations of s.d. 0.2 only just before the first observation.
##' Parameters \code{d} and \code{e}, by contrast, get perturbations of s.d. 0.2 only just before the thirteenth observation.
##' Finally, parameter \code{f} gets a random perturbation of size 0.02 before every observation falling before \eqn{t=23}.
##' results in random perturbations of parameter \code{a} with s.d. 0.05 at every time step, while parameters \code{b} and \code{c} both get perturbations of s.d. 0.2 only before the first observation (i.e., at the zero-time).
##' Parameters \code{d} and \code{e}, by contrast, get perturbations of s.d. 0.2 only before the thirteenth observation.
##' Parameter \code{f} gets a random perturbation of size 0.02 before every observation falling before \eqn{t=23},
##' while \code{g} gets perturbed before all observations that fall in the interval \eqn{23\le{t}<{50}}{23<=t<50}.
##' Finally, the magnitude of the perturbation of parameter \code{h} is applied before the third through eighth observations.
##'
##' On the \eqn{m}-th IF2 iteration, prior to time-point \eqn{n}, the \eqn{d}-th parameter is given a random increment normally distributed with mean \eqn{0} and standard deviation \eqn{c_{m,n} \sigma_{d,n}}{c[m,n] sigma[d,n]}, where \eqn{c} is the cooling schedule and \eqn{\sigma}{sigma} is specified using \code{rw_sd}, as described above.
##' Let \eqn{N} be the length of the time series and \eqn{\alpha=}{alpha=}\code{cooling.fraction.50}.
Expand Down Expand Up @@ -546,7 +555,7 @@ perturbn_kernel_sd <- function (rw.sd, time, paramnames) {
sQuote("params"),": ",paste(lapply(unrec,sQuote),collapse=","),".")
}
ivp <- function (sd, lag = 1L) {
sd*(seq_along(time)==lag)
sd*(seq_along(time) %in% lag)
}
sds <- lapply(rw.sd,eval,envir=list(time=time,ivp=ivp),enclos=enclos)
for (n in names(sds)) {
Expand Down
6 changes: 6 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
_N_e_w_s _f_o_r _p_a_c_k_a_g_e '_p_o_m_p'

_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _6._0._5:

• It is now possible to specify more than one lag in the ‘ivp’
function, which is evaluated only when the ‘mif2’
perturbations are specified. See ‘?mif2’.

_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _6._0._4:

• The new function ‘append_data’ appends a data frame to an
Expand Down
6 changes: 6 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
\name{NEWS}
\title{News for package `pomp'}
\section{Changes in \pkg{pomp} version 6.0.5}{
\itemize{
\item It is now possible to specify more than one lag in the \code{ivp} function, which is evaluated only when the \code{mif2} perturbations are specified.
See \code{?mif2}.
}
}
\section{Changes in \pkg{pomp} version 6.0.4}{
\itemize{
\item The new function \code{append_data} appends a data frame to an existing CSV file (creating the file if it does not exist).
Expand Down
25 changes: 17 additions & 8 deletions man/mif2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f5f59f

Please sign in to comment.