simulate_nls {nlraa} | R Documentation |
Simulate fitted values from an object of class nls
Description
Simulate values from an object of class nls.
Usage
simulate_nls(
object,
nsim = 1,
psim = 1,
resid.type = c("none", "resample", "normal", "wild"),
value = c("matrix", "data.frame"),
data = NULL,
...
)
Arguments
object |
object of class |
nsim |
number of simulations to perform |
psim |
parameter simulation level, 0: for fitted values, 1: for simulation from fixed parameters (assuming a fixed vcov matrix), 2: simulation from sampling both from the parameters and the residuals, 3: for simulation considering the uncertainty in the residual standard error only (sigma) and fixing the parameter estimates at their original value; this will result in simulations similar to the observed values. |
resid.type |
either ‘none’, “resample”, “normal” or “wild”. |
value |
either ‘matrix’ or ‘data.frame’ |
data |
the data argument is needed when using this function inside user defined functions. |
... |
additional arguments (it is possible to supply a newdata this way) |
Details
This function is based on predict.gnls
function
It uses function mvrnorm
to generate new values for the coefficients
of the model using the Variance-Covariance matrix vcov
. This variance-covariance matrix
refers to the one for the parameters ‘beta’, not the one for the residuals.
Value
It returns a vector with simulated values with length equal to the number of rows in the original data
Note
The default behavior is that simulations are perfomed for the mean function only.
When ‘psim = 2’ this function will silently choose ‘resample’ as the
‘resid.type’. This is not ideal design for this function, but I made this choice for
compatibility with other types of simulation originating from glm
and
gam
.
See Also
Examples
data(barley, package = "nlraa")
fit <- nls(yield ~ SSlinp(NF, a, b, xs), data = barley)
sim <- simulate_nls(fit, nsim = 100)