createResponseVariable: Create a response from a data set and an equation

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

Description

Create a response from a data set and an equation

Usage

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

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.

Value

A numeric vector corresponding to the response variable.

Author(s)

Mike K Smith mstoolkit@googlemail.com

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  # define a data set
  myData <- data.frame( X = c(1,2,1), Y = c(1,1,1), Z = c(1,1,1) )
  
  
  
  # 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))

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