addResidualError: Add residual error to the response.

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Adds residual error to a generated response, based on a supplied variance-covariance matrix

Usage

1
2
3
4
addResidualError(response, 
covariance, 
errStruc = c("Additive", "Proportional", "Log-Normal"), 
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 covariance 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)

Author(s)

Mike K Smith mstoolkit@googlemail.com

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

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

MSToolkit documentation built on May 2, 2019, 6:30 p.m.