Learn R Programming

effectsize (version 0.2.0)

standardize_parameters: Parameters standardization

Description

Compute standardized model parameters (coefficients).

Usage

standardize_parameters(
  model,
  parameters = NULL,
  method = "refit",
  robust = FALSE,
  two_sd = FALSE,
  verbose = TRUE,
  centrality = "median",
  ...
)

standardize_posteriors( model, method = "refit", robust = FALSE, two_sd = FALSE, verbose = TRUE, ... )

Arguments

model

A statistical model.

parameters

An optional table containing the parameters to standardize. If NULL, will automatically retrieve it from the model.

method

The method used for standardizing the parameters. Can be "refit" (default), "posthoc", "smart" or "basic". See 'Details'.

robust

Logical, if TRUE, centering is done by substracting the median from the variables and dividing it by the median absolute deviation (MAD). If FALSE, variables are standardized by substracting the mean and dividing it by the standard deviation (SD).

two_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 (Gelman, 2008).

verbose

Toggle warnings on or off.

centrality

For Bayesian models, which point-estimates (centrality indices) to compute. Character (vector) or list with one or more of these options: "median", "mean", "MAP" or "all".

...

Arguments passed to or from other methods.

Value

Standardized parameters.

Details

Methods:

  • refit: This method is based on a complete model re-fit with a standardized version of data. Hence, this method is equal to standardizing the variables before fitting the model. It is the "purest" and the most accurate (Neter et al., 1989), but it is also the most computationally costly and long (especially for heavy models such as, for instance, for Bayesian models). 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, i.e., based on the median and MAD instead of the mean and SD.

  • posthoc: Post-hoc standardization of the parameters, aiming at emulating the results obtained by "refit" without refitting the model. The coefficients are divided by the standard deviation (or MAD if robust) of the outcome (which becomes their expression 'unit'). Then, the coefficients related to numeric variables are additionally multiplied by the standard deviation (or MAD if robust) of the related terms, so that they correspond to changes of 1 SD of the predictor (e.g., "A change in 1 SD of x is related to a change of 0.24 of the SD of y). This does not apply to binary variables or factors, so the coefficients are still related to changes in levels. This method is not accurate and tend to give aberrant results when interactions are specified.

  • smart (Standardization of Model's parameters with Adjustment, Reconnaissance and Transformation): Similar to method = "posthoc" in that it does not involve model refitting. The difference is that the SD of the response is computed on the relevant section of the data. For instance, if a factor with 3 levels A (the intercept), B and C is entered as a predictor, the effect corresponding to B vs. A will be scaled by the variance of the response at the intercept only. As a results, the coefficients for effects of factors are similar to a Glass' delta.

  • basic: This method is similar to method = "posthoc", but treats all variables as continuous: it also scales the coefficient by the standard deviation of model's matrix' parameter of factors levels (transformed to integers) or binary predictors. Although being inappropriate for these cases, this method is the one implemented by default in other software packages, such as lm.beta::lm.beta().

When method = "smart" or method = "classic", standardize_parameters() also returns the standard errors for the standardized coefficients. Then, ci() can be used to calculate confidence intervals for the standardized coefficients. See 'Examples'.

References

  • Neter, J., Wasserman, W., & Kutner, M. H. (1989). Applied linear regression models.

  • Gelman, A. (2008). Scaling regression inputs by dividing by two standard deviations. Statistics in medicine, 27(15), 2865-2873.

See Also

standardize_info

Examples

Run this code
# NOT RUN {
library(effectsize)
data(iris)

model <- lm(Sepal.Length ~ Species * Petal.Width, data = iris)
standardize_parameters(model, method = "refit")

# }
# NOT RUN {
standardize_parameters(model, method = "posthoc")
standardize_parameters(model, method = "smart")
standardize_parameters(model, method = "basic")

# Robust and 2 SD
standardize_parameters(model, robust = TRUE)
standardize_parameters(model, two_sd = TRUE)

# show CI
library(parameters)
params <- standardize_parameters(model, method = "smart", robust = TRUE)
ci(params)

iris$binary <- ifelse(iris$Sepal.Width > 3, 1, 0)
model <- glm(binary ~ Species * Sepal.Length, data = iris, family = "binomial")
standardize_parameters(model, method = "refit")
standardize_parameters(model, method = "posthoc")
standardize_parameters(model, method = "smart")
standardize_parameters(model, method = "basic")
# }
# NOT RUN {
# }
# NOT RUN {
if (require("rstanarm")) {
  model <- stan_glm(Sepal.Length ~ Species * Petal.Width, data = iris, iter = 500, refresh = 0)
  standardize_posteriors(model, method = "refit")
  standardize_posteriors(model, method = "posthoc")
  standardize_posteriors(model, method = "smart")
  standardize_posteriors(model, method = "basic")

  standardize_parameters(model, method = "refit")
  standardize_parameters(model, method = "posthoc")
  standardize_parameters(model, method = "smart")
  standardize_parameters(model, method = "basic")
}
# }

Run the code above in your browser using DataLab