R typically recognizes relationships between variables given data in this format:
dependent variable(s) ~ independent variable(s)
Example:
y
.x
and z
, respectively.y ~ x + z
.Functions that accept formula notation often let you reference data objects in either of two ways:
y
and x
are each vectors in your environment, so lm(formula = y ~ x)
dat
has columns dat$y
and dat$x
, so lm(formula = y ~ x, data = dat)
y ~ x
y ~ x + z
y ~ x + z - 1
y ~ .
z
) as independent variables: y ~ . - z
x
and z
: x:z
x
, z
, w
, and all interactions among them: x * z * w
x
, z
, w
, and all interactions up to two-way interactions: (x + z + w)^2
When fitting a mixed effects model (e.g.: lme(...)
), fit x
grouped by z
: x|z
Model the variable resulting from the enclosed mathematical operation: I(...)
x
and z
: I(x*z)
x
, z
, and w
: I(x+z+w)