smargins
is a package that aids in calculating expected values for models of various kinds. There are many packages like it (e.g., coreSim, effects, lsmeans, margins, rms and Zelig) but this one is mine.
The main functions provided by this package are: * smargins()
calculates average marginal effects * scompare()
performs pairwise comparisons of the average marginal effects produced by smargins
.
Some examples are available at (https://izahn.github.io/smargins/)
The primary purpose of this package is to serve as a test bed for exploring interfaces and designs for R packages that facilitate calculating quantities of interest. Several such packages exist, each with their own pros and cons. This package is serves as a play ground where we can try different approaches in order to see if we can find one with more pros and fewer cons than existing solutions.
smargins
is not on CRAN (and may never be). You can install it from github using the devtools
package:
## install.packages("devtools")
devtools::install_github("izahn/smargins")
library(smargins)
mtc <- transform(mtcars, gear = factor(gear))
m.sm <- smargins(lm(mpg ~ gear, data = mtc),
gear = levels(gear))
summary(m.sm)
#> gear mean sd median lower_2.5 upper_97.5
#> 1 3 16.09981 1.223575 16.11015 13.65396 18.48544
#> 2 4 24.53154 1.357174 24.51836 21.87141 27.22361
#> 3 5 21.39918 2.102933 21.36829 17.30387 25.44792
summary(scompare(m.sm, "gear"))
#> gear mean sd median lower_2.5 upper_97.5
#> 1 3 vs 4 -8.431731 1.825132 -8.406538 -12.067044 -4.933481
#> 2 3 vs 5 -5.299365 2.431523 -5.267398 -10.083198 -0.573709
#> 3 4 vs 5 3.132366 2.494932 3.190112 -1.804889 7.976909