Formula {Formula}R Documentation

Extended Formulas

Description

The new class Formula extends the base class formula. Currently, the only extenseion are two-part formulas, further extensions are planned.

Usage

Formula(object)

as.Formula(x, ...)
## Default S3 method:
as.Formula(x, ...)
is.Formula(object)

## S3 method for class 'Formula':
formula(x, part = c("first", "second", "both"), response = NULL, ...)
## S3 method for class 'Formula':
terms(x, ..., part = "first", response = NULL)
## S3 method for class 'Formula':
update(object, new, ...)
## S3 method for class 'Formula':
model.matrix(object, ..., part = "first")
## S3 method for class 'Formula':
model.frame(formula, ..., part = NULL, response = NULL)
## S3 method for class 'Formula':
length(x)

has.intercept(object, ...)
## S3 method for class 'formula':
has.intercept(object, ...)
## S3 method for class 'Formula':
has.intercept(object, part = "first", ...)

Arguments

object, x, formula an object. For Formula it needs to be a formula object.
part character specifying the part of the right hand side of the formula to use: "first", "second" or "both".
response logical. Should the response be include in the formula?
new a formula giving a template which specifies how to update.
... further arguments.

Details

Formula objects extend the basic formula objects. Currently, the only extension implemented are two-part formulas of type: y ~ x1 + x2 | z1 + z2 + z3. However, Formula is under development and features on the wishlist for future versions include multi-part formulas (y ~ x1 + x2 | u1 + u2 + u3 | v1 + v2) and multiple response formulas (y1 + y2 ~ x1 + x2 + x3). This might result in changes of the interface of some methods in future versions.

Currently, a Formula is a formula for which the right hand side has two parts separated by a pipe sign. The Formula function coerce a formula to a Formula object just by modifying the class attribute.

is.Formula check whether the argument of the function is Formula object.

as.Formula is a generic for coercing to Formula, the default method first coerces to formula and then calls Formula.

Several methods are provided: They all use the formula method for creating a standard formula first. The returned formula is a one-sided formula if response = FALSE and a two-sided formula if response = TRUE. The right-hand side depends on the part argument: the first part ("first"), the second part "second" or both ("both").

Hence, the two arguments (response and part) are used in the terms, model.frame and model.matrix methods.

Value

Formula returns an object of class Formula which inherits from formula.

Examples

data("airquality", package = "datasets")
f <- Ozone ~ Solar.R + Wind | Temp

# create a Formula object from the formula
f2 <- Formula(f)
class(f2)

# examples of updates of the two-parts formula
update(f2,. ~ . - Wind + Day | . + Month)
update(f2,. ~ . | . + Month)
update(f2,. ~ . - Wind + Day | .)

# get the first, second and both parts, with or without the response
formula(f2, part = "first", response = TRUE)
formula(f2, part = "second", response = FALSE)
formula(f2, part = "both")

# model.frame for the first part and for both parts
head(model.frame(f2, part = "first", data = airquality))
head(model.frame(f2, part = "both", data = airquality))

# model.matrix for the first and the second part
head(model.matrix(f2, data = airquality, part = "first"))
head(model.matrix(f2, data = airquality, part = "second"))

# note that the sample is not the same due to missing values
mf <- model.frame(f2, part = "both", data = airquality)
head(model.matrix(f2, data = mf, part = "first"))
head(model.matrix(f2, data = mf, part = "second"))

[Package Formula version 0.1-3 Index]