---
title: "compare.margins"
output: rmarkdown::html_vignette
description: >
  This vignette explains the rationale and implementation for the compare.margins function.
vignette: >
  %\VignetteIndexEntry{compare.margins}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

Compares two marginal effects (MEMs or AMEs). Estimate of uncertainty is from a simulated draw from a normal distribution.

For example:
```{r}
library(catregs)
data("essUK")
m1 <- glm(safe ~ religious + minority*female + age,data=essUK,family="binomial")
des<-margins.des(m1,expand.grid(minority=c(0,1),female=c(0,1)))
des
ma1 <- suppressWarnings(as.data.frame(marginaleffects::avg_slopes(m1,
                                                                         variables="female",newdata=marginaleffects::datagrid(minority=0,
                                                                                                                              religious=3.6024,age=53.146))))
ma2 <- suppressWarnings(as.data.frame(marginaleffects::avg_slopes(m1,
                                                                  variables="female",newdata=marginaleffects::datagrid(minority=1,
                                                                                                                       religious=3.6024,age=53.146))))
cames <- rbind(ma2,ma1)
compare.margins(margins=cames$estimate,margins.ses=cames$std.error)
```
