# If you don't have devtools already
install.packages("devtools")
# You can install easytable from GitHub
::install_github("alhdzsz/easytable") devtools
easytable R package
Create MS word friendly regression tables
Introduction to easytable: Creating Beautiful Tables for Model Summaries
Overview
easytable
is an R package designed to simplify the process of creating visually appealing and informative tables for summarizing model results. Whether you’re working with linear regression, logistic regression, or any other type of model, easytable
provides a user-friendly interface to generate tables with ease.
In this tutorial, we’ll walk through the basic usage of easytable
using a sample dataset and a few example models.
Installation
You can install easytable
from GitHub using the devtools
package:
Once installed, you can load the package into your R session:
library(easytable)
Model Input
The easytable
package has one function (easytable()
). The main input to use this function is a named list of statistical objects.
data(mtcars)
$cyl <- as.factor(mtcars$cyl)
mtcars
# Fit models
<- lm(am ~ cyl + hp + wt, data = mtcars)
m1 <- glm(am ~ cyl + hp + wt, data = mtcars, family = "binomial")
m2 <- glm(am ~ wt + disp, data = mtcars, family = binomial(link = "probit"))
m3
# Create a list of models
<- list(
model_list LPM = m1,
Logit = m2,
Probit = m3
)
Models are tidied using the broom::tidy()
function and thus must be statistical objects.
Example Usage
Let’s dive into an example to see how easytable
works. We’ll use the famous mtcars dataset and fit three different models to it: a linear probability model (LPM), a logistic regression, and a probit regression.
# Generate the table
easy_table(model_list)
term | LPM | Logit | Probit |
---|---|---|---|
(Intercept) | 1.18 *** | 18.09 * | 8.64 *** |
cyl6 | -0.18 | 2.77 | |
cyl8 | -0.57 * | -8.39 | |
hp | 0 *** | 0.1 | |
wt | -0.38 *** | -10.68 ** | -3.34 *** |
disp | 0.01 | ||
N | 32 | 32 | 32 |
R sq. | 0.61 | ||
Adj. R sq. | 0.56 | ||
AIC | 17.26 | 23.85 | |
Significance: ***p < .01; **p < .05; *p < .1 |
Other options within the function include: a) highlighting statistically significant results, b) adding average marginal effects coefficients, c) adding robust standard errors, d) printing a .csv
file of the table, and e) omitting control variables from the output.
# Generate the table
easy_table(model_list,
highlight = TRUE,
csv = "model_summaries", # Export as CSV
control.var = c("cyl", "disp"), # Control variables
margins = TRUE, # Include row/column margins
robust.se = TRUE # Calculate robust standard errors
)
term | LPM | Logit | Probit |
---|---|---|---|
hp | 0 *** | 0 * | |
wt | -0.38 *** | -0.34 *** | -0.52 *** |
disp | Y | ||
cyl | Y | Y | |
N | 32 | 32 | 32 |
R sq. | 0.61 | ||
Adj. R sq. | 0.56 | ||
AIC | 17.26 | 23.85 | |
Significance: ***p < .01; **p < .05; *p < .1 | |||
Note: Marginal Effects and Robust Standard Errors |
With easytable
, creating informative model summaries in R has never been easier. Whether you’re conducting data analysis, writing research papers, or preparing presentations, easytable
empowers you to generate elegant and insightful tables with just a few lines of code.