addResidualError: Add residual error to the response.

View source: R/addResidualError.R

addResidualErrorR Documentation

Add residual error to the response.

Description

Adds residual error to a generated response, based on a supplied variance values.

Usage

addResidualError(
  response,
  covariance,
  errStruc = c("Additive", "Proportional", "Log-Normal", "Combined"),
  seed = .deriveFromMasterSeed()
)

Arguments

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 parseCovMatrix is used to ensure that the matrix is in the right format.

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

Details

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".

Value

A numeric vector

Note

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.

Author(s)

Romain Francois, Rich Pugh

See Also

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.

Examples


  myVec <- 1:10
  addResidualError(response = myVec, covariance = "1")


MikeKSmith/MSToolkit documentation built on July 3, 2024, 1:53 a.m.