Skip to contents

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

Usage

compare_parameters(
  ...,
  ci = 0.95,
  effects = "fixed",
  component = "conditional",
  standardize = NULL,
  exponentiate = FALSE,
  ci_method = "wald",
  p_adjust = NULL,
  select = NULL,
  column_names = NULL,
  pretty_names = TRUE,
  keep = NULL,
  drop = NULL,
  verbose = TRUE
)

compare_models(
  ...,
  ci = 0.95,
  effects = "fixed",
  component = "conditional",
  standardize = NULL,
  exponentiate = FALSE,
  ci_method = "wald",
  p_adjust = NULL,
  select = NULL,
  column_names = NULL,
  pretty_names = TRUE,
  keep = NULL,
  drop = NULL,
  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.

ci

Confidence Interval (CI) level. Default to 0.95 (95%).

effects

Should parameters for fixed effects ("fixed"), random effects ("random"), or both ("all") be returned? Only applies to mixed models. May be abbreviated. If the calculation of random effects parameters takes too long, you may use effects = "fixed".

component

Model component for which parameters should be shown. See documentation for related model class in model_parameters().

standardize

The method used for standardizing the parameters. Can be NULL (default; no standardization), "refit" (for re-fitting the model on standardized data) or one of "basic", "posthoc", "smart", "pseudo". See 'Details' in standardize_parameters(). Importantly:

  • The "refit" method does not standardize categorical predictors (i.e. factors), 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="basic" or standardize the data with datawizard::standardize(force=TRUE) before fitting the model.

  • For mixed models, when using methods other than "refit", only the fixed effects will be standardized.

  • Robust estimation (i.e., vcov set to a value other than NULL) of standardized parameters only works when standardize="refit".

exponentiate

Logical, indicating whether or not to exponentiate the coefficients (and related confidence intervals). This is typical for logistic regression, or more generally speaking, for models with log or logit links. It is also recommended to use exponentiate = TRUE for models with log-transformed response values. 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.

ci_method

Method for computing degrees of freedom for p-values and confidence intervals (CI). See documentation for related model class in model_parameters().

p_adjust

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).

select

Determines which columns and and which layout columns are printed. There are three options for this argument:

  1. Selecting columns by name or index
    select can be a character vector (or numeric index) of column names that should be printed. There are two pre-defined options for selecting columns: select = "minimal" prints coefficients, confidence intervals and p-values, while select = "short" prints coefficients, standard errors and p-values.

  2. A string expression with layout pattern
    select is a string with "tokens" enclosed in braces. These tokens will be replaced by their associated columns, where the selected columns will be collapsed into one column. However, it is possible to create multiple columns as well. Following tokens are replaced by the related coefficients or statistics: {estimate}, {se}, {ci} (or {ci_low} and {ci_high}), {p} and {stars}. The token {ci} will be replaced by {ci_low}, {ci_high}. Furthermore, a | separates values into new cells/columns. If format = "html", a <br> inserts a line break inside a cell. See 'Examples'.

  3. A string indicating a pre-defined layout
    select can be one of the following string values, to create one of the following pre-defined column layouts:

    • "ci": Estimates and confidence intervals, no asterisks for p-values. This is equivalent to select = "{estimate} ({ci})".

    • "se": Estimates and standard errors, no asterisks for p-values. This is equivalent to select = "{estimate} ({se})".

    • "ci_p": Estimates, confidence intervals and asterisks for p-values. This is equivalent to select = "{estimate}{stars} ({ci})".

    • "se_p": Estimates, standard errors and asterisks for p-values. This is equivalent to select = "{estimate}{stars} ({se})"..

    • "ci_p2": Estimates, confidence intervals and numeric p-values, in two columns. This is equivalent to select = "{estimate} ({ci})|{p}".

    • "se_p2": Estimate, standard errors and numeric p-values, in two columns. This is equivalent to select = "{estimate} ({se})|{p}".

For model_parameters(), glue-like syntax is still experimental in the case of more complex models (like mixed models) and may not return expected results.

column_names

Character vector with strings that should be used as column headers. Must be of same length as number of models in ....

pretty_names

