From 80b084d33a2d19dd03bca4db63b7de0cbb859172 Mon Sep 17 00:00:00 2001 From: "Thomas J. Leeper" Date: Fri, 5 Aug 2016 15:17:51 +0100 Subject: [PATCH] update documentation --- .Rbuildignore | 2 + .gitignore | 1 + DESCRIPTION | 4 +- README.Rmd | 36 +- README.md | 36 +- inst/doc/Stata_OLS.log | 956 ------------------------------------- vignettes/Interactions.Rmd | 94 +--- vignettes/Introduction.Rmd | 51 +- 8 files changed, 57 insertions(+), 1123 deletions(-) delete mode 100644 inst/doc/Stata_OLS.log diff --git a/.Rbuildignore b/.Rbuildignore index 967868a..0aeff24 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,5 @@ vignettes/Cigar.csv inst/standarderrors.pdf /figure /cache +/inst/doc/*.log +/inst/doc/*.Rmd diff --git a/.gitignore b/.gitignore index b8e7e42..11e2afa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ README.html inst/standarderrors.pdf +inst/doc/*.log diff --git a/DESCRIPTION b/DESCRIPTION index fcec6b3..411f519 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,9 +2,9 @@ Package: margins Type: Package Title: Marginal Effects for Model Objects Description: An R port of Stata's 'margins' command, which can be used to - calculate marginal effects or partial effects from model objects. + calculate marginal (or partial) effects from model objects. License: MIT + file LICENSE -Version: 0.1.25 +Version: 0.2.0 Date: 2016-08-05 Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"), diff --git a/README.Rmd b/README.Rmd index df2d4e3..71733bc 100644 --- a/README.Rmd +++ b/README.Rmd @@ -33,24 +33,6 @@ Given the challenges of interpreting the contribution of a given regressor in an Some technical details of the package are worth briefly noting. The estimation of marginal effects relies on numeric derivatives produced using `predict()` and [`numDeriv::grad()`](https://cran.r-project.org/package=numDeriv). While symbolic differentiation of some models (e.g., linear models) is possible using `D()` and `deriv()`, R's modelling language (the "formula" class) is sufficiently general to enable the construction of model formulae that contain terms that fall outside of R's symbolic differentiation rule table (e.g., `y ~ factor(x)` or `y ~ I(FUN(x))` for any arbitrary `FUN()`). By relying on numeric differentiation, `margins()` supports *any* model that can be expressed in R formula syntax. Even Stata's `margins` command is limited in its ability to handle variable transformations (e.g., including `x` and `log(x)` as predictors) and quadratic terms (e.g., `x^3`); these scenarios are easily expressed in an R formula and easily handled, correctly, by `margins()`. -## Requirements and Installation ## - -[![CRAN](http://www.r-pkg.org/badges/version/slopegraph)](http://cran.r-project.org/web/packages/margins/index.html) -[![Build Status](https://travis-ci.org/leeper/margins.svg?branch=master)](https://travis-ci.org/leeper/margins) -[![Build status](https://ci.appveyor.com/api/projects/status/t6nxndmvvcw3gw7f/branch/master?svg=true)](https://ci.appveyor.com/project/leeper/margins/branch/master) -[![codecov.io](http://codecov.io/github/leeper/margins/coverage.svg?branch=master)](http://codecov.io/github/leeper/margins?branch=master) -[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) - -The development version of this package can be installed directly from GitHub using `devtools`: - -```R -if (!require("ghit")) { - install.packages("ghit") - library("ghit") -} -install_github("leeper/margins") -``` - ## Simple code examples ## ```{r opts, echo = FALSE} @@ -105,3 +87,21 @@ persp(x, xvar = "cyl", yvar = "wt", what = "effect", nx = 10) The numerous package vignettes and help files contain extensive documentation and examples of all package functionality. +## Requirements and Installation ## + +[![CRAN](http://www.r-pkg.org/badges/version/slopegraph)](http://cran.r-project.org/web/packages/margins/index.html) +[![Build Status](https://travis-ci.org/leeper/margins.svg?branch=master)](https://travis-ci.org/leeper/margins) +[![Build status](https://ci.appveyor.com/api/projects/status/t6nxndmvvcw3gw7f/branch/master?svg=true)](https://ci.appveyor.com/project/leeper/margins/branch/master) +[![codecov.io](http://codecov.io/github/leeper/margins/coverage.svg?branch=master)](http://codecov.io/github/leeper/margins?branch=master) +[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) + +The development version of this package can be installed directly from GitHub using `devtools`: + +```R +if (!require("ghit")) { + install.packages("ghit") + library("ghit") +} +install_github("leeper/margins", build_vignettes = FALSE) +``` + diff --git a/README.md b/README.md index a0f1e18..429e807 100644 --- a/README.md +++ b/README.md @@ -33,24 +33,6 @@ Given the challenges of interpreting the contribution of a given regressor in an Some technical details of the package are worth briefly noting. The estimation of marginal effects relies on numeric derivatives produced using `predict()` and [`numDeriv::grad()`](https://cran.r-project.org/package=numDeriv). While symbolic differentiation of some models (e.g., linear models) is possible using `D()` and `deriv()`, R's modelling language (the "formula" class) is sufficiently general to enable the construction of model formulae that contain terms that fall outside of R's symbolic differentiation rule table (e.g., `y ~ factor(x)` or `y ~ I(FUN(x))` for any arbitrary `FUN()`). By relying on numeric differentiation, `margins()` supports *any* model that can be expressed in R formula syntax. Even Stata's `margins` command is limited in its ability to handle variable transformations (e.g., including `x` and `log(x)` as predictors) and quadratic terms (e.g., `x^3`); these scenarios are easily expressed in an R formula and easily handled, correctly, by `margins()`. -## Requirements and Installation ## - -[![CRAN](http://www.r-pkg.org/badges/version/slopegraph)](http://cran.r-project.org/web/packages/margins/index.html) -[![Build Status](https://travis-ci.org/leeper/margins.svg?branch=master)](https://travis-ci.org/leeper/margins) -[![Build status](https://ci.appveyor.com/api/projects/status/t6nxndmvvcw3gw7f/branch/master?svg=true)](https://ci.appveyor.com/project/leeper/margins/branch/master) -[![codecov.io](http://codecov.io/github/leeper/margins/coverage.svg?branch=master)](http://codecov.io/github/leeper/margins?branch=master) -[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) - -The development version of this package can be installed directly from GitHub using `devtools`: - -```R -if (!require("ghit")) { - install.packages("ghit") - library("ghit") -} -install_github("leeper/margins") -``` - ## Simple code examples ## @@ -132,3 +114,21 @@ persp(x, xvar = "cyl", yvar = "wt", what = "effect", nx = 10) The numerous package vignettes and help files contain extensive documentation and examples of all package functionality. +## Requirements and Installation ## + +[![CRAN](http://www.r-pkg.org/badges/version/slopegraph)](http://cran.r-project.org/web/packages/margins/index.html) +[![Build Status](https://travis-ci.org/leeper/margins.svg?branch=master)](https://travis-ci.org/leeper/margins) +[![Build status](https://ci.appveyor.com/api/projects/status/t6nxndmvvcw3gw7f/branch/master?svg=true)](https://ci.appveyor.com/project/leeper/margins/branch/master) +[![codecov.io](http://codecov.io/github/leeper/margins/coverage.svg?branch=master)](http://codecov.io/github/leeper/margins?branch=master) +[![Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) + +The development version of this package can be installed directly from GitHub using `devtools`: + +```R +if (!require("ghit")) { + install.packages("ghit") + library("ghit") +} +install_github("leeper/margins", build_vignettes = FALSE) +``` + diff --git a/inst/doc/Stata_OLS.log b/inst/doc/Stata_OLS.log deleted file mode 100644 index 7fa30cc..0000000 --- a/inst/doc/Stata_OLS.log +++ /dev/null @@ -1,956 +0,0 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9) (preloaded format=pdftex 2016.8.4) 5 AUG 2016 14:36 -entering extended mode -**C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md -(C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:6: You can't use `macro -parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:6: You can't use `macro -parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:18: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:18: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:18: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:18: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:20: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -Overfull \hbox (3.71806pt too wide) in paragraph at lines 31--40 -\tenrm P>|t| [95-------------+------------------------------------------------- ---------------- cyl | -.9416166 .5509165 -1.71 0.098| - -\hbox(7.5+2.5)x469.75499, glue set - 1.0 -.\tenrm P -.\tenrm > -.\tenrm | -.\tenrm t -.\tenrm | -.etc. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:41: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:47: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:52: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:52: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:53: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:53: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:59: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:59: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:59: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:59: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:61: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:64: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:64: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -Overfull \hbox (3.71806pt too wide) in paragraph at lines 72--81 -\tenrm P>|t| [95-------------+------------------------------------------------- ---------------- cyl | -.3652391 .5086204 -0.72 0.479| - -\hbox(7.5+2.5)x469.75499, glue set - 1.0 -.\tenrm P -.\tenrm > -.\tenrm | -.\tenrm t -.\tenrm | -.etc. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:82: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:87: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:92: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:92: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:93: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:93: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:98: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:98: You can't use `macro - parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:98: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:98: You can't use `macro - parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:100: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:124: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:129: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:134: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:134: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:136: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -Overfull \hbox (130.16634pt too wide) in paragraph at lines 133--136 -[]\tenrm ``` Er-ror in model.frame.default(Terms, new-data, na.action = na.act -ion, xlev = object$\teni xlevels\tenrm ) : \teni factorfactor\tenrm (\teni cyl\ -tenrm )\teni hasnewlevel\tenrm 6\teni :\tenrm 0001\`$ | - -\hbox(7.5+2.5)x469.75499, glue set - 1.0 -.\hbox(0.0+0.0)x20.0 -.\tenrm \ (ligature ``) -.\tenrm ` -.\glue 3.33333 plus 1.66666 minus 1.11111 -.\glue 3.33333 plus 1.66666 minus 1.11111 -.etc. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:140: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:140: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:140: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:140: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:142: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:145: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:145: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -[1{C:/Users/THOMAS/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}] -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:163: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:167: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:168: You can't use `macr -o parameter character #' in math mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:171: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:173: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:173: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:174: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:174: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:179: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:179: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:179: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:179: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:181: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:184: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:187: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in vertical mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:202: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:206: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:207: You can't use `macr -o parameter character #' in math mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:210: Missing $ inserted -I've inserted a begin-math/end-math symbol since I think -you left one out. Proceed, with fingers crossed. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:212: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:212: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:213: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - - -C:/Users/THOMAS/Software/margins/inst/doc/Stata_OLS.md:213: You can't use `macr -o parameter character #' in horizontal mode -Sorry, but I'm not programmed to handle this case; -I'll just pretend that you didn't ask for it. -If you're in the wrong mode, you might be able to -return to the right one by typing `I}' or `I$' or `I\par'. - -) -! Emergency stop -*** (job aborted, no legal \end found) - -! ==> Fatal error occurred, no output PDF file produced! diff --git a/vignettes/Interactions.Rmd b/vignettes/Interactions.Rmd index 4958f32..ab87b73 100644 --- a/vignettes/Interactions.Rmd +++ b/vignettes/Interactions.Rmd @@ -103,29 +103,13 @@ x2 <- lm(mpg ~ hp * wt, data = mtcars) margins(x2) ``` -On average across the cases in the dataset, the effect of horsepower is slightly negative. On average, the effect of weight is also negative. Both decrease fuel economy. But what is the marginal effect of each variable across the range of values we actually observe in the data. To get a handle on this, we'll do something similar to what we did above with `wt`, except now we'll do it for both `wt` and `hp`: +On average across the cases in the dataset, the effect of horsepower is slightly negative. On average, the effect of weight is also negative. Both decrease fuel economy. But what is the marginal effect of each variable across the range of values we actually observe in the data. To get a handle on this, we can use the `persp()` method provided by margins. ```{r} -wts <- seq(range(mtcars$wt)[1], range(mtcars$wt)[2], length.out = 10) -hps <- seq(range(mtcars$hp)[1], range(mtcars$hp)[2], length.out = 10) -m2 <- margins(x2, at = list(wt = wts, hp = hps)) -length(m2) -``` - -In essence, the resulting `m2` marginslist contains the marginal effect of both `wt` and `hp` at each level of both variables. Because we requested 10 values across the range of each variable, the result is a list of 100 sets of marginal effects. We can look at these values directly, for example to understand what the marginal effects of weight and horsepower are when both variables are at their minimum: - -```{r} -m2[[1]] -``` - -Both are negative. But, to really understand what is going on, we probably need to plot the marginal effects. How best to do this is debatable, but arguably a three-dimensional plot of the response surface is the most informative. Let's start by looking at the marginal effects of `wt` across levels of weight and horsepower: - -```{r} -me_wt <- sapply(m2, function(x) {as.numeric(c(summary(x)["wt","dy/dx"]))}) -persp(wts, hps, matrix(me_wt, 10), theta=45, phi=10, shade=.75, xlab='Weight', ylab='Horsepower', zlab='Marginal Effect of Weight') +persp(x2, "wt", "hp", theta = c(45, 135, 225, 315), what = "effect") ``` -To make sense of this plot, it will also be helpful to have the original regression results close at-hand: +To make sense of this set of plots (actually, the same plot seen from four different angles), it will also be helpful to have the original regression results close at-hand: ```{r} summary(x2) @@ -138,8 +122,7 @@ For example, if we take the partial derivative of the regression equation with r If we then take the partial derivative with respect to `hp` (to obtain the marginal effect of horsepower), the equation is: `d_mpg/d_hp = (-0.12) + (0.03 * wt)`. When `wt` is zero, this partial derivative (or marginal effect) is -0.12 miles/gallon. The observed range of `wt`, however, is only: `r range(mtcars$wt)`. We can see these results in the analogous graph of the marginal effects of horsepower (below). The "front" and "back" edges of the graph are now flat (reflecting how the marginal effect of horsepower is constant across levels of horsepower), while the "front-left" and "right-back" edges of the surface are lines with slope 0.03, reflecting the coefficient on the interaction term. ```{r} -me_hp <- sapply(m2, function(x) {as.numeric(c(summary(x)["hp","dy/dx"]))}) -persp(wts, hps, matrix(me_hp, 10), theta=45, phi=10, shade=.75, xlab='Weight', ylab='Horsepower', zlab='Marginal Effect of Horsepower') +persp(x2, "hp", "wt", theta = c(45, 135, 225, 315), what = "effect") ``` An alternative way of plotting these results is to take "slices" of the three-dimensional surface and present them in a two-dimensional graph, similar to what we did above with the indicator-by-continuous approach. That strategy would be especially appropriate for a categorical-by-continuous interaction where the categories of the first variable did not necessarily have a logical ordering sufficient to draw a three-dimensional surface. @@ -161,40 +144,23 @@ This dataset contains data on 332 women, including whether or not they are diabe summary(g1 <- glm(type ~ age * skin, data = Pima.te, family = binomial)) ``` -Logit models (like all GLMs) present the dual challenges of having coefficients that are directly uninterpretable and marginal effects that depend on the values of the data. As a result, we can see coefficients and statistical significance tests above but it's hard to make sense of those results without converting them into a more intuitive quantity, such as the predicted probability of having diabetes. We can see that increasing age and increasing skin thickness are associated with higher rates of diabetes, but the negative coefficient on the interaction term makes it hard to express the substantive size of these relationships. We can use `margins` to achieve this. By default, however, `margins` follows the `predict` function by reporting marginal effects on the scale of the linear predictor: +Logit models (like all GLMs) present the dual challenges of having coefficients that are directly uninterpretable and marginal effects that depend on the values of the data. As a result, we can see coefficients and statistical significance tests above but it's hard to make sense of those results without converting them into a more intuitive quantity, such as the predicted probability of having diabetes. We can see that increasing age and increasing skin thickness are associated with higher rates of diabetes, but the negative coefficient on the interaction term makes it hard to express the substantive size of these relationships. We can use `margins` to achieve this. By default, however, `margins()` reports results on the response scale (thus differing from the default behavior of `stats::predict()`): ```{r} margins(g1) ``` -In a logit model we can interpret the above results as the marginal effect of each constituent variable on the log-odds of having diabetes. Some people find that quantity easy to work with, others do not. Predicted probabilities are universally seen as more intuitive because the marginal effects reflect the change in the predicted probability of having diabetes. To achieve this, we need to request `type = "response"` (instead of the default `type = "link"`): +These marginal effects reflect, on average across all of the cases in our data, how much more likely a woman is to have diabetes. Because this is an *instantaneous* effect, it can be a little hard to conceptualize. I find it helpful to take a look at a predicted probability plot to understand what is going on. Let's take a look, for example, at the effect of age on the probability of having diabetes: ```{r} -margins(g1, type = "response") -``` - -These marginal effects reflect, on average across all of the cases in our data, how much likely a woman is to have diabetes. Because this is an *instantaneous* effect, it can be a little hard to conceptualize. I find it helpful to take a look at a predicted probability plot to understand what is going on. Let's take a look, for example, at the effect of age on the probability of having diabetes: - -```{r} -arange <- range(Pima.te$age) -as <- seq(arange[1], arange[2], by = 1) -plot(as, sapply(as, function(x) { - tmp <- Pima.te - tmp$age <- x - mean(predict(g1, newdata = tmp, type = "response")) -}), xlab = "Age", ylab = "Pr(Diabetes|Age)", ylim = c(0,1), type = "l") +cplot(g1, "age") ``` The above graph shows that as age increase, the probability of having diabetes increases. When a woman is 20 years old, the probability is about .20 whereas when a woman is 80, the probability is about 0.80. In essence, the marginal effect of `age` reported above is the slope of this predicted probability plot at the mean age of women in the dataset (which is `r mean(Pima.te$age)`). Clearly, this quantity is useful (it's the impact of age for the average-aged woman) but the logit curve shows that the marginal effect of `age` differs considerably across ages and, as we know from above with linear models, also depends on the other variable in the interaction (skin thickness). To really understand what is going on, we need to graph the data. Let's look at the perspective plot like the one we drew for the OLS model, above: ```{r} -as <- seq(range(Pima.te$age)[1], range(Pima.te$age)[2], length.out = 10) -ss <- seq(range(Pima.te$skin)[1], range(Pima.te$skin)[2], length.out = 10) -gm1 <- margins(g1, at = list(age = as, skin = ss), type = "response") -me_age <- sapply(gm1, function(x) {as.numeric(c(summary(x)["age","dy/dx"]))}) -persp(as, ss, matrix(me_age, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Age') +persp(g1, theta = c(45, 135, 225, 315), what = "prediction") ``` This graph is much more complicated than the analogous graph for an OLS model, this is because of the conversion between the log-odds scale of the linear predictors and the distribution of the data. What we can see is that the average marginal effect of age (across all of the women in our dataset) is highest when a woman is middle age and skin thickness is low. In these conditions, the marginal change in the probability of diabetes is about 3%, but the AME of age is nearly zero at higher and lower ages. Indeed, as skin thickness increases, the marginal effect of age flattens out and actually becomes negative (such that increasing age actually decreases the probability of diabetes for women with thick arms). @@ -202,9 +168,7 @@ This graph is much more complicated than the analogous graph for an OLS model, t Now let's examine the average marginal effects of skin thickness across levels of age and skin thickness: ```{r} -me_skin <- sapply(gm1, function(x) {as.numeric(c(summary(x)["skin","dy/dx"]))}) -persp(as, ss, matrix(me_skin, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Skin') +persp(g1, theta = c(45, 135, 225, 315), what = "effect") ``` This graphs is somewhat flatter, indicating that the average marginal effects of skin thickness vary less than those for age. Yet, the AME of skin thickness is as high as 2% when age is low and skin thickness is high. Interestingly, however, this effect actually becomes negative as age increases. The marginal effect of skin thickness is radically different for young and old women. @@ -216,45 +180,11 @@ It is also worth comparing the above graphs to those that would result from a mo ```{r, echo = FALSE, fig.width=8, fig.height=4} g2 <- glm(type ~ age + skin, data = Pima.te, family = binomial) -gm2 <- margins(g2, at = list(age = as, skin = ss), type = "response") -par(mar = c(1,2,1,1)) -layout(matrix(1:2, nrow = 1)) -me_age2 <- sapply(gm2, function(x) {as.numeric(c(summary(x)["age","dy/dx"]))}) -persp(as, ss, matrix(me_age2, 10), theta=55, phi=30, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Age') -me_skin2 <- sapply(gm2, function(x) {as.numeric(c(summary(x)["skin","dy/dx"]))}) -persp(as, ss, matrix(me_skin2, 10), theta=55, phi=30, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Skin') +persp(g2, theta = c(45, 135, 225, 315), what = "prediction") +persp(g2, theta = c(45, 135, 225, 315), what = "effect") ``` -Our inferences about the impact of a variable on the outcome in a GLM therefore depend quite heavily on how the interaction is modelled. It also worth pointing out that the surface of the AMEs on the log-odds (linear) scale are actually flat (as in an OLS model), so the the curved shape of the plot immediately above reflects only the conversion of the effects from the linear scale to the probability scale (and the distributions of the covariates), whereas the much more unusual surface from earlier reflects that conversion and the interaction between the two variables (and the distributions thereof). If we plot the interaction model on the scale of the log-odds, it looks much more like the plot from the OLS models, earlier: - - -```{r, echo = FALSE, fig.width=8, fig.height=4} -gm3 <- margins(g1, at = list(age = as, skin = ss), type = "link") -par(mar = c(1,2,1,1)) -layout(matrix(1:2, nrow = 1)) -me_age3 <- sapply(gm3, function(x) {as.numeric(c(summary(x)["age","dy/dx"]))}) -persp(as, ss, matrix(me_age3, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Age') -me_skin3 <- sapply(gm3, function(x) {as.numeric(c(summary(x)["skin","dy/dx"]))}) -persp(as, ss, matrix(me_skin3, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Skin (Log-Odds)') -``` - -And were we to examine a similar plot for the logit model without the interaction term, expressed in terms of log-odds, it would simply show two flat, horizontal surfaces wherein the effect of age did not depend on age or skin thickness nor did the effect of skin thickness depend on age or skin thickness. - -```{r, eval=FALSE, echo = FALSE, fig.width=8, fig.height=4} -gm4 <- margins(g2, at = list(age = as, skin = ss), type = "link") -par(mar = c(1,2,1,1)) -layout(matrix(1:2, nrow = 1)) -me_age4 <- sapply(gm4, function(x) {as.numeric(c(summary(x)["age","dy/dx"]))}) -persp(as, ss, matrix(me_age4, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Age') -me_skin4 <- sapply(gm4, function(x) {as.numeric(c(summary(x)["skin","dy/dx"]))}) -persp(as, ss, matrix(me_skin4, 10), theta=45, phi=10, shade=.75, ticktype = "detailed", - xlab='Age', ylab='Skin Thickness', zlab='Marginal Effect of Skin (Log-Odds)') -``` +Our inferences about the impact of a variable on the outcome in a GLM therefore depend quite heavily on how the interaction is modelled. It also worth pointing out that the surface of the AMEs on the log-odds (linear) scale are actually flat (as in an OLS model), so the the curved shape of the plot immediately above reflects only the conversion of the effects from the linear scale to the probability scale (and the distributions of the covariates), whereas the much more unusual surface from earlier reflects that conversion and the interaction between the two variables (and the distributions thereof). If we were to plot the interaction model on the scale of the log-odds, it would look much more like the plot from the OLS models (this is left as an exercise to the reader). ## References ## diff --git a/vignettes/Introduction.Rmd b/vignettes/Introduction.Rmd index 4137296..b46744f 100644 --- a/vignettes/Introduction.Rmd +++ b/vignettes/Introduction.Rmd @@ -69,56 +69,13 @@ The slopes of the predicted value lines are the marginal effect of `wt` when `am margins(x, at = list(am = 0:1)) ``` -The above plot also highlights, though, that the marginal effect of transmission `am` differs across values of `wt`. As weight increases, the effect of a manual transmission goes from positive (where the blue line is higher than the red line) to negative (where the red line exceed the blue line). Because `am` is an indicator variable, the marginal effect is simply the first-difference (i.e., the difference between the two sets of values we just predicted that are now stored in `p`). We can plot the differences between predicted values to see how the marginal effect of `am` increases (in negative magnitude): +A final plotting function - the `persp()` method for "lm" objects implemented by **margins** - gives even more functionality: -```{r, results = "hold"} -me <- p[3,] - p[1,] -plot(tmp_wt, me, type = "l", ylim = c(-15,15), lwd = 2, xlab = "wt", ylab = "Marginal Effect at Means") -abline(h = 0, col = 'gray') -s <- sqrt(p[4,]^2 + p[2,]^2) -lines(tmp_wt, me + 1.96 * s, lty = 2, lwd = 1) -lines(tmp_wt, me - 1.96 * s, lty = 2, lwd = 1) -``` - -The marginal effect of `am` is now clear. It is positive when weight is low, indistinguishable from zero for much of the range of weight, and then negative when weight is very high. - -But, that's a lot of code to create a plot of marginal effects. Using `margins`, we can produce an essentially identical plot much more easily. Starting again from the same regression model estimation, we can produce the plot quite easily: - -```{r, results = "hold"} -x <- lm(mpg ~ cyl + wt * am, data = mtcars) - -# calculate marginal effects at specified `wt`s and extract results -tmp_wt <- seq(min(mtcars$wt), max(mtcars$wt), .05) -m <- margins(x, at = list(wt = tmp_wt)) -me <- sapply(m, function(z) summary(z)["am",c(2,6,7)]) - -# draw plot -plot(tmp_wt, me[1,], type = "l", ylim = c(-15,15), lwd = 2, xlab = "wt", ylab = "Marginal Effect at Means") -abline(h = 0, col = 'gray') -lines(tmp_wt, me[2,], lty = 2, lwd = 1) -lines(tmp_wt, me[3,], lty = 2, lwd = 1) -``` - - -It is also possible to do this with **ggplot2**. Starting from the list of marginal effects results (`m`) from above, we can replace the base plotting code with simple ggplot2 code: - -```{r, results = "hold"} -me <- do.call(rbind, lapply(m, function(z) summary(z)["am",c(2,6,7)])) -me$x <- as.numeric(row.names(me)) -names(me) <- c("e","l","u","x") # rename columns for simplicity - -library("ggplot2") -ggplot(me) + geom_line(aes(x=x, y=e, group=1)) + - geom_hline(yintercept=0, linetype=2, color="dark gray") + - geom_line(aes(x=x, y=u, group=1), stat="identity", alpha=.3, color="black") + - geom_line(aes(x=x, y=l, group=1), stat="identity", alpha=.3, color="black") + - xlab("wt") + ylab("Marginal Effect") + theme_bw() +```{r} +persp(x, "cyl", "wt") ``` - - - - +Richer examples of this are included in [the "Interpreting Interactions" vignette](Interactions.html). ## Using Optional Arguments in `margins`