makeAdditiveFormula
Construct modeling formulae programatically

Description

Given the names of the predictor and response variables, construct a formula suitable for use with modeling functions like lm and glm.

Usage

makeAdditiveFormula(predictors, responses, env = parent.frame(),
    onMultipleResponse = "cbind", emptyResponsesOutput = stop("no response"))

Arguments

predictors A character vector listing the names of the predictor variables or a list of expressions to use as the predictor variables.
responses A character vector listing the names of the response variables or a list of expressions to use as the response variables.
env In R, the environment attribute of the returned formula will be set to this environment. Names in the formula not otherwise found will be searched for in this environment. In S+, which has no concept of an environment, this is not used.
onMultipleResponse A character string, either "cbind" or "+". If there are multiple responses should they be tied together by a call to "cbind" (the common thing in modeling functions) or by calls to "+" (uncommon, but used in ftable)?
emptyResponsesOutput If there are no response variables (or expressions) listed, use this as a placeholder. The default action is to signal an error. You can supply NULL to mean that not having a response is acceptable.

Details

The most common usage is just makeAdditiveFormula(predictors, responses) where predictors and responses list the names of variables. makeAdditiveFormula calls the two helper routines .makeAdditiveExpr and .makeCbindExpr to build the formula and it is possible that one might want to use them directly to construct unusual formulae.
Value
If there is only one response variable makeAdditiveFormula returns a formula of the form Response ~ Predictor1 + Predictor2 + ...; if there is more than one response variable it returns either cbind(Response1,Response2,...) ~ Predictor1 + Predictor2 + ... or Response1 + Response2 + ... ~ Predictor1 + Predictor2 + ..., depending on the value of onMultipleResponses.
See Also
.makeAdditiveExpr and .makeCbindExpr are used to make the default right and left sides of the formula, respectively.
Examples
makeAdditiveFormula(predictors=c("Age", "Sex"), responses=c("Attitude"))
makeAdditiveFormula(predictors=c("Town"), responses=c("NumCases", "Population"))
Package SpotfireUtils version 4.0.0-28
Package Index