Can be TRUE, which will return "pretty" (i.e. more human readable) parameter names. Or "labels", in which case value and variable labels will be used as parameters names. The latter only works for "labelled" data, i.e. if the data used to fit the model had "label" and "labels" attributes. See also section Global Options to Customize Messages when Printing.

keep

Character containing a regular expression pattern that describes the parameters that should be included (for keep) or excluded (for drop) in the returned data frame. 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 keep 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.

drop

See keep.

verbose

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

# custom style
compare_parameters(lm1, lm2, select = "{estimate}{stars} ({se})")
#> Parameter            |            lm1 |             lm2
#> -------------------------------------------------------
#> (Intercept)          | 5.01*** (0.07) |  3.68*** (0.11)
#> Species (versicolor) | 0.93*** (0.10) | -1.60*** (0.19)
#> Species (virginica)  | 1.58*** (0.10) | -2.12*** (0.27)
#> Petal Length         |                |  0.90*** (0.06)
#> -------------------------------------------------------
#> Observations         |            150 |             150

# \donttest{
# custom style, in HTML
result <- compare_parameters(lm1, lm2, select = "{estimate}<br>({se})|{p}")
print_html(result)
#> <div id="btjrmikwex" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>#btjrmikwex table {
#>   font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
#>   -webkit-font-smoothing: antialiased;
#>   -moz-osx-font-smoothing: grayscale;
#> }
#> 
#> #btjrmikwex thead, #btjrmikwex tbody, #btjrmikwex tfoot, #btjrmikwex tr, #btjrmikwex td, #btjrmikwex th {
#>   border-style: none;
#> }
#> 
#> #btjrmikwex p {
#>   margin: 0;
#>   padding: 0;
#> }
#> 
#> #btjrmikwex .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   line-height: normal;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 100%;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_caption {
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#> }
#> 
#> #btjrmikwex .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #btjrmikwex .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 3px;
#>   padding-bottom: 5px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #btjrmikwex .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #btjrmikwex .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #btjrmikwex .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #btjrmikwex .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #btjrmikwex .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #btjrmikwex .gt_spanner_row {
#>   border-bottom-style: hidden;
#> }
#> 
#> #btjrmikwex .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   text-align: left;
#> }
#> 
#> #btjrmikwex .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #btjrmikwex .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #btjrmikwex .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #btjrmikwex .gt_row {
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #btjrmikwex .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #btjrmikwex .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #btjrmikwex .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #btjrmikwex .gt_row_group_first th {
#>   border-top-width: 2px;
#> }
#> 
#> #btjrmikwex .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #btjrmikwex .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #btjrmikwex .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #btjrmikwex .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_last_grand_summary_row_top {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: double;
#>   border-bottom-width: 6px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #btjrmikwex .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #btjrmikwex .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #btjrmikwex .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #btjrmikwex .gt_left {
#>   text-align: left;
#> }
#> 
#> #btjrmikwex .gt_center {
#>   text-align: center;
#> }
#> 
#> #btjrmikwex .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #btjrmikwex .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #btjrmikwex .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #btjrmikwex .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #btjrmikwex .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #btjrmikwex .gt_footnote_marks {
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#>   position: initial;
#> }
#> 
#> #btjrmikwex .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #btjrmikwex .gt_indent_1 {
#>   text-indent: 5px;
#> }
#> 
#> #btjrmikwex .gt_indent_2 {
#>   text-indent: 10px;
#> }
#> 
#> #btjrmikwex .gt_indent_3 {
#>   text-indent: 15px;
#> }
#> 
#> #btjrmikwex .gt_indent_4 {
#>   text-indent: 20px;
#> }
#> 
#> #btjrmikwex .gt_indent_5 {
#>   text-indent: 25px;
#> }
#> </style>
#>   <table class="gt_table" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
#>   <thead>
#>     
#>     <tr class="gt_col_headings gt_spanner_row">
#>       <th class="gt_col_heading gt_columns_bottom_border gt_left" rowspan="2" colspan="1" scope="col" id="Parameter">Parameter</th>
#>       <th class="gt_center gt_columns_top_border gt_column_spanner_outer" rowspan="1" colspan="2" scope="colgroup" id="lm1">
#>         <span class="gt_column_spanner">lm1</span>
#>       </th>
#>       <th class="gt_center gt_columns_top_border gt_column_spanner_outer" rowspan="1" colspan="2" scope="colgroup" id="lm2">
#>         <span class="gt_column_spanner">lm2</span>
#>       </th>
#>     </tr>
#>     <tr class="gt_col_headings">
#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col" id="Estimate(SE)">Estimate(SE)</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col" id="p">p</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col" id="Estimate(SE)">Estimate(SE)</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col" id="p">p</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr><td headers="Parameter" class="gt_row gt_left" style="border-right-width: 1px; border-right-style: solid; border-right-color: #d3d3d3;"><div class='gt_from_md'><p>(Intercept)</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>5.01<br>(0.07)</p>
#> </div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>3.68<br>(0.11)</p>
#> </div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td></tr>
#>     <tr><td headers="Parameter" class="gt_row gt_left" style="border-right-width: 1px; border-right-style: solid; border-right-color: #d3d3d3;"><div class='gt_from_md'><p>Species (versicolor)</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>0.93<br>(0.10)</p>
#> </div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>-1.60<br>(0.19)</p>
#> </div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td></tr>
#>     <tr><td headers="Parameter" class="gt_row gt_left" style="border-right-width: 1px; border-right-style: solid; border-right-color: #d3d3d3;"><div class='gt_from_md'><p>Species (virginica)</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>1.58<br>(0.10)</p>
#> </div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>-2.12<br>(0.27)</p>
#> </div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td></tr>
#>     <tr><td headers="Parameter" class="gt_row gt_left" style="border-right-width: 1px; border-right-style: solid; border-right-color: #d3d3d3;"><div class='gt_from_md'><p>Petal Length</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>0.90<br>(0.06)</p>
#> </div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>&lt;0.001</p>
#> </div></td></tr>
#>     <tr><td headers="Parameter" class="gt_row gt_left"><div class='gt_from_md'></div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'></div></td></tr>
#>     <tr><td headers="Parameter" class="gt_row gt_left"><div class='gt_from_md'><p>Observations</p>
#> </div></td>
#> <td headers="Estimate(SE) (lm1)" class="gt_row gt_center"><div class='gt_from_md'><p>150</p>
#> </div></td>
#> <td headers="p (lm1)" class="gt_row gt_center"><div class='gt_from_md'></div></td>
#> <td headers="Estimate(SE) (lm2)" class="gt_row gt_center"><div class='gt_from_md'><p>150</p>
#> </div></td>
#> <td headers="p (lm2)" class="gt_row gt_center"><div class='gt_from_md'></div></td></tr>
#>   </tbody>
#>   <tfoot class="gt_sourcenotes">
#>     <tr>
#>       <td class="gt_sourcenote" colspan="5"></td>
#>     </tr>
#>   </tfoot>
#>   
#> </table>
#> </div>
# }

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
# \donttest{
# exponentiate coefficients, but not for lm
compare_parameters(m1, m2, exponentiate = "nongaussian")
#> Parameter    |                   m1 |                         m2
#> ----------------------------------------------------------------
#> (Intercept)  | 37.29 (33.45, 41.12) | 40911.34 (11.59, 1.44e+08)
#> wt           | -5.34 (-6.49, -4.20) |     8.17 ( 0.39,   169.06)
#> cyl          |                      |     0.05 ( 0.00,     0.80)
#> ----------------------------------------------------------------
#> Observations |                   32 |                         32

# change column names
compare_parameters("linear model" = m1, "logistic reg." = m2)
#> Parameter    |         linear model |        logistic reg.
#> ----------------------------------------------------------
#> (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
compare_parameters(m1, m2, column_names = c("linear model", "logistic reg."))
#> Parameter    |         linear model |        logistic reg.
#> ----------------------------------------------------------
#> (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

# or as list
compare_parameters(list(m1, m2))
#> Parameter    |              Model 1 |              Model 2
#> ----------------------------------------------------------
#> (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
compare_parameters(list("linear model" = m1, "logistic reg." = m2))
#> Parameter    |         linear model |        logistic reg.
#> ----------------------------------------------------------
#> (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
# }