|
22 | 22 | ##' @param rw.sd specification of the magnitude of the random-walk perturbations that will be applied to some or all model parameters. |
23 | 23 | ##' Parameters that are to be estimated should have positive perturbations specified here. |
24 | 24 | ##' The specification is given using the \code{\link{rw_sd}} function, which creates a list of unevaluated expressions. |
25 | | -##' The latter are evaluated in a context where the model time variable is defined (as \code{time}). |
| 25 | +##' The latter are evaluated in a context where vector of observation times is visible (as \sQuote{\code{time}}). |
26 | 26 | ##' The expression \code{ivp(s)} can be used in this context as shorthand for \preformatted{ifelse(time==time[1],s,0).} |
27 | 27 | ##' Likewise, \code{ivp(s,lag)} is equivalent to \preformatted{ifelse(time==time[lag],s,0).} |
28 | 28 | ##' See below for some examples. |
|
55 | 55 | ##' |
56 | 56 | ##' @section Specifying the perturbations: |
57 | 57 | ##' The \code{rw_sd} function simply returns a list containing its arguments as unevaluated expressions. |
58 | | -##' These are then evaluated in a context containing the model \code{time} variable. |
| 58 | +##' These are then evaluated in a context in which the vector of observation times is defined (as \sQuote{\code{time}}). |
59 | 59 | ##' This allows for easy specification of the structure of the perturbations that are to be applied. |
60 | 60 | ##' For example, |
61 | 61 | ##' \preformatted{ |
62 | | -##' rw_sd(a=0.05, b=ifelse(time==time[1],0.2,0), |
63 | | -##' c=ivp(0.2), d=ifelse(time==time[13],0.2,0), |
64 | | -##' e=ivp(0.2,lag=13), f=ifelse(time<23,0.02,0)) |
| 62 | +##' rw_sd( |
| 63 | +##' a=0.05, |
| 64 | +##' b=ifelse(time==time[1], 0.2, 0), |
| 65 | +##' c=ivp(0.2), |
| 66 | +##' d=ifelse(time==time[13], 0.2, 0), |
| 67 | +##' e=ivp(0.2, lag=13), |
| 68 | +##' f=ifelse(time<23, 0.02, 0), |
| 69 | +##' g=ifelse(time>=23 & time<50, 0.02, 0), |
| 70 | +##' h=ivp(0.1,lags=3:8) |
| 71 | +##' ) |
65 | 72 | ##' } |
66 | | -##' 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. |
67 | | -##' Parameters \code{d} and \code{e}, by contrast, get perturbations of s.d. 0.2 only just before the thirteenth observation. |
68 | | -##' Finally, parameter \code{f} gets a random perturbation of size 0.02 before every observation falling before \eqn{t=23}. |
| 73 | +##' 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). |
| 74 | +##' Parameters \code{d} and \code{e}, by contrast, get perturbations of s.d. 0.2 only before the thirteenth observation. |
| 75 | +##' Parameter \code{f} gets a random perturbation of size 0.02 before every observation falling before \eqn{t=23}, |
| 76 | +##' while \code{g} gets perturbed before all observations that fall in the interval \eqn{23\le{t}<{50}}{23<=t<50}. |
| 77 | +##' Finally, the magnitude of the perturbation of parameter \code{h} is applied before the third through eighth observations. |
69 | 78 | ##' |
70 | 79 | ##' 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. |
71 | 80 | ##' Let \eqn{N} be the length of the time series and \eqn{\alpha=}{alpha=}\code{cooling.fraction.50}. |
@@ -546,7 +555,7 @@ perturbn_kernel_sd <- function (rw.sd, time, paramnames) { |
546 | 555 | sQuote("params"),": ",paste(lapply(unrec,sQuote),collapse=","),".") |
547 | 556 | } |
548 | 557 | ivp <- function (sd, lag = 1L) { |
549 | | - sd*(seq_along(time)==lag) |
| 558 | + sd*(seq_along(time) %in% lag) |
550 | 559 | } |
551 | 560 | sds <- lapply(rw.sd,eval,envir=list(time=time,ivp=ivp),enclos=enclos) |
552 | 561 | for (n in names(sds)) { |
|
0 commit comments