I have mostly been using stargazer for comparing linear model summaries but there are few other packages that also provide this feature.
One in particular is the library(memisc). memisc was designed for survey data sets but it can handle other kinds, too.
Below, I’ve put togehter an example that utilzes mtcars data with memisc to provide a comparison of stats between linear models (lms).
First we load the library, and create the linear models:
library(memisc) # mtcars
lm0 <- lm(hp ~ wt, mtcars)
lm1 <- lm(qsec ~ hp, mtcars)
lm2 <- lm(qsec ~ wt, mtcars)
Next, we use mtable to list the models to compare. Included is the argument summary.stats that can be populated with a charcater vector with the names of the summary stats to report:
mtable123 <- mtable('Model 1' = lm0,
'Model 2' = lm1,
'Model 3' = lm2,
summary.stats = c('R-squared','F','p','N'))
And then we print out the table:
mtable123
##
## Calls:
## Model 1: lm(formula = hp ~ wt, data = mtcars)
## Model 2: lm(formula = qsec ~ hp, data = mtcars)
## Model 3: lm(formula = qsec ~ wt, data = mtcars)
##
## =================================================
## Model 1 Model 2 Model 3
## ----------- ---------- ----------
## hp qsec qsec
## -------------------------------------------------
## (Intercept) -1.821 20.556*** 18.875***
## (32.325) (0.542) (1.103)
## wt 46.160*** -0.319
## (9.625) (0.328)
## hp -0.018***
## (0.003)
## -------------------------------------------------
## R-squared 0.434 0.502 0.031
## F 22.999 30.190 0.945
## p 0.000 0.000 0.339
## N 32 32 32
## =================================================
You can also use array-semantics to access portions of the data which is a nice touch:
mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2,
summary.stats=c("sigma","R-squared","F","p","N"))
mtable123[c("wt","hp"),
c("Model 2","Model 3")]
##
## Calls:
## Model 2: lm(formula = qsec ~ hp, data = mtcars)
## Model 3: lm(formula = qsec ~ wt, data = mtcars)
##
## =================================
## Model 2 Model 3
## ---------------------------------
## wt -0.319
## (0.328)
## hp -0.018***
## (0.003)
## ---------------------------------
## sigma 1.282 1.789
## R-squared 0.502 0.031
## F 30.190 0.945
## p 0.000 0.339
## N 32 32
## =================================