Skip to contents

Create a response from a data set and an equation

Usage

createResponseVariable(data, equation, preTest = TRUE, subsetSize = 5)

Arguments

data

(Required) The dataset to use, must be a data.frame

equation

(Required) R function that must have a data argument or character string describing the equation that uses names of the variables in the data.

preTest

(Optional) Logical Flag. TRUE to try and build the response first with a subset of the data. The subset size is given by the minimum between the number of rows in the data and the subsetSize argument.

subsetSize

(Optional) Size of the subset if the preTest has been requested.

Value

A numeric vector corresponding to the response variable.

Details

Using the preTest will make the function fail early if the code is wrong. This is typically useful during the first steps of try and error. When the user is confident that the equation is correct, the preTest can be set to FALSE.

See also

addResidualError adds a residual error to a response.

The function createResponse is the high level function in the response component and acts as a wrapper for createResponseVariable and addResidualError.

Author

Mike K Smith mstoolkit@googlemail.com

Examples


  # define a data set
  myData <- data.frame(X = c(1,2,1), Y = c(1,1,1), Z = c(1,1,1))

  # added to comply with SF issue 7
  # Tue Jul 24 10:20:20 BST 2007 @430 /Internet Time/
  # function version
  out1 <- createResponseVariable(data = myData, equation = function(data){
    with(data, X + Y + Z)
  })

  # same using the character version
  out2 <- createResponseVariable(data = myData, equation = "X+Y+Z")
  stopifnot(identical(out1,out2))