View source: R/addResidualError.R
addResidualError | R Documentation |
Adds residual error to a generated response, based on a supplied variance values.
addResidualError(
response,
covariance,
errStruc = c("Additive", "Proportional", "Log-Normal", "Combined"),
seed = .deriveFromMasterSeed()
)
response |
(Required) Numeric vector of response data |
covariance |
(Required) Residual error (co)variance. This would be the
lower-triangle of the matrix, or the matrix itself. The function
|
errStruc |
(Optional) Function describing how to apply residual error: "Additive", "Log-Normal" or "Proportional". "Additive" is the default |
seed |
(Optional) Random seed to use. Derived from the current random seed by default |
The first step in the algorithm will be to set the random number seed to the
"seed" argument. Then, a number of samples will be drawn from a
multivariate normal distribution with mean 0 and variance set by the
(parsed) covariance
input. The number of samples to take will be set
by the number of elements in the "response" vector.
Based on the "errStruc" input, the algorithm should continue as follows. * If it is Additive, the residual errors should be added to the response vector. * If it is Log Normal, the response vector is multiplied by the exponentiated residual error. * If it is Proportional, the response vector is multiplied by "1 + the residual error".
A numeric vector
In earlier versions of MSToolkit, the "Proportional" Error Structure behaved differently (it assumed parameters passed were on the log scale).
MSToolkit currently has a limit of two residual error variances / covariances to create additive, proportional or combined additive + proportional error structures. At this time MSToolkit cannot simulate from time-series or complex residual variance structures i.e. multi-variate Normal distributions with number of error terms = number of observations.
Romain Francois, Rich Pugh
This function is typically not directly called by the user, but
rather called by the function createResponse
that is the
high-level function for the response component.
The function createResponseVariable
is also in the response
component. It create the the response onto which addResidualError
adds error.
myVec <- 1:10
addResidualError(response = myVec, covariance = "1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.