Compute and extract model parameters of multiple regression models. See model_parameters() for further details.

compare_parameters(
...,
ci = 0.95,
effects = "fixed",
component = "conditional",
standardize = NULL,
exponentiate = FALSE,
df_method = "wald",
style = NULL,
column_names = NULL,
keep = NULL,
drop = NULL,
parameters = keep,
verbose = TRUE
)

compare_models(
...,
ci = 0.95,
effects = "fixed",
component = "conditional",
standardize = NULL,
exponentiate = FALSE,
df_method = "wald",
style = NULL,
column_names = NULL,
keep = NULL,
drop = NULL,
parameters = keep,
verbose = TRUE
)

## Arguments

... One or more regression model objects, or objects returned by model_parameters(). Regression models may be of different model types. Model objects may be passed comma separated, or as a list. If model objects are passed with names or the list has named elements, these names will be used as column names. Confidence Interval (CI) level. Default to 0.95 (95%). Should parameters for fixed effects ("fixed"), random effects ("random"), or both ("all") be returned? Only applies to mixed models. May be abbreviated. Model component for which parameters should be shown. See documentation for related model class in model_parameters(). The method used for standardizing the parameters. Can be "refit", "posthoc", "smart", "basic", "pseudo" or NULL (default) for no standardization. See 'Details' in effectsize::standardize_parameters(). Important: Categorical predictors (i.e. factors) are never standardized by default, which may be a different behaviour compared to other R packages or other software packages (like SPSS). If standardizing categorical predictors is desired, either use standardize="basic" to mimic behaviour of SPSS or packages such as lm.beta, or standardize the data with effectsize::standardize(force=TRUE) before fitting the model. Robust estimation (i.e. robust=TRUE) of standardized parameters only works when standardize="refit". Logical, indicating whether or not to exponentiate the the coefficients (and related confidence intervals). This is typical for logistic regression, or more generally speaking, for models with log or logit links. Note: Delta-method standard errors are also computed (by multiplying the standard errors by the transformed coefficients). This is to mimic behaviour of other software packages, such as Stata, but these standard errors poorly estimate uncertainty for the transformed coefficient. The transformed confidence interval more clearly captures this uncertainty. For compare_parameters(), exponentiate = "nongaussian" will only exponentiate coefficients from non-Gaussian families. Method for computing degrees of freedom for p values, standard errors and confidence intervals (CI). See documentation for related model class in model_parameters(). Character vector, if not NULL, indicates the method to adjust p-values. See stats::p.adjust() for details. Further possible adjustment methods are "tukey", "scheffe", "sidak" and "none" to explicitly disable adjustment for emmGrid objects (from emmeans). String, indicating which style of output is requested. Following templates are possible: "ci": Estimate and confidence intervals, no asterisks for p-values. "se": Estimate and standard errors, no asterisks for p-values. "ci_p": Estimate, confidence intervals and asterisks for p-values. "se_p": Estimate, standard errors and asterisks for p-values. "ci_p2": Estimate, confidence intervals and numeric p-values, in two columns. "se_p2": Estimate, standard errors and numeric p-values, in two columns. Character vector with strings that should be used as column headers. Must be of same length as number of models in .... Character containing a regular expression pattern that describes the parameters that should be included in the returned data frame (for keep), resp. parameters to exclude (drop). keep may also be a named list of regular expressions. All non-matching parameters will be removed from the output. If keep is a character vector, every parameter name in the "Parameter" column that matches the regular expression in parameters will be selected from the returned data frame (and vice versa, all parameter names matching drop will be excluded). Furthermore, if keep has more than one element, these will be merged with an OR operator into a regular expression pattern like this: "(one|two|three)". If keep is a named list of regular expression patterns, the names of the list-element should equal the column name where selection should be applied. This is useful for model objects where model_parameters() returns multiple columns with parameter components, like in model_parameters.lavaan(). Note that the regular expression pattern should match the parameter names as they are stored in the returned data frame, which can be different from how they are printed. Inspect the $Parameter column of the parameters table to get the exact parameter names. Character containing a regular expression pattern that describes the parameters that should be included in the returned data frame (for keep), resp. parameters to exclude (drop). keep may also be a named list of regular expressions. All non-matching parameters will be removed from the output. If keep is a character vector, every parameter name in the "Parameter" column that matches the regular expression in parameters will be selected from the returned data frame (and vice versa, all parameter names matching drop will be excluded). Furthermore, if keep has more than one element, these will be merged with an OR operator into a regular expression pattern like this: "(one|two|three)". If keep is a named list of regular expression patterns, the names of the list-element should equal the column name where selection should be applied. This is useful for model objects where model_parameters() returns multiple columns with parameter components, like in model_parameters.lavaan(). Note that the regular expression pattern should match the parameter names as they are stored in the returned data frame, which can be different from how they are printed. Inspect the $Parameter column of the parameters table to get the exact parameter names. Deprecated, alias for keep. Toggle warnings and messages.

## Value

A data frame of indices related to the model's parameters.

## Details

This function is in an early stage and does not yet cope with more complex models, and probably does not yet properly render all model components. It should also be noted that when including models with interaction terms, not only do the values of the parameters change, but so does their meaning (from main effects, to simple slopes), thereby making such comparisons hard. Therefore, you should not use this function to compare models with interaction terms with models without interaction terms.

## Examples

data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
compare_parameters(lm1, lm2)
#> Parameter            |               lm1 |                  lm2
#> ---------------------------------------------------------------
#> (Intercept)          | 5.01 (4.86, 5.15) |  3.68 ( 3.47,  3.89)
#> Species (versicolor) | 0.93 (0.73, 1.13) | -1.60 (-1.98, -1.22)
#> Species (virginica)  | 1.58 (1.38, 1.79) | -2.12 (-2.66, -1.58)
#> Petal Length         |                   |  0.90 ( 0.78,  1.03)
#> ---------------------------------------------------------------
#> Observations         |               150 |                  150

data(mtcars)
m1 <- lm(mpg ~ wt, data = mtcars)
m2 <- glm(vs ~ wt + cyl, data = mtcars, family = "binomial")
compare_parameters(m1, m2)
#> Parameter    |                   m1 |                   m2
#> ----------------------------------------------------------
#> (Intercept)  | 37.29 (33.45, 41.12) | 10.62 ( 2.45, 18.79)
#> wt           | -5.34 (-6.49, -4.20) |  2.10 (-0.93,  5.13)
#> cyl          |                      | -2.93 (-5.63, -0.23)
#> ----------------------------------------------------------
#> Observations |                   32 |                   32
if (FALSE) {
# exponentiate coefficients, but not for lm
compare_parameters(m1, m2, exponentiate = "nongaussian")

# change column names
compare_parameters("linear model" = m1, "logistic reg." = m2)
compare_parameters(m1, m2, column_names = c("linear model", "logistic reg."))

# or as list
compare_parameters(list(m1, m2))
compare_parameters(list("linear model" = m1, "logistic reg." = m2))
}