Title: | Create Publication-Ready Regression Tables with Panels |
---|---|
Description: | Create an automated regression table that is well-suited for models that are estimated with multiple dependent variables. 'panelsummary' extends 'modelsummary' (Arel-Bundock, V. (2022) <doi:10.18637/jss.v103.i01>) by allowing regression tables to be split into multiple sections with a simple function call. Utilize familiar arguments such as fmt, estimate, statistic, vcov, conf_level, stars, coef_map, coef_omit, coef_rename, gof_map, and gof_omit from 'modelsummary' to clean the table, and additionally, add a row for the mean of the dependent variable without external manipulation. |
Authors: | Michael Topper [aut, cre], Vincent Arel-Bundock [cph] (Some documentation is inherited from 'modelsummary') |
Maintainer: | Michael Topper <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.2.1 |
Built: | 2025-02-10 05:45:48 UTC |
Source: | https://github.com/michaeltopper1/panelsummary |
'clean_raw' Passes a panelsummary::panelsummary_raw dataframe that has (or has not) been edited further into kableExtra::kbl() with default settings that look publication-ready. This includes changing the column names and fixing the alignment.
clean_raw( data.frame, alignment = NULL, colnames = NULL, format = NULL, caption = NULL, pretty_num = FALSE )
clean_raw( data.frame, alignment = NULL, colnames = NULL, format = NULL, caption = NULL, pretty_num = FALSE )
data.frame |
The data.frame (or tibble) from panelsummary::panelsummary_raw() that has been manipulated. |
alignment |
A character string. By default, it is set to left adjusting the first column, and centering the rest of the columns. For example, a model with three columns will have adjustment of "lcc". |
colnames |
An optional vector of strings. The vector of strings should have the same length as the number columns of the table. * 'NULL' (the default): colnames are defaulted to a whitespace, followed by (1), (2), ....etc. |
format |
A character string. Possible values are latex, html, pipe (Pandoc's pipe tables), simple (Pandoc's simple tables), and rst. The value of this argument will be automatically determined if the function is called within a knitr document. The format value can also be set in the global option knitr.table.format. If format is a function, it must return a character string. |
caption |
A string. The table caption. |
pretty_num |
A logical. If TRUE, then numbers over 999 have a comma printing format. |
A raw data frame that is ready for further manipulation.
## Cleaning a panelsummary_raw dataframe with clean_raw ols_1 <- lm(mpg ~ hp + cyl, data = mtcars) panelsummary_raw(ols_1, ols_1) |> clean_raw()
## Cleaning a panelsummary_raw dataframe with clean_raw ols_1 <- lm(mpg ~ hp + cyl, data = mtcars) panelsummary_raw(ols_1, ols_1) |> clean_raw()
'connect_means' connects the means to the modelsummary dataframe.
connect_means(panel_df, means)
connect_means(panel_df, means)
panel_df |
The modelsummary dataframe supplied from modelsummary::modelsummary(x, output = "data.frame") |
means |
The list of named vectors of means which correspond to each model. |
A data.frame with the attached means.
all models supported by panelsummary
models_supported()
models_supported()
a list of all modeltypes supported by panelsummary
models_supported()
models_supported()
‘panelsummary' Creates a beautiful and customizable regression table with panels. This function is best used to summarize multiple dependent variables that are passed through the same regression models. This function returns a kableExtra object which can then be edited using kableExtra’s suite of functions.
panelsummary( ..., panel_labels = NULL, mean_dependent = FALSE, colnames = NULL, caption = NULL, format = NULL, pretty_num = FALSE, collapse_fe = FALSE, bold = FALSE, italic = FALSE, hline_after = FALSE, hline_before_fe = TRUE, fmt = 3, estimate = "estimate", statistic = "std.error", vcov = NULL, conf_level = 0.95, stars = FALSE, coef_map = NULL, coef_omit = NULL, coef_rename = NULL, gof_map = NULL, gof_omit = NULL )
panelsummary( ..., panel_labels = NULL, mean_dependent = FALSE, colnames = NULL, caption = NULL, format = NULL, pretty_num = FALSE, collapse_fe = FALSE, bold = FALSE, italic = FALSE, hline_after = FALSE, hline_before_fe = TRUE, fmt = 3, estimate = "estimate", statistic = "std.error", vcov = NULL, conf_level = 0.95, stars = FALSE, coef_map = NULL, coef_omit = NULL, coef_rename = NULL, gof_map = NULL, gof_omit = NULL )
... |
A regression model or models (see panelsummary::models_supported for classes that are supported). * The regression model can be a list of models or a singular object. * If a list is passed in, one column for each list is created. Each argument will correspond to a panel. * If only one object is passed in, there will be no panels and the output will be similar to evaluating modelsummary::modelsummary() followed by kableExtra::kbl() |
panel_labels |
A character vector. How to label each panel in the table. * 'NULL' (the default): the panels will be labeled "Panel A:", "Panel B:",...etc. |
mean_dependent |
A boolean. For use with fixest objects only. * 'FALSE' (the default): the mean of the dependent variable will not be shown in the resulting table. * 'TRUE': the mean of the dependent variable will be shown in the resulting table. |
colnames |
An optional vector of strings. The vector of strings should have the same length as the number columns of the table. * 'NULL' (the default): colnames are defaulted to a whitespace, followed by (1), (2), ....etc. |
caption |
A string. The table caption. |
format |
A character string. Possible values are latex, html, pipe (Pandoc's pipe tables), simple (Pandoc's simple tables), and rst. The value of this argument will be automatically determined if the function is called within a knitr document. The format value can also be set in the global option knitr.table.format. If format is a function, it must return a character string. |
pretty_num |
A logical. If TRUE, then numbers over 999 have a comma printing format. |
collapse_fe |
A boolean. For use with fixest objects only. Determines whether fixed effects should only be included in the bottom of the table. This is suited for when each panel has the same models with the same fixed effects. * 'FALSE' (the default): fixed effects are shown in each panel. * 'TRUE': fixed effects are shown only at the bottom of the final panel, separated by a horizontal line (see hline_before_fe) |
bold |
A boolean. Determines whether the panel names should be in bold font. * 'FALSE' (the default): the panel names are not in bold. * 'TRUE': the panel names are bolded |
italic |
A boolean. Determines whether the panel names should be in italics. * 'FALSE' (the default): the panel names are not in italics. * 'TRUE': the panel names will be in italics. |
hline_after |
A boolean. Adds a horizontal line after the panel labels. * 'FALSE' (the default): there is not horizonal line after the panel labels. * 'TRUE': a horizontal line will appear after the panel labels. |
hline_before_fe |
A boolean. To be used only when collapse_fe = TRUE, and hence with fixest objects only. Adds a horizontal line before the fixed effects portion of the table. |
fmt |
how to format numeric values: integer, user-supplied function, or
|
estimate |
a single string or a character vector of length equal to the
number of models. Valid entries include any column name of
the data.frame produced by
|
statistic |
vector of strings or
|
vcov |
robust standard errors and other manual statistics. The
|
conf_level |
numeric value between 0 and 1. confidence level to use for
confidence intervals. Setting this argument to |
stars |
to indicate statistical significance
|
coef_map |
character vector. Subset, rename, and reorder coefficients.
Coefficients omitted from this vector are omitted from the table. The order
of the vector determines the order of the table. |
coef_omit |
integer vector or regular expression to identify which coefficients to omit (or keep) from the table. Positive integers determine which coefficients to omit. Negative integers determine which coefficients to keep. A regular expression can be used to omit coefficients, and perl-compatible "negative lookaheads" can be used to specify which coefficients to keep in the table. Examples:
|
coef_rename |
logical, named or unnamed character vector, or function
|
gof_map |
rename, reorder, and omit goodness-of-fit statistics and other model information. This argument accepts 4 types of values:
|
gof_omit |
string regular expression (perl-compatible) used to determine which statistics to omit from the bottom section of the table. A "negative lookahead" can be used to specify which statistics to keep in the table. Examples:
|
A kableExtra object that is instantly customizable by kableExtra's suite of functions.
# Panelsummary with lm ------------------------- reg_1 <- lm(mpg ~ hp + cyl, data = mtcars) reg_2 <- lm(disp ~ hp + cyl, data = mtcars) panelsummary(reg_1, reg_2, panel_labels = c("Panel A: MPG", "Panel B: Displacement")) # Panelsummary with fixest ------------------------- ## Not run: ols_1 <- mtcars |> fixest::feols(mpg ~ cyl | gear + carb, cluster = ~hp, nthreads = 2) panelsummary(ols_1, ols_1, mean_dependent = TRUE, panel_labels = c("Panel A:MPG", "Panel B: DISP"), caption = "The effect of cyl on MPG and DISP", italic = TRUE, stars = TRUE) ## Collapsing fixed effects (fixest-only)---------------- panelsummary(ols_1, ols_1, mean_dependent = TRUE, collapse_fe = TRUE, panel_labels = c("Panel A: MPG", "Panel B: DISP"), caption = "The effect of cyl on MPG and DISP", italic = TRUE, stars = TRUE) ## Including multiple models------------------ panelsummary(list(ols_1, ols_1, ols_1), ols_1, panel_labels = c("Panel A: MPG", "Panel B: DISP"), caption = "Multiple models", stars = TRUE) ## End(Not run)
# Panelsummary with lm ------------------------- reg_1 <- lm(mpg ~ hp + cyl, data = mtcars) reg_2 <- lm(disp ~ hp + cyl, data = mtcars) panelsummary(reg_1, reg_2, panel_labels = c("Panel A: MPG", "Panel B: Displacement")) # Panelsummary with fixest ------------------------- ## Not run: ols_1 <- mtcars |> fixest::feols(mpg ~ cyl | gear + carb, cluster = ~hp, nthreads = 2) panelsummary(ols_1, ols_1, mean_dependent = TRUE, panel_labels = c("Panel A:MPG", "Panel B: DISP"), caption = "The effect of cyl on MPG and DISP", italic = TRUE, stars = TRUE) ## Collapsing fixed effects (fixest-only)---------------- panelsummary(ols_1, ols_1, mean_dependent = TRUE, collapse_fe = TRUE, panel_labels = c("Panel A: MPG", "Panel B: DISP"), caption = "The effect of cyl on MPG and DISP", italic = TRUE, stars = TRUE) ## Including multiple models------------------ panelsummary(list(ols_1, ols_1, ols_1), ols_1, panel_labels = c("Panel A: MPG", "Panel B: DISP"), caption = "Multiple models", stars = TRUE) ## End(Not run)
'panelsummary_raw' Creates a data.frame for further editing. The data.frame can be directly passed into kableExtra::kbl(), or alternatively, passed into panelsummary::clean_raw() to get typical defaults from kableExtra::kbl().
panelsummary_raw( ..., mean_dependent = FALSE, colnames = NULL, caption = NULL, format = NULL, fmt = 3, estimate = "estimate", statistic = "std.error", vcov = NULL, conf_level = 0.95, stars = FALSE, coef_map = NULL, coef_omit = NULL, coef_rename = NULL, gof_map = NULL, gof_omit = NULL )
panelsummary_raw( ..., mean_dependent = FALSE, colnames = NULL, caption = NULL, format = NULL, fmt = 3, estimate = "estimate", statistic = "std.error", vcov = NULL, conf_level = 0.95, stars = FALSE, coef_map = NULL, coef_omit = NULL, coef_rename = NULL, gof_map = NULL, gof_omit = NULL )
... |
all other arguments are passed through to three functions. See the documentation of these functions for lists of available arguments.
|
mean_dependent |
A boolean. For use with fixest objects only. * 'FALSE' (the default): the mean of the dependent variable will not be shown in the resulting table. * 'TRUE': the mean of the dependent variable will be shown in the resulting table. |
colnames |
An optional vector of strings. The vector of strings should have the same length as the number columns of the table. * 'NULL' (the default): colnames are defaulted to a whitespace, followed by (1), (2), ....etc. |
caption |
A string. The table caption. |
format |
A character string. Possible values are latex, html, pipe (Pandoc's pipe tables), simple (Pandoc's simple tables), and rst. The value of this argument will be automatically determined if the function is called within a knitr document. The format value can also be set in the global option knitr.table.format. If format is a function, it must return a character string. |
fmt |
how to format numeric values: integer, user-supplied function, or
|
estimate |
a single string or a character vector of length equal to the
number of models. Valid entries include any column name of
the data.frame produced by
|
statistic |
vector of strings or
|
vcov |
robust standard errors and other manual statistics. The
|
conf_level |
numeric value between 0 and 1. confidence level to use for
confidence intervals. Setting this argument to |
stars |
to indicate statistical significance
|
coef_map |
character vector. Subset, rename, and reorder coefficients.
Coefficients omitted from this vector are omitted from the table. The order
of the vector determines the order of the table. |
coef_omit |
integer vector or regular expression to identify which coefficients to omit (or keep) from the table. Positive integers determine which coefficients to omit. Negative integers determine which coefficients to keep. A regular expression can be used to omit coefficients, and perl-compatible "negative lookaheads" can be used to specify which coefficients to keep in the table. Examples:
|
coef_rename |
logical, named or unnamed character vector, or function
|
gof_map |
rename, reorder, and omit goodness-of-fit statistics and other model information. This argument accepts 4 types of values:
|
gof_omit |
string regular expression (perl-compatible) used to determine which statistics to omit from the bottom section of the table. A "negative lookahead" can be used to specify which statistics to keep in the table. Examples:
|
A kableExtra object that is instantly customizable by kableExtra's suite of functions.
## Using panelsummary_raw ols_1 <- lm(mpg ~ hp + cyl, data = mtcars) panelsummary_raw(ols_1, ols_1) ## Including multiple models------------------ panelsummary_raw(list(ols_1, ols_1, ols_1), ols_1, caption = "Multiple models", stars = TRUE)
## Using panelsummary_raw ols_1 <- lm(mpg ~ hp + cyl, data = mtcars) panelsummary_raw(ols_1, ols_1) ## Including multiple models------------------ panelsummary_raw(list(ols_1, ols_1, ols_1), ols_1, caption = "Multiple models", stars = TRUE)