First model.frame
is called. Then,
if family = gaussian
, the response is checked to ensure that it is
numeric and has more than two unique values. If scale_by
is
used on the response in formula
, then the scale
argument to
scale_by
is ignored and forced to 1
. If scale_by
is not called, then scale
is used with default arguments.
The result is that gaussian responses are on unit scale (i.e. have mean
0
and standard deviation 1
), or, if scale_by
is
used on the left hand side of formula
, unit scale within each
level of the specified conditioning factor.
Offsets in gaussian models are divided by the standard deviation of the
the response prior to scaling (within-factor-level if scale_by
is used on the response). In this way, if the transformed offset is added
to the transformed response, and then placed back on the response's original
scale, the result would be the same as if the un-transformed offset had
been added to the un-transformed response.
For all other values for family
, the response and offsets are not checked.
If offsets are used within the formula
, then they will be in the
formula
and data
elements of the '>standardized
object. If the offset
argument to the standardize
function is
used, then the offset provided in the argument will be
in the offset
element of the '>standardized
object
(scaled if family = gaussian
).
For the other predictors in the formula, first any random effects grouping factors
in the formula are coerced to factor and unused levels are dropped. The
levels of the resulting factor are then recorded in the groups
element.
Then for the remaining predictors, regardless of their original
class, if they have only two unique non-NA
values, they are coerced
to unordered factors. Then, named_contr_sum
and
scaled_contr_poly
are called for unordered and ordered factors,
respectively, using the scale
argument provided in the call
to standardize
as the scale
argument to the contrast
functions. For numeric variables, if the variable contains a call to
scale_by
, then, regardless of whether the call to
scale_by
specifies scale
, the value of scale
in the call to standardize
is used. If the numeric variable
does not contain a call to scale_by
, then
scale
is called, ensuring that the result has
standard deviation scale
.
With the default value of scale = 1
, the result is a
'>standardized
object which contains a formula and data
frame (and offset vector if the offset
argument to the
standardize
function was used) which can be used to fit regressions
where the predictors are all on a similar scale. Its data frame
has numeric variables on unit scale, unordered factors with named sum
sum contrasts, and ordered factors with orthogonal polynomial contrasts
on unit scale. For gaussian regressions, the response is also placed on
unit scale. If scale = 0.5
(for example),
then gaussian responses would still
be placed on unit scale, but unordered factors' named sum contrasts would
take on values -0.5, 0, 0.5 rather than -1, 0, 1, the standard deviation
of each column in the contrast matrices for ordered factors would be
0.5
rather than 1
, and the standard deviation of numeric
variables would be 0.5
rather than 1
(within-factor-level
in the case of scale_by
calls).