knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
library(outreg)
Create Regression Tables for Publication
fitlist <- list(lm(mpg ~ cyl, data = mtcars), lm(mpg ~ cyl + wt + hp, data = mtcars), lm(mpg ~ cyl + wt + hp + drat, data = mtcars)) knitr::kable(outreg(fitlist))
outreg
summarizes regression outcomes into a coefficient table in data.frame
format. Currently, outreg
supports the following model fit objects:
lm
: linear regressionglm
: logistic regression, poisson regression, etcsurvreg
: survival regression, tobit regression, etcivreg
: instrument variable regressionoutreg
takes a list of model fit objects as the main input, and returns a
data.frame
object where a model is represented in a column.
library(outreg) fitlist <- list(lm(mpg ~ cyl, data = mtcars), lm(mpg ~ cyl + wt + hp, data = mtcars), lm(mpg ~ cyl + wt + hp + drat, data = mtcars)) outreg(fitlist)
Install from the CRAN repository.
install.packages('outreg')
Or the recent version from the github repository.
devtools::install_github('kota7/outreg')
library(outreg) fitlist <- list(lm(mpg ~ cyl, data = mtcars), lm(mpg ~ cyl + wt + hp, data = mtcars), lm(mpg ~ cyl + wt + hp + drat, data = mtcars)) outreg(fitlist)
If regression list is named, the names are used as column names.
outreg(setNames(fitlist, c('small', 'medium', 'large')))
You may choose statistics to display and which stats to put "stars" on, and significance level.
outreg(fitlist, pv = TRUE, se = FALSE, starred = 'pv', alpha = c(0.05, 0.01, 0.001))
outreg(fitlist, constlast = TRUE)
outreg(fitlist, robust = TRUE)
counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) fitlist2 <- list(glm(counts ~ outcome, family = poisson()), glm(counts ~ outcome + treatment, family = poisson())) outreg(fitlist2)
fitlist3 <- list(glm(cbind(ncases, ncontrols) ~ agegp, data = esoph, family = binomial()), glm(cbind(ncases, ncontrols) ~ agegp + tobgp + alcgp, data = esoph, family = binomial()), glm(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp, data = esoph, family = binomial())) outreg(fitlist3)
library(survival) fitlist4 <- list(survreg(Surv(time, status) ~ ph.ecog + age, data = lung), survreg(Surv(time, status) ~ ph.ecog + age + strata(sex), data = lung)) outreg(fitlist4)
fitlist5 <- list(survreg(Surv(durable, durable>0, type='left') ~ 1, data=tobin, dist='gaussian'), survreg(Surv(durable, durable>0, type='left') ~ age + quant, data=tobin, dist='gaussian')) outreg(fitlist5)
library(AER) data("CigarettesSW", package = "AER") CigarettesSW$rprice <- with(CigarettesSW, price/cpi) CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi) CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi) fitlist6 <- list(OLS = lm(log(packs) ~ log(rprice) + log(rincome), data = CigarettesSW, subset = year == "1995"), IV1 = ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi), data = CigarettesSW, subset = year == "1995"), IV2 = ivreg(log(packs) ~ log(rprice) + log(rincome) | log(population) + tdiff + I(tax/cpi), data = CigarettesSW, subset = year == "1995")) outreg(fitlist6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.