Plot the Spatial or Temporal Interaction Function of a
The function plots the fitted temporal or (isotropic) spatial
interaction function of a
The implementation is illustrated in Meyer et al. (2017, Section 3),
iafplot(object, which = c("siaf", "tiaf"), types = NULL, scaled = c("intercept", "standardized", "no"), truncated = FALSE, log = "", conf.type = if (length(pars) > 1) "MC" else "parbounds", conf.level = 0.95, conf.B = 999, xgrid = 101, col.estimate = rainbow(length(types)), col.conf = col.estimate, alpha.B = 0.15, lwd = c(3,1), lty = c(1,2), verticals = FALSE, do.points = FALSE, add = FALSE, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, legend = !add && (length(types) > 1), ...)
object of class
"twinstim"containing the fitted model.
argument indicating which of the two interaction functions to plot. Possible values are
"siaf"(default) for the spatial interaction \(f(x)\) as a function of the distance \(x\), and
"tiaf"for the temporal interaction function \(g(t)\).
integer vector indicating for which event
typesthe interaction function should be plotted in case of a marked
"twinstim". The default
types=NULLchecks if the interaction function is type-specific: if so,
types=1:nrow(object$qmatrix)is used, otherwise
character string determining if/how the the interaction function should be scaled. Possible choices are:
multiplication by the epidemic intercept.
division by the value at 0 distance such that the function starts at 1.
The first one is the default and required for the comparison of estimated interaction functions from different models. For backward compatibility,
scaledcan also be a boolean, where
logical indicating if the plotted interaction function should take the maximum range of interaction (
eps.s) into account, i.e., drop to zero at that point (if it is finite after all). If there is no common range of interaction, a
rugindicating the various ranges will be added to the plot if
truncatedis a scalar, this value is used as the point
epswhere the function drops to 0.
a character string passed to
plot.defaultindicating which axes should be logarithmic. If
logis set according to
type of confidence interval to produce.
conf.Bparameter vectors are sampled from the asymptotic (multivariate) normal distribution of the ML estimate of the interaction function parameters; the interaction function is then evaluated on the
xgrid(i.e. temporal or spatial distances from the host) for each parameter realization to obtain a
conf.levelconfidence interval at each point of the
xgrid(or to plot the interaction functions of all Monte-Carlo samples if
conf.level=NA). Note that the resulting plot is
.Random.seed-dependent for the Monte-Carlo type of confidence interval.
conf.levelWald confidence intervals for the interaction function parameters are calculated and the interaction function is evaluated on the
xgrid(distances from the host) for all combinations of the bounds of the parameters and the point-wise extremes of those functions are plotted. This type of confidence interval is only valid in case of a single parameter, i.e.
scaled + nsiafpars == 1, but could also be used as a rough indication if the Monte-Carlo approach takes too long. A warning is thrown if the
"parbounds"type is used for multiple parameters.
NULL, no confidence interval will be calculated.
the confidence level required. For
conf.type = "MC"it may also be specified as
NA, in which case all
conf.Bsampled functions will be plotted with transparency value given by
number of samples for the
"MC"(Monte Carlo) confidence interval.
either a numeric vector of x-values (distances from the host) where to evaluate
which, or a scalar representing the desired number of evaluation points in the interval
If the interaction function is a step function (
xgridis ignored and internally set to
vector of colours to use for the function point estimates of the different
vector of colours to use for the confidence intervals of the different
alpha transparency value (as relative opacity) used for the
conf.Bsampled interaction functions in case
conf.level = NA
- lwd, lty
numeric vectors of length two specifying the line width and type of point estimates (first element) and confidence limits (second element), respectively.
graphical settings for step function kernels. These can be logical (as in
plot.stepfun) or lists of graphical parameters.
add to an existing plot?
- xlim, ylim
vectors of length two containing the x- and y-axis limit of the plot. The default y-axis range (
ylim=NULL) is from 0 to the value of the (scaled) interaction function at \(x = 0\). The default x-axis (
xlim=NULL) starts at 0, and the upper limit is determined as follows (in decreasing order of precedence):
xgridis a vector of evaluation points,
xlimis set to
eps.sif it is unique and finite.
If the interaction function is a step function with
maxRange<Inf, i.e. it drops to 0 at
xlimis set to
Otherwise, it is set to the length of the observation period (
which="tiaf") or the diagonal length of the bounding box of the observation region (
- xlab, ylab
labels for the axes with
NULLproviding sensible defaults.
logical indicating if a legend for the
typesshould be added. It can also be a list of arguments passed to
legendto tweak the default settings.
additional arguments passed to the default
A plot is created -- see e.g. Figure 3(b) in Meyer et al. (2012).
The function invisibly returns a matrix of the plotted values of the
interaction function (evaluated on
xgrid, by type). The first
column of the matrix contains the distance \(x\), and the remaining
length(types) columns contain the (scaled) function values for
The pointwise confidence intervals of the interaction functions are returned in similar matrices as attributes: if
length(types)==1, there is a single attribute
whereas for multiple types, the attributes are named
paste0("CI.",typeNames) (where the
Meyer, S., Elias, J. and Höhle, M. (2012): A space-time conditional intensity model for invasive meningococcal disease occurrence. Biometrics, 68, 607-616. doi:10.1111/j.1541-0420.2011.01684.x
Meyer, S., Held, L. and Höhle, M. (2017): Spatio-temporal analysis of epidemic phenomena using the R package surveillance. Journal of Statistical Software, 77 (11), 1-55. doi:10.18637/jss.v077.i11
plot.twinstim, which calls this function.
data("imdepifit") iafplot(imdepifit, "tiaf", scaled=FALSE) # tiaf.constant(), not very exciting iafplot(imdepifit, "siaf", scaled=FALSE) # scaled version uses a Monte-Carlo-CI set.seed(1) # result depends on .Random.seed iafplot(imdepifit, "siaf", scaled=TRUE, conf.type="MC", conf.B=199, col.conf=gray(0.4), conf.level=NA) # show MC samples