Performs a standardization of data (z-scoring) using
datawizard::standardize()
and then re-fits the model to the standardized
data.
Standardization is done by completely refitting the model on the standardized
data. Hence, this approach is equal to standardizing the variables before
fitting the model and will return a new model object. This method is
particularly recommended for complex models that include interactions or
transformations (e.g., polynomial or spline terms). The robust
(default to
FALSE
) argument enables a robust standardization of data, based on the
median
and the MAD
instead of the mean
and the SD
.
# S3 method for default
standardize(
x,
robust = FALSE,
two_sd = FALSE,
weights = TRUE,
verbose = TRUE,
include_response = TRUE,
...
)
A statistical model.
Logical, if TRUE
, centering is done by subtracting the
median from the variables and dividing it by the median absolute deviation
(MAD). If FALSE
, variables are standardized by subtracting the
mean and dividing it by the standard deviation (SD).
If TRUE
, the variables are scaled by two times the deviation
(SD or MAD depending on robust
). This method can be useful to obtain
model coefficients of continuous parameters comparable to coefficients
related to binary predictors, when applied to the predictors (not the
outcome) (Gelman, 2008).
If TRUE
(default), a weighted-standardization is carried out.
Toggle warnings and messages on or off.
For a model, if TRUE
(default), the response value
will also be standardized. If FALSE
, only the predictors will be
standardized. Note that for certain models (logistic regression, count
models, ...), the response value will never be standardized, to make
re-fitting the model work. (For mediate
models, only applies to the y
model; m model's response will always be standardized.)
Arguments passed to or from other methods.
A statistical model fitted on standardized data
Standardization for generalized linear models (GLM, GLMM, etc) is done only with respect to the predictors (while the outcome remains as-is, unstandardized) - maintaining the interpretability of the coefficients (e.g., in a binomial model: the exponent of the standardized parameter is the OR of a change of 1 SD in the predictor, etc.)
standardize(model)
or standardize_parameters(model, method = "refit")
do
not standardized categorical predictors (i.e. factors) / their
dummy-variables, which may be a different behaviour compared to other R
packages (such as lm.beta) or other software packages (like SPSS). To
mimic such behaviours, either use standardize_parameters(model, method = "basic")
to obtain post-hoc standardized parameters, or standardize the data
with datawizard::standardize(data, force = TRUE)
before fitting the
model.
When the model's formula contains transformations (e.g. y ~ exp(X)
) the
transformation effectively takes place after standardization (e.g.,
exp(scale(X))
). Since some transformations are undefined for none positive
values, such as log()
and sqrt()
, the releven variables are shifted (post
standardization) by Z - min(Z) + 1
or Z - min(Z)
(respectively).
Other standardize:
standardize_info()
,
standardize_parameters()
# NOT RUN {
model <- lm(Infant.Mortality ~ Education * Fertility, data = swiss)
coef(standardize(model))
# }
Run the code above in your browser using DataLab