knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of stargate package is to simplify production of formatted tables that hold regression analysis results from several models side-by-side.
For many years, we have used stargazer package for this purpose. stargazer is great and every applied econometrician has to be thankful to Marek Hlaváč for kindly providing it. However, this package is implemented as one monolithic function, which has two drawbacks:
This package is an attempt to rewrite stargazer remove these obstacles. To pay homage to the original package, it is named similarly: stargate.
kbl()
from kableExtra.However, this package is just in a rudimentary state---it is more a proof of the concept and a playground than a real thing. It is here to raise some feedback, comments, and wishes. If used, it must be used with extreme care:
You have been warned. Enjoy!
At the present time, there is only the development version. It is available from GitHub with:
# install.packages("devtools") devtools::install_github("mkvasnicka/stargate")
This is a basic example which shows you how to use stargate. Load the necessary packages first:
library(stargate) library(tibble) library(kableExtra)
Estimates some models (simulated here):
n <- 1e3 df <- tibble( x1 = rnorm(n), x2 = rnorm(n), x3 = rnorm(n), e = rnorm(n), y = x1 - 2 * x2 + 3 * x3 + e ) m1 <- lm(y ~ x1 + x2, df) m2 <- lm(y ~ x1 + x2 + x3, df) m3 <- lm(y ~ x1 + x2 * x3, df)
Convert the estimates to their stargate representation: one model with sg_model()
, many models with sg_table()
:
sm1 <- sg_model(m1) stab <- sg_table(sm1, m2, m3)
You can also convert at least one estimate to a stargate model or table and then add other using the plus (+
) sign:
stab <- sm1 + m2 + m3
Transform the model table to your liking:
stab <- stab |> sg_remove(coefs = "Interc", regex = TRUE) |> sg_remove(stats = c("r.squared", "logLik", "nobs"), keep = TRUE)
Rename coefficients and statistics as you like:
stab <- stab |> sg_rename(coefs = c("a" = "x", " x " = ":"), regex = TRUE) |> sg_rename(stats = c("R2" = "r.squared", "log Lik." = "logLik"))
Format the table:
sftab <- stab |> sg_format()
Present:
sftab <- sftab |> sg_present()
Print the table:
kbl(sftab, format = "pipe") |> kable_classic()
Or do all that at once:
sg_table(sm1, m2, m3) |> sg_remove(coefs = "Interc", regex = TRUE) |> sg_remove(stats = c("r.squared", "logLik", "nobs"), keep = TRUE) |> sg_rename(coefs = c("a" = "x", " x " = ":"), regex = TRUE) |> sg_rename(stats = c("R2" = "r.squared", "log Lik." = "logLik", "num. of. obs." = "nobs")) |> sg_format(style = c("{estimate}", "({std.error})"), format = list(nsmall = 3)) |> sg_present() |> kbl(format = "pipe") |> kable_classic()
print()
methods for all stargate objects.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.