View source: R/difeq_replicate.R
difeq_replicate | R Documentation |
Solve a replicate set of difference (or recurrence) equation by
iterating it a number of times. This is a wrapper around
difeq
that does not (yet) do anything clever to
avoid many allocations.
difeq_replicate(n, y, steps, target, parms, ..., n_out = 0L,
n_history = 0L, grow_history = FALSE, return_history = n_history > 0,
dllname = "", parms_are_real = TRUE, ynames = NULL, outnames = NULL,
return_by_column = TRUE, return_initial = TRUE, return_step = TRUE,
return_output_with_y = TRUE, restartable = FALSE,
return_minimal = FALSE, as_array = TRUE)
n |
Number of replicates. It is an error to request zero replicates. |
y |
The initial state of the system. Must be either a
numeric vector or a |
steps |
A vector of steps to return the system at. The
first step is taken as step zero, and the solution will
be recorded at every other step in the vector. So to step a
system from time zero to times 1, 2, 3, ..., n use 0:n. Must be
integer values and will be passed through |
target |
The target function to advance. This can either be
an R function taking arguments |
parms |
Parameters to pass through to the difference function |
... |
Dummy arguments - nothing is allowed here, but this means that all further arguments must be specified by name (not order) so I can easily reorder them later on. |
n_out |
The number of output variables (in addition to the
difference equation variables). If given, then an R function
must return an attribute |
n_history |
The number of iterations of history to save during the simulation. By default, no history is saved. |
grow_history |
Logical indicating if history should be grown
during the simulation. If |
return_history |
Logical indicating if history is to be
returned. By default, history is returned if |
dllname |
Name of the shared library (without extension) to
find the function |
parms_are_real |
Logical, indicating if |
ynames |
Logical, indicating if the output should be named
following the names of the input vector |
outnames |
An optional character vector, used when
|
return_by_column |
Logical, indicating if the output should be
returned organised by column (rather than row). This incurs a
slight cost for transposing the matrices. If you can work with
matrices that are transposed relative to |
return_initial |
Logical, indicating if the output should
include the initial conditions. Specifying |
return_step |
Logical, indicating if a row (or column if
|
return_output_with_y |
Logical, indicating if the output
should be bound together with the returned matrix |
restartable |
Logical, indicating if the problem should be
restartable. If |
return_minimal |
Shorthand option - if set to |
as_array |
(Defunct) Logical, indicating if the output should
be converted into an array. If |
It is not currently possible to replicate over a set of parameters at once yet; the same parameter set will be used for all replications.
The details of how replication is done here are all considered
implementation details and are up for change in the future - in
particular if the models are run in turn or simultaneously (and
the effect that has on the random number stream). Logic around
naming output may change in future too; note that varying names in
the y
here will have some unexpected behaviours.
# Here is a really simple equation that does a random walk with
# steps that are normally distributed:
rhs <- function(i, y, p) y + runif(1)
y0 <- 1
t <- 0:10
p <- 5
dde::difeq_replicate(10, y0, t, rhs, p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.