If you are only interested in obtaining the marginal effects (without corresponding variances or the overhead of creating a "margins" object), you can call `marginal_effects(x)` directly. Furthermore, the `dydx()` function enables the calculation of the marginal effect of a single named variable:
This functionality removes the need to modify data before performing such calculations, which can be quite unwieldy when many specifications are desired.
@@ -212,10 +199,6 @@ summary(margins(mod2, data = subset(margex, sex == 1)))


In addition to the estimation procedures and `plot()` generic, **margins** offers several plotting methods for model objects. First, there is a new generic `cplot()` that displays predictions or marginal effects (from an "lm" or "glm" model) of a variable conditional across values of third variable (or itself). For example, here is a graph of predicted probabilities from a logit model:
@@ -260,31 +240,7 @@ mod4 <- glm(am ~ wt*drat, data = mtcars, family = binomial)
cplot(mod4, x="wt", se.type="shade")
```
```
## xvals yvals upper lower
## 1 1.513000 0.927274748 1.25767803 0.59687146
## 2 1.675958 0.896156250 1.31282164 0.47949086
## 3 1.838917 0.853821492 1.36083558 0.34680740
## 4 2.001875 0.798115859 1.38729030 0.20894142
## 5 2.164833 0.727945940 1.37431347 0.08157841
## 6 2.327792 0.644257693 1.30643930 -0.01792391
## 7 2.490750 0.550714595 1.17940279 -0.07797360
## 8 2.653708 0.453441410 1.00638808 -0.09950526
## 9 2.816667 0.359598025 0.81514131 -0.09594526
## 10 2.979625 0.275390447 0.63577343 -0.08499254
## 11 3.142583 0.204601856 0.48756886 -0.07836515
## 12 3.305542 0.148285654 0.37415646 -0.07758515
## 13 3.468500 0.105415989 0.28892829 -0.07809631
## 14 3.631458 0.073865178 0.22356331 -0.07583296
## 15 3.794417 0.051216829 0.17224934 -0.06981569
## 16 3.957375 0.035248556 0.13162443 -0.06112732
## 17 4.120333 0.024132208 0.09961556 -0.05135115
## 18 4.283292 0.016461806 0.07467832 -0.04175471
## 19 4.446250 0.011201450 0.05550126 -0.03309836
## 20 4.609208 0.007609032 0.04093572 -0.02571766
```


And fitted values with a factor independent variable:
@@ -293,15 +249,7 @@ And fitted values with a factor independent variable:
cplot(lm(Sepal.Length~Species, data=iris))
```
```
## xvals yvals upper lower
## 1 setosa 5.006 5.14869 4.86331
## 2 versicolor 5.936 6.07869 5.79331
## 3 virginica 6.588 6.73069 6.44531
```

>>>>>>> master

and a graph of the effect of `drat` across levels of `wt`:
@@ -310,7 +258,7 @@ and a graph of the effect of `drat` across levels of `wt`:


`cplot()` also returns a data frame of values, so that it can be used just for calculating quantities of interest before plotting them with another graphics package, such as **ggplot2**:

=======

>>>>>>> master

Second, the package implements methods for "lm" and "glm" class objects for the `persp()` generic plotting function. This enables three-dimensional representations of predicted outcomes:
@@ -354,13 +298,7 @@ Second, the package implements methods for "lm" and "glm" class objects for the
persp(mod1, xvar="cyl", yvar="hp")
```
<<<<<<< HEAD
```
## Error in x[["model"]]: subscript out of bounds
```
=======

>>>>>>> master


>>>>>>> master

And if three-dimensional plots aren't your thing, there are also analogous methods for the `image()` generic, to produce heatmap-style representations:
@@ -384,14 +316,7 @@ And if three-dimensional plots aren't your thing, there are also analogous metho
image(mod1, xvar="cyl", yvar="hp", main="Predicted Fuel Efficiency,\nby Cylinders and Horsepower")
```
<<<<<<< HEAD
```
## Error in x[["model"]]: subscript out of bounds
```
=======

>>>>>>> master

The numerous package vignettes and help files contain extensive documentation and examples of all package functionality.
The most computationally expensive part of `margins()` is variance estimation. If you don't need variances, use `marginal_effects()` directly or specify `margins(..., vce = "none")`.
0 comments on commit
5d55153