├── _pkgdown.yml ├── .gitattributes ├── LICENSE ├── dev ├── jss │ ├── jsslogo.jpg │ ├── jss_manuscript.pdf │ ├── _extensions │ │ └── jss │ │ │ ├── jsslogo.jpg │ │ │ ├── partials │ │ │ ├── before-body.tex │ │ │ ├── _print-author.tex │ │ │ ├── _print-address.tex │ │ │ └── title.tex │ │ │ ├── _extensions │ │ │ └── quarto-ext │ │ │ │ └── fancy-text │ │ │ │ ├── _extension.yml │ │ │ │ └── fancy-text.lua │ │ │ ├── _extension.yml │ │ │ └── jss.lua │ └── jss_interplot.bib ├── plot-by-category.R ├── runBeforeRelease.R ├── interplot_test.R └── predprob_mlm.R ├── .gitignore ├── docs ├── reference │ ├── Rplot001.png │ ├── Rplot002.png │ ├── interplot-1.png │ ├── interplot-2.png │ ├── interplot.lmmi-1.png │ ├── index.html │ └── interplot.lmerMod.html ├── pkgdown.yml ├── articles │ ├── interplot-vignette_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ ├── unnamed-chunk-13-1.png │ │ │ ├── unnamed-chunk-14-1.png │ │ │ ├── unnamed-chunk-14-2.png │ │ │ ├── unnamed-chunk-15-1.png │ │ │ ├── unnamed-chunk-16-1.png │ │ │ ├── unnamed-chunk-17-1.png │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ ├── unnamed-chunk-7-1.png │ │ │ ├── unnamed-chunk-8-1.png │ │ │ └── unnamed-chunk-9-1.png │ │ └── header-attrs-2.7 │ │ │ └── header-attrs.js │ └── index.html ├── link.svg ├── sitemap.xml ├── bootstrap-toc.css ├── docsearch.js ├── pkgdown.js ├── LICENSE-text.html ├── bootstrap-toc.js ├── 404.html ├── authors.html ├── CONDUCT.html ├── index.html ├── pkgdown.css └── docsearch.css ├── CRAN-RELEASE ├── .Rbuildignore ├── cran-comments.md ├── interplot.Rproj ├── R ├── replicated_file_ks.R └── Interplot.R ├── NAMESPACE ├── DESCRIPTION ├── README.md ├── CONDUCT.md ├── NEWS.md ├── vignettes ├── vignette.bib.bak ├── interplot-vignette.R └── vignette.bib └── man ├── interplot.lmerMod.Rd ├── interplot.mlmmi.Rd ├── interplot.plot.Rd ├── interplot.default.Rd ├── interplot.lmmi.Rd └── interplot.Rd /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | inst/doc/*.html linguist-documentation 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2015 2 | COPYRIGHT HOLDER: Frederick Solt, Yue HU 3 | -------------------------------------------------------------------------------- /dev/jss/jsslogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/dev/jss/jsslogo.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | 6 | lit/ 7 | pew1_w.csv 8 | -------------------------------------------------------------------------------- /dev/jss/jss_manuscript.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/dev/jss/jss_manuscript.pdf -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/interplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/reference/interplot-1.png -------------------------------------------------------------------------------- /docs/reference/interplot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/reference/interplot-2.png -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/jsslogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/dev/jss/_extensions/jss/jsslogo.jpg -------------------------------------------------------------------------------- /docs/reference/interplot.lmmi-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/reference/interplot.lmmi-1.png -------------------------------------------------------------------------------- /CRAN-RELEASE: -------------------------------------------------------------------------------- 1 | This package was submitted to CRAN on 2021-02-18. 2 | Once it is accepted, delete this file and tag the release (commit abccade). 3 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/partials/before-body.tex: -------------------------------------------------------------------------------- 1 | $if(has-frontmatter)$ 2 | \frontmatter 3 | $endif$ 4 | $if(title)$ 5 | \maketitle 6 | $endif$ 7 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 3.1.1 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: 5 | interplot-vignette: interplot-vignette.html 6 | last_built: 2024-03-01T08:58Z 7 | 8 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/_extensions/quarto-ext/fancy-text/_extension.yml: -------------------------------------------------------------------------------- 1 | title: Fancy Text 2 | author: "RStudio, PBC" 3 | version: 0.0.1 4 | contributes: 5 | shortcodes: 6 | - fancy-text.lua 7 | -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-14-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-14-2.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammo3182/interplot/HEAD/docs/articles/interplot-vignette_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/partials/_print-author.tex: -------------------------------------------------------------------------------- 1 | $if(it.metadata.latex-prefix)$ $it.metadata.latex-prefix$ $endif$$it.name.literal$$if(it.orcid)$~\orcidlink{$it.orcid$}$endif$$for(it.affiliations/first)$\\$it.name$$endfor$ -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^cran-comments.md$ 4 | 5 | ^dev$ 6 | ^lit$ 7 | ^CONDUCT\.md$ 8 | ^CRAN-RELEASE$ 9 | ^jss_manuscript.* 10 | ^_pkgdown\.yml$ 11 | ^docs$ 12 | ^pkgdown$ 13 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * Local OS X install, R 3.5.0 3 | * Ubuntu 14.04.5 LTS (on travis-ci), R 3.5.0 4 | * win-builder (R Under development (unstable) (2020-10-12 r79333)) 5 | 6 | ## R CMD check results 7 | 0 errors | 0 warnings | 0 notes -------------------------------------------------------------------------------- /interplot.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageCheckArgs: --as-cran 19 | PackageRoxygenize: rd,collate,namespace,vignette 20 | -------------------------------------------------------------------------------- /docs/articles/interplot-vignette_files/header-attrs-2.7/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/partials/_print-address.tex: -------------------------------------------------------------------------------- 1 | $it.name.literal$\\$if(it.affiliations/first)$$for(it.affiliations/first)$$if(it.department)$ 2 | 3 | $it.department$\\$endif$$if(it.address)$ 4 | 5 | $it.address$\\$endif$$if(it.city)$ 6 | 7 | $it.city$$endif$$if(it.state)$ $it.state$$endif$$if(it.country)$ $it.country$$endif$$if(it.city)$\\$elseif(it.state)$\\$elseif(it.country)$\\$endif$$endfor$$endif$$if(it.phone)$ 8 | 9 | Telephone: $it.phone$\\$endif$$if(it.fax)$ 10 | 11 | Fax: $it.fax$\\$endif$$if(it.email)$ 12 | 13 | E-mail: \email{$it.email$}\\$endif$$if(it.url)$ 14 | 15 | URL: \url{$it.url$}\\$endif$ 16 | 17 | \\~ 18 | 19 | -------------------------------------------------------------------------------- /R/replicated_file_ks.R: -------------------------------------------------------------------------------- 1 | m <- lm(mpg ~ wt * qsec, data = mtcars) 2 | 3 | var1 = 'qsec' 4 | var2 = 'wt' 5 | var12 <- paste0(var2, ":", var1) 6 | 7 | m.sims <- arm::sim(m, 100) 8 | 9 | xmin <- min(m$model[var2], na.rm = T) 10 | xmax <- max(m$model[var2], na.rm = T) 11 | 12 | 13 | min_sim <- m.sims@coef[, match(var1, names(m$coef))] + xmin * m.sims@coef[, match(var12, names(m$coef))] # simulation of the value at the minimum value of the conditioning variable 14 | max_sim <- m.sims@coef[, match(var1, names(m$coef))] + xmax * m.sims@coef[, match(var12, names(m$coef))] # simulation of the value at the maximum value of the conditioning variable 15 | 16 | ks.test(min_sim, max_sim) -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(interplot,default) 4 | S3method(interplot,glmerMod) 5 | S3method(interplot,glmmi) 6 | S3method(interplot,gmlmmi) 7 | S3method(interplot,lmerMod) 8 | S3method(interplot,lmmi) 9 | S3method(interplot,mlmmi) 10 | S3method(interplot,plot) 11 | export(interplot) 12 | import(dplyr) 13 | import(ggplot2) 14 | importFrom(abind,abind) 15 | importFrom(arm,sim) 16 | importFrom(dplyr,mutate) 17 | importFrom(graphics,hist) 18 | importFrom(interactionTest,fdrInteraction) 19 | importFrom(purrr,map) 20 | importFrom(stats,median) 21 | importFrom(stats,model.matrix) 22 | importFrom(stats,plogis) 23 | importFrom(stats,qnorm) 24 | importFrom(stats,quantile) 25 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/_extensions/quarto-ext/fancy-text/fancy-text.lua: -------------------------------------------------------------------------------- 1 | -- shortcode that provides a nicely formatted 'LaTeX' string 2 | function latex() 3 | if quarto.doc.is_format("pdf") then 4 | return pandoc.RawBlock('tex', '{\\LaTeX}') 5 | elseif quarto.doc.is_format("html") then 6 | return pandoc.Math('InlineMath', "\\LaTeX") 7 | else 8 | return pandoc.Span('LaTeX') 9 | end 10 | end 11 | 12 | -- shortcode that provides a nicely formatted 'bibtex' string 13 | function bibtex() 14 | if quarto.doc.is_format("pdf") then 15 | return pandoc.RawBlock('tex', '\\textsc{Bib}{\\TeX}') 16 | elseif quarto.doc.is_format("html") then 17 | return pandoc.RawBlock('html', 'BibTEX') 18 | else 19 | return pandoc.Span('BibTeX') 20 | end 21 | end -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: interplot 2 | Title: Plot the Effects of Variables in Interaction Terms 3 | Version: 0.2.3 4 | Authors@R: c( 5 | person("Frederick", "Solt", email = "frederick-solt@uiowa.edu", role = c("aut")), 6 | person("Yue", "Hu", email = "yuehu@tsinghua.edu.cn", role = c("aut", "cre")), 7 | person("Brenton", "Kenkel", email = "brenton.kenkel@gmail.com", role = "ctb")) 8 | Maintainer: Yue Hu 9 | Description: Plots the conditional coefficients ("marginal effects") of 10 | variables included in multiplicative interaction terms. 11 | BugReports: https://github.com/sammo3182/interplot/issues 12 | Encoding: UTF-8 13 | Depends: 14 | R (>= 3.1.1), 15 | ggplot2, 16 | abind, 17 | arm 18 | Imports: 19 | stats, 20 | dplyr, 21 | purrr, 22 | interactionTest 23 | License: MIT + file LICENSE 24 | LazyData: true 25 | Suggests: 26 | knitr, 27 | rmarkdown, 28 | mitools, 29 | gridExtra 30 | VignetteBuilder: knitr 31 | RoxygenNote: 7.2.3 32 | -------------------------------------------------------------------------------- /dev/plot-by-category.R: -------------------------------------------------------------------------------- 1 | #' --- 2 | #' title: "Crop Analysis Q3 2013" 3 | #' author: "Yue Hu" 4 | #' --- 5 | 6 | 7 | library(interplot) 8 | 9 | #' Toy models 10 | m_cyl1 <- lm(mpg ~ wt * cyl, data = mtcars[1:16,]) 11 | m_cyl2 <- lm(mpg ~ wt * cyl, data = mtcars[17:32,]) 12 | 13 | 14 | #' Build the data frames and categorize them manually 15 | #' 16 | df_outcome1 <- interplot(m = m_cyl1, var1 = 'cyl', var2 = 'wt', plot = FALSE) 17 | df_outcome1$value <- "Category 1" # variable name has to be "value" 18 | 19 | df_outcome2 <- interplot(m = m_cyl2, var1 = 'cyl', var2 = 'wt', plot = FALSE) 20 | df_outcome2$value <- "Category 2" 21 | 22 | #' combine the data frames 23 | df_outcome <- rbind(df_outcome1, df_outcome2) 24 | df_outcome$value <- as.factor(df_outcome$value) # required step 25 | names(df_outcome) <- c("fake", "coef1", "lb", "ub", "value") # variables have to be named in this way 26 | df_outcome 27 | 28 | #' Let `interplot` presents the effect by category 29 | #' 30 | interplot(df_outcome, predPro = TRUE) 31 | 32 | rmarkdown::render("dev/plot-by-category.R") 33 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /articles/index.html 8 | 9 | 10 | /articles/interplot-vignette.html 11 | 12 | 13 | /authors.html 14 | 15 | 16 | /CONDUCT.html 17 | 18 | 19 | /index.html 20 | 21 | 22 | /LICENSE-text.html 23 | 24 | 25 | /news/index.html 26 | 27 | 28 | /reference/index.html 29 | 30 | 31 | /reference/interplot.default.html 32 | 33 | 34 | /reference/interplot.html 35 | 36 | 37 | /reference/interplot.lmerMod.html 38 | 39 | 40 | /reference/interplot.lmmi.html 41 | 42 | 43 | /reference/interplot.mlmmi.html 44 | 45 | 46 | /reference/interplot.plot.html 47 | 48 | 49 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/_extension.yml: -------------------------------------------------------------------------------- 1 | title: Journal of Statistical Software Format 2 | author: Charles Teague 3 | version: 0.9.4 4 | quarto-required: ">=1.2.198" 5 | contributes: 6 | format: 7 | common: 8 | filters: 9 | - jss.lua 10 | shortcodes: 11 | - quarto-ext/fancy-text 12 | knitr: 13 | opts_chunk: 14 | R.options: 15 | prompt: "R> " 16 | continue: "+" 17 | pdf: 18 | documentclass: jss 19 | shift-heading-level-by: -1 20 | tbl-cap-location: bottom 21 | highlight-style: none 22 | include-in-header: 23 | text: | 24 | \usepackage{orcidlink,thumbpdf,lmodern} 25 | 26 | \newcommand{\class}[1]{`\code{#1}'} 27 | \newcommand{\fct}[1]{\code{#1()}} 28 | fig-width: 4.9 # 6.125" * 0.8, as in template 29 | fig-height: 3.675 # 4.9 * 3:4 30 | template-partials: 31 | - "partials/title.tex" 32 | - "partials/before-body.tex" 33 | - "partials/_print-address.tex" 34 | - "partials/_print-author.tex" 35 | cite-method: natbib 36 | biblio-config: false 37 | format-resources: 38 | - jss.bst 39 | - jss.cls 40 | - jsslogo.jpg 41 | html: 42 | number-sections: true 43 | toc: true 44 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/partials/title.tex: -------------------------------------------------------------------------------- 1 | %% -- Article metainformation (author, title, ...) ----------------------------- 2 | 3 | %% Author information 4 | \author{$for(by-author)$$_print-author.tex()$$endfor$} 5 | \Plainauthor{$for(by-author)$$it.name.literal$$sep$, $endfor$} %% comma-separated 6 | 7 | \title{$title$} 8 | $if(title-plain)$ 9 | \Plaintitle{$title-plain$} %% without formatting 10 | $endif$ 11 | $if(short-title)$ 12 | \Shorttitle{$short-title$} %% a short title (if necessary) 13 | $endif$ 14 | 15 | %% an abstract and keywords 16 | $if(abstract)$ 17 | \Abstract{$abstract$} 18 | $endif$ 19 | 20 | %% at least one keyword must be supplied 21 | $if(keywords-formatted)$ 22 | \Keywords{$for(keywords-formatted)$$it$$sep$, $endfor$} 23 | $endif$ 24 | $if(keywords)$ 25 | \Plainkeywords{$for(keywords)$$it$$sep$, $endfor$} 26 | $endif$ 27 | 28 | %% publication information 29 | %% NOTE: Typically, this can be left commented and will be filled out by the technical editor 30 | %% \Volume{50} 31 | %% \Issue{9} 32 | %% \Month{June} 33 | %% \Year{2012} 34 | %% \Submitdate{2012-06-04} 35 | %% \Acceptdate{2012-06-04} 36 | %% \setcounter{page}{1} 37 | %% \Pages{1--xx} 38 | 39 | %% The address of (at least) one author should be given 40 | %% in the following format: 41 | $if(by-author)$ 42 | \Address{ 43 | $for(by-author)$$_print-address.tex()$$endfor$ 44 | } 45 | $endif$ 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pkgdown 2 | 3 | [![CRAN version](http://www.r-pkg.org/badges/version/interplot)](https://cran.r-project.org/package=interplot) ![](http://cranlogs.r-pkg.org/badges/grand-total/interplot) 4 | 5 | ------------------------------------------------------------------------ 6 | interplot 7 | ========= 8 | 9 | `interplot` is a tool for plotting the conditional coefficients ("marginal effects") of variables included in multiplicative interaction terms. The function plots the changes in the coefficient of one variable in a two-way interaction term conditional on the value of the other included variable. The plot also includes simulated 95% confidential intervals of these coefficients. 10 | 11 | To install: 12 | 13 | * the latest released version: `install.packages("interplot")`. 14 | * the latest developing version: `remotes::install_github("sammo3182/interplot")`. 15 | 16 | 17 | More details are available at: 18 | 19 | http://cran.r-project.org/web/packages/interplot/vignettes/interplot-vignette.html 20 | 21 | 22 | Please note that this project is released with a [Contributor Code of Conduct](https://github.com/sammo3182/interplot/blob/master/CONDUCT.md). By participating in this project you agree to abide by its terms. 23 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /dev/runBeforeRelease.R: -------------------------------------------------------------------------------- 1 | # Check List for A New Release 2 | 3 | ## Vignette building 4 | 5 | devtools::install(build_vignettes = TRUE) 6 | 7 | ## Spell checking 8 | 9 | library(devtools) 10 | library(roxygen2) 11 | 12 | spell_check() 13 | 14 | rhub::validate_email(email = "yuehu@tsinghua.edu.cn", token = "345011f4ca60404abf76007e9ae89e3e") 15 | 16 | check_rhub(email = "yuehu@tsinghua.edu.cn") 17 | 18 | 19 | ## Run the CRAN check 20 | # 1. Under the `Build` tab 21 | # 1. Fixed all the errors and warnings 22 | 23 | ## Documentation 24 | 25 | # 1. Update the version number in `DESCRIPTION` 26 | # 1. Update `NEWS` 27 | 28 | ## Removing the htmls to release space 29 | 30 | library(here) 31 | 32 | ls_html <- 33 | list.files(here("inst/tutorials"), 34 | pattern = "*.html$", 35 | recursive = TRUE, 36 | full.names = TRUE) 37 | 38 | file.remove(ls_html) 39 | 40 | ## Release 41 | 42 | devtools::release() 43 | 44 | ## Change the version number in `DESCRIPTION` back to the dev version (i.e., "9999") 45 | 46 | ## Post the Release note when the package is on CRAN 47 | 48 | 49 | ## (No need if the package already has a website) Package website building 50 | library(devtools) 51 | 52 | usethis::git_vaccinate() #Adds .DS_Store, .Rproj.user, .Rdata, .Rhistory, and .httr-oauth to your global (a.k.a. user-level) .gitignore. This is good practice as it decreases the chance that you will accidentally leak credentials to GitHub. 53 | 54 | use_github_links() 55 | use_github_action_check_standard() 56 | 57 | library(pkgdown) 58 | build_site() 59 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /dev/interplot_test.R: -------------------------------------------------------------------------------- 1 | library(mi) 2 | library(mitools) 3 | library(Amelia) 4 | 5 | p2005 <- read_sav("../Meritocracy_Rep/data/pew/merit/version_a/Dec05/Dec05c.sav") 6 | p2005x <- data.frame( 7 | resp = p2005$resp, 8 | fips = as.numeric(p2005$qfips), 9 | state = floor(as.numeric(p2005$qfips)/1000), 10 | rej_merit = ifelse(p2005$q14k<=2, 0, ifelse(p2005$q14k>4, NA, 1)), 11 | income = ifelse(p2005$income<=9, p2005$income, NA), # 1 to 9 12 | educ = ifelse(p2005$educ<=7, p2005$educ, NA), # 1 to 7 13 | age = ifelse(p2005$age<99, p2005$age, NA), 14 | male = ifelse(p2005$sex==1, 1, 0), 15 | white = ifelse(p2005$race==1 & p2005$hisp!=1, 1, 0), 16 | union = ifelse(p2005$labor<=3, 1, ifelse(p2005$labor==4, 0, NA)), 17 | ideo = 6 - ifelse(p2005$ideo<=5, p2005$ideo, NA), # 1 to 5 18 | attend = 7 - ifelse(p2005$attend<=6, p2005$attend, NA) # 1 to 6 19 | ) 20 | 21 | m1 <- glm(rej_merit ~ income*educ + age, data = p2005x, family = binomial(link = "logit")) 22 | interplot(m1, "income", "educ") 23 | 24 | p2005x_mi <- missing_data.frame(p2005x) 25 | p2005x_mi <- change_type(p2005x_mi, y = "resp", to = "irrelevant") 26 | p2005x_mi <- change_type(p2005x_mi, y = "fips", to = "irrelevant") 27 | p2005x_mi <- change_type(p2005x_mi, y = "state", to = "irrelevant") 28 | p2005x_mi <- change_type(p2005x_mi, y = "income", to = "ordered-categorical") 29 | p2005x_mi <- change_type(p2005x_mi, y = "educ", to = "ordered-categorical") 30 | p2005x_mi <- change_type(p2005x_mi, y = "attend", to = "ordered-categorical") 31 | 32 | ptm <- proc.time() 33 | p2005x_im <- mi(p2005x_mi, n.chains=8, n.iter=30, seed=324, max.minutes=60) 34 | proc.time() - ptm 35 | 36 | m2_mi <- pool(formula = rej_merit ~ as.numeric(income) * as.numeric(educ) + age, 37 | family=binomial(link="logit"), 38 | data = p2005x_im) 39 | # class "pooled" should be implemented 40 | 41 | p2005x_mi_list <- complete(p2005x_im, m = 10) 42 | p2005x_mi_list2 <- p2005x_mi_list 43 | for (i in 1:10) { 44 | p2005x_mi_list2[[i]]$income <- as.numeric(p2005x_mi_list[[i]]$income) 45 | p2005x_mi_list2[[i]]$educ <- as.numeric(p2005x_mi_list[[i]]$educ) 46 | p2005x_mi_list2[[i]]$attend <- as.numeric(p2005x_mi_list[[i]]$attend) 47 | } 48 | p2005x_mi_list3 <- imputationList(p2005x_mi_list2) 49 | 50 | 51 | m2_mitools <- with(p2005x_mi_list3, 52 | glm(formula = rej_merit ~ income * educ + age, 53 | family=binomial(link="logit"))) 54 | interplot(m2_mitools, "income", "educ") 55 | 56 | m3_mitools <- with(p2005x_mi_list3, 57 | glmer(formula = rej_merit~income * educ + age + 58 | (1+income|state), family=binomial(link="logit"))) 59 | interplot(m3_mitools, "income", "educ") 60 | 61 | 62 | a <- amelia(p2005x, m = 5, ords = 4) # lgstc doesn't seem to work 63 | a2 <- imputationList(a$imputations) 64 | 65 | m4_amelia <- with(a2, glm(formula = rej_merit ~ income * educ + age, 66 | family=binomial(link="logit"))) 67 | interplot(a4, "income", "educ") -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # interplot 1.0.9999 2 | 3 | In this version, the structure of the primary function is rewritten. 4 | The function treats factor and numeric base terms with separate side functions leaving room for more distinguished actions on the models with the two types of terms. 5 | 6 | ## New features 7 | 8 | - `stats_cp = "ci"` works for factor base-term models. 9 | - Allow to output confidence intervals of the difference between the minimum and maximum values of the conditioning variable when `plot = FALSE`. 10 | - `prePro` can be used on multilevel models 11 | 12 | ## Bug fix 13 | 14 | - Update `interplot.plot` for the latest version of `ggplot` 15 | 16 | 17 | # interplot 0.2.3 18 | 19 | ## New features 20 | 21 | 1. Adding new statistics for testing the statistical significance of the conditional effect (by `stats_cp`). 22 | 1. Adding an argument to modify the plot caption (by `txt_caption`). 23 | 24 | ## Bug fix 25 | 26 | 1. Adding example of models based on multiple imputations. 27 | 1. Modifying the vignette to include new functions. 28 | 29 | # interplot 0.2.2 30 | * interplot no longer sets the random seed; to ensure complete reproducibility, users must now set their own seeds using `set.seed()` before calling interplot functions. 31 | * Adds facet_labs argument, an optional character vector of facet labels to be used when plotting an interaction with a factor variable. 32 | 33 | # interplot 0.2.1 34 | ## Function Updates 35 | * Showing the confidence intervals between the conditional effects at the minimum and maximum values of the conditioning variable. 36 | 37 | ## Error Fixed 38 | * Avoiding the warning caused by the `class(m) == "polr"`. 39 | 40 | # interplot 0.2.0 41 | ## Adding Argument 42 | * Adding an argument to adjust CIs to control the false discovery rate. 43 | * Adding an argument to produce conditional predicted probabilities at given values. 44 | 45 | ## Vignette Updates 46 | * Adding a brief review of the methodology of interaction. 47 | * Adding an example to show how to control for the false discovery rate. 48 | * Adding an example to illustrate plotting conditional predicted propbabilities. 49 | 50 | # interplot 0.1.5 51 | ## Adding Argument 52 | * Adding an argument to adjust the CIs. 53 | 54 | # interplot 0.1.4 55 | ## Error Fixed 56 | * Fixing the error in plotting `lmer` projects. 57 | 58 | 59 | # interplot 0.1.3 60 | ## Function Updates 61 | * Take the `steps` argument back in case of special design requirement of the plot. 62 | * Fixed an error in presenting the histogram on categorical conditioning variables. 63 | * Improving the histogram presentation: all the bars for categorical variables are centered. 64 | 65 | ## Vignette Updates 66 | Updated the vignette including instructions of how to change the aesthetics of the plot and how to use histogram function. 67 | 68 | # interplot 0.1.2.1 69 | ## Vignette Updates 70 | Updated the vignette including instructions of how to change the aesthetics of the plot and how to use histogram function. 71 | 72 | # interplot 0.1.2.0 73 | ## Additional Function 74 | 1. The aesthetics can be modified through built-in arguments or the ggplot `geom_` functions. 75 | 2. A histogram can be superimposed into the plot. 76 | 77 | 78 | # interplot 0.1.1.1 79 | ## Additional Function 80 | Adding the function to plot interactions based on factor variables. 81 | ## Bug fix 82 | Fit `ggplot2` 2.0.0 83 | Fixed the quadratic error (#16) 84 | 85 | 86 | # interplot 0.1.1.0 87 | ## Additional Function 88 | Adding the function to plot interactions based on factor variables. 89 | ## Bug fix 90 | Fit `ggplot2` 2.0.0 91 | 92 | 93 | # interplot 0.1.0.2 94 | ## Bug fix 95 | Fix the bug for nonlinear multilevel models with multiply imputed data (gmlmmi). 96 | 97 | 98 | # interplot 0.1.0.1 99 | ## Bug fix 100 | Fix the error to run mlm and mlmmi. 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /dev/jss/_extensions/jss/jss.lua: -------------------------------------------------------------------------------- 1 | -- these classes, when placed on a span will be replaced 2 | -- with an identical LaTeX command for PDF output 3 | local texMappings = { 4 | "proglang", 5 | "pkg", 6 | "fct", 7 | "class" 8 | } 9 | 10 | -- layout and style 11 | local kTypes = pandoc.List({'article', 'codesnippet', 'bookreview', 'softwarereview'}) 12 | local kSuppress = pandoc.List({'title', 'headings', 'footer'}) 13 | 14 | local function setClassOption(meta, option) 15 | if meta['classoption'] == nil then 16 | meta['classoption'] = pandoc.List({}) 17 | end 18 | 19 | meta['classoption']:insert({ pandoc.Str(option)}) 20 | end 21 | 22 | local function printList(list) 23 | local result = '' 24 | local sep = '' 25 | for i,v in ipairs(list) do 26 | result = result .. sep .. v 27 | sep = ', ' 28 | end 29 | return result 30 | end 31 | 32 | return { 33 | { 34 | Span = function(el) 35 | -- read the span contents and emit correct output 36 | local contentStr = pandoc.utils.stringify(el.content) 37 | 38 | for i, mapping in ipairs(texMappings) do 39 | if #el.attr.classes == 1 and el.attr.classes:includes(mapping) then 40 | if quarto.doc.is_format("pdf") then 41 | return pandoc.RawInline("tex", "\\" .. mapping .. "{" .. contentStr .. "}" ) 42 | else 43 | return pandoc.Code(contentStr); 44 | end 45 | end 46 | end 47 | end, 48 | Meta = function(meta) 49 | if quarto.doc.is_format("pdf") then 50 | -- Authors output in the template uses a special separator 51 | -- to join authors (including wrapping to a new line) 52 | -- this computes the proper prefix and places it in the author metadata 53 | -- for use by the template 54 | local byAuthor = meta['by-author'] 55 | if byAuthor ~= nil then 56 | for i, author in ipairs(byAuthor) do 57 | local prefix = {pandoc.RawInline("tex ","")}; 58 | if i > 1 and i % 2 == 1 then 59 | prefix = {pandoc.RawInline("tex", "\\AND")} 60 | elseif i > 1 then 61 | prefix = {pandoc.RawInline("tex", "\\And")} 62 | end 63 | author['metadata']['latex-prefix'] = prefix 64 | end 65 | end 66 | 67 | -- read the journal settings 68 | local journal = meta['journal'] 69 | local type = nil 70 | local shortnames = nil 71 | local suppress = nil 72 | local jss = nil 73 | 74 | if journal ~= nil then 75 | type = journal['type'] 76 | shortnames = journal['cite-shortnames'] 77 | suppress = journal['suppress'] 78 | jss = journal['include-jss-layout'] 79 | end 80 | 81 | -- process the type 82 | if type ~= nil then 83 | type = pandoc.utils.stringify(type) 84 | if kTypes:includes(type) then 85 | setClassOption(meta, type) 86 | else 87 | error("Unknown type " .. type .. "\nPlease use one of " .. printList(kTypes)) 88 | end 89 | else 90 | setClassOption(meta, 'article') 91 | end 92 | 93 | -- process the citation variant 94 | if shortnames == true then 95 | setClassOption(meta, 'shortnames') 96 | end 97 | 98 | -- process the suppressed parts 99 | if suppress ~= nil then 100 | for i,v in ipairs(suppress) do 101 | s = pandoc.utils.stringify(v) 102 | if kSuppress:includes(s) then 103 | setClassOption(meta, 'no' .. s) 104 | else 105 | error("Unknown suppressed part " .. s .. "\nPlease use one of " .. printList(kSuppress)) 106 | end 107 | end 108 | end 109 | 110 | -- process switch for JSS layout 111 | if jss == false then 112 | setClassOption(meta, 'nojss') 113 | end 114 | 115 | -- make sure there is a plain title 116 | if meta['title'] ~= nil and meta['title-plain'] == nil then 117 | meta['title-plain'] = pandoc.utils.stringify(meta['title']) 118 | end 119 | end 120 | 121 | return meta 122 | end 123 | } 124 | } -------------------------------------------------------------------------------- /dev/predprob_mlm.R: -------------------------------------------------------------------------------- 1 | library(readr) 2 | library(lme4) 3 | library(arm) 4 | library(dplyr) 5 | library(ggplot2) 6 | 7 | pew1.w <- read_csv("dev/pew1_w.csv") 8 | 9 | t1m1 <- glmer(formula=meritocracy~ginicnty+income_i+ginicnty:income_i+income_cnty+black_cnty+ 10 | perc_bush04+pop_cnty+educ_i+age_i+gender_i+unemp_i+union_i+partyid_i+ 11 | ideo_i+attend_i+survid2006+survid2007+survid2009+(1+income_i|fips), 12 | data=pew1.w,family=binomial(link="logit")) 13 | summary(t1m1) 14 | 15 | # predicted probabilities with confidence intervals (see http://glmm.wikidot.com/faq under lme4) 16 | newdat <- pew1.w %>% summarise_each(funs(mean)) 17 | newdat <- newdat[rep(1, 200), ] # two values of var2 * 100 18 | newdat$ginicnty <- rep(seq(min(pew1.w$ginicnty, na.rm=T), max(pew1.w$ginicnty, na.rm=T), length.out = 100), times = 2) # Full observed range of ginicnty # times =2 from the value picked from var2 19 | newdat$income_i <- c(rep(quantile(pew1.w$income_i, .001), 100), rep(max(pew1.w$income_i), 100)) 20 | 21 | ## quantile -> min; user defined the value they want to pick 22 | 23 | # One imputed value falls below theoretical range of variable, use actual range instead by taking 0.1 percentile value 24 | newdat$fips <- NULL # mean FIPs meaningless (and causes error); not used anyway with re.form=NA 25 | newdat$inc[1:100] <- "low" 26 | newdat$inc[101:200] <- "high" 27 | 28 | mm <- model.matrix(terms(t1m1), newdat) 29 | newdat$pred <- predict(t1m1, newdat, re.form=NA, type="link") 30 | pvar1 <- diag(mm %*% tcrossprod(vcov(t1m1), mm)) # FE variance only (no RE variance) 31 | newdat <- data.frame( 32 | newdat, 33 | pp = invlogit(newdat$pred), 34 | pplo = invlogit(newdat$pred+qnorm(.025)*sqrt(pvar1)), 35 | pphi = invlogit(newdat$pred+qnorm(.975)*sqrt(pvar1)) 36 | ) 37 | 38 | t1m1.pp <- ggplot(newdat, aes(x=ginicnty, y=pp, colour=inc)) + geom_line() + 39 | labs(x = "County Income Inequality", 40 | y = "Probability of Rejecting Meritocracy") + 41 | geom_ribbon(aes(ymin = pplo, ymax = pphi, fill=inc, linetype=NA), 42 | alpha = .25) + 43 | geom_text(aes(.5, .17, label = "Highest Income", colour="high"), size=4.5) + 44 | geom_text(aes(.25, .32, label = "Lowest Income", colour="low"), size=4.5) + 45 | scale_colour_grey(end=.6) + scale_fill_grey(end=.6) + 46 | theme_bw() + theme(legend.position="none") 47 | #ggsave(file="t1m1_pp.pdf", width=8, height=5.25) 48 | 49 | 50 | ### consider a (version of) this code for flat models 51 | pred_probs <- function(m, var1, var2, var2_vals, 52 | times = 20, sims = 1000) { 53 | m_sims <- arm::sim(m, sims) 54 | df <- data.frame(m@frame) 55 | df[[names(m@flist)]] <- NULL # omit L2 var 56 | names(df)[1] <- "(Intercept)" # replace DV with intercept 57 | df$`(Intercept)` <- 1 58 | 59 | # Find name of interaction term 60 | ifelse(var1 == var2, var12 <- paste0("I(", var1, "^2)"), 61 | var12 <- paste0(var2, ":", var1)) 62 | if (!var12 %in% unlist(dimnames(m@pp$X)[2])) 63 | var12 <- paste0(var1, ":", var2) 64 | if (!var12 %in% unlist(dimnames(m@pp$X)[2])) 65 | stop(paste("Model does not include the interaction of", var1, "and", 66 | var2, ".")) 67 | 68 | iv_medians <- summarize_each(df, funs(median(., na.rm = TRUE))) 69 | 70 | fake_data <- iv_medians[rep(1:nrow(iv_medians), each=times*length(var2_vals)), ] 71 | fake_data[[var1]] <- with(df, rep(seq(min(get(var1)), max(get(var1)), length.out=times), 72 | times=length(var2_vals))) 73 | fake_data[[var2]] <- rep(var2_vals, each=times) 74 | fake_data[[var12]] <- fake_data[[var1]] * fake_data[[var2]] 75 | 76 | pp <- rowMeans(plogis(data.matrix(fake_data) %*% t(data.matrix(m_sims@fixef)))) 77 | row_quantiles <- function (x, probs) { 78 | naValue <- NA 79 | storage.mode(naValue) <- storage.mode(x) 80 | nrow <- nrow(x) 81 | q <- matrix(naValue, nrow = nrow, ncol = length(probs)) 82 | if (nrow > 0L) { 83 | t <- quantile(x[1L, ], probs = probs) 84 | colnames(q) <- names(t) 85 | q[1L, ] <- t 86 | if (nrow >= 2L) { 87 | for (rr in 2:nrow) { 88 | q[rr, ] <- quantile(x[rr, ], probs = probs) 89 | } 90 | } 91 | } 92 | else { 93 | t <- quantile(0, probs = probs) 94 | colnames(q) <- names(t) 95 | } 96 | q <- drop(q) 97 | q 98 | } 99 | pp_bounds <- row_quantiles(plogis(data.matrix(fake_data) %*% t(data.matrix(m_sims@fixef))), prob = c(.025, .975)) 100 | pp <- cbind(pp, pp_bounds) 101 | pp <- pp*100 102 | colnames(pp) <- c("est", "lb", "ub") 103 | pp <- cbind(fake_data, pp) 104 | pp$income <- as.factor(pp$income) 105 | return(pp) 106 | } -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 |
    YEAR: 2015
    60 | COPYRIGHT HOLDER: Frederick Solt, Yue HU
    61 | 
    62 | 63 |
    64 | 65 | 68 | 69 |
    70 | 71 | 72 | 73 |
    76 | 77 |
    78 |

    Site built with pkgdown 2.0.7.

    79 |
    80 | 81 |
    82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 |
    60 |

    All vignettes

    61 |

    62 | 63 |
    interplot: Plot the Effects of Variables in Interaction Terms
    64 |
    65 |
    66 |
    67 |
    68 | 69 | 70 |
    73 | 74 |
    75 |

    Site built with pkgdown 2.0.7.

    76 |
    77 | 78 |
    79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /vignettes/vignette.bib.bak: -------------------------------------------------------------------------------- 1 | % Encoding: UTF-8 2 | 3 | @Article{Brambor2006, 4 | author = {Brambor, Thomas and Clark, William Roberts and Golder, Matt}, 5 | title = {Understanding Interaction Models: Improving Empirical Analyses}, 6 | journal = {Political Analysis}, 7 | year = {2006}, 8 | volume = {14}, 9 | number = {1}, 10 | pages = {63--82}, 11 | __markedentry = {[Sammo:6]}, 12 | publisher = {SPM-PMSAPSA} 13 | } 14 | 15 | @Book{Aiken1991, 16 | title = {Multiple regression: Testing and interpreting interactionsMultiple Regression: Testing and Interpreting Interactions}, 17 | publisher = {Sage}, 18 | year = {1991}, 19 | author = {Aiken, Leona S and West, Stephen G and Reno, Raymond R} 20 | } 21 | 22 | @Article{WrightJr1976, 23 | author = {Wright Jr, Gerald C}, 24 | title = {Linear Models for Evaluating Conditional Relationships}, 25 | journal = {American Journal of Political Science}, 26 | year = {1976}, 27 | pages = {349--373}, 28 | __markedentry = {[Sammo:]}, 29 | publisher = {JSTOR} 30 | } 31 | 32 | @Article{Berry2012, 33 | author = {Berry, William D and Golder, Matt and Milton, Daniel}, 34 | title = {Improving Tests of Theories Positing Interaction}, 35 | journal = {Journal of Politics}, 36 | year = {2012}, 37 | volume = {74}, 38 | number = {3}, 39 | pages = {653--671}, 40 | publisher = {Cambridge Univ Press} 41 | } 42 | 43 | @Unpublished{Hainmueller2016, 44 | author = {Hainmueller, Jens and Mummolo, Jonathan and Xu, Yiqing}, 45 | title = {How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice}, 46 | year = {2016}, 47 | timestamp = {2017-07-20}, 48 | url = {https://ssrn.com/abstract=2739221}, 49 | } 50 | 51 | @Article{Clark2006, 52 | author = {Clark, William Roberts and Gilligan, Michael J and Golder, Matt}, 53 | title = {A Simple Multivariate Test for Asymmetric Hypotheses}, 54 | journal = {Political Analysis}, 55 | year = {2006}, 56 | volume = {14}, 57 | number = {3}, 58 | pages = {311--331}, 59 | publisher = {SPM-PMSAPSA} 60 | } 61 | 62 | @Article{Berry2016, 63 | author = {Berry, William D and DeMeritt, Jacqueline HR and Esarey, Justin}, 64 | title = {Bias and Overconfidence in Parametric Models of Interactive Processes}, 65 | journal = {American Journal of Political Science}, 66 | year = {2016}, 67 | volume = {60}, 68 | number = {2}, 69 | pages = {521--539}, 70 | publisher = {Wiley Online Library}, 71 | } 72 | 73 | @Unpublished{Esarey2017, 74 | author = {Esarey, Justin and Sumner, Jane Lawrence}, 75 | title = {Marginal Effects in Interaction Models: Determining and Controlling the False Positive Rate}, 76 | year = {2017}, 77 | timestamp = {2017-07-20}, 78 | url = {http://jee3.web.rice.edu/interaction-overconfidence.pdf}, 79 | } 80 | 81 | @Article{Braumoeller2004, 82 | author = {Braumoeller, Bear F}, 83 | title = {Hypothesis Testing and Multiplicative Interaction Terms}, 84 | journal = {International Organization}, 85 | year = {2004}, 86 | volume = {58}, 87 | number = {4}, 88 | pages = {807--820}, 89 | publisher = {Cambridge University Press}, 90 | } 91 | 92 | @Article{Benjamini1995, 93 | author = {Benjamini, Yoav and Hochberg, Yosef}, 94 | title = {Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing}, 95 | journal = {Journal of the Royal Statistical Society. Series B (Methodological)}, 96 | year = {1995}, 97 | pages = {289--300}, 98 | publisher = {JSTOR}, 99 | } 100 | 101 | @Article{Hanmer2013, 102 | author = {Hanmer, Michael J. and Ozan Kalkan, Kerem}, 103 | title = {Behind the Curve: Clarifying the Best Approach to Calculating Predicted Probabilities and Marginal Effects from Limited Dependent Variable Models}, 104 | journal = {American Journal of Political Science}, 105 | year = {2013}, 106 | volume = {57}, 107 | number = {1}, 108 | pages = {263--277}, 109 | issn = {1540-5907}, 110 | abstract = {Models designed for limited dependent variables are increasingly common in political science. Researchers estimating such models often give little attention to the coefficient estimates and instead focus on marginal effects, predicted probabilities, predicted counts, etc. Since the models are nonlinear, the estimated effects are sensitive to how one generates the predictions. The most common approach involves estimating the effect for the “average case.” But this approach creates a weaker connection between the results and the larger goals of the research enterprise and is thus less preferable than the observed-value approach. That is, rather than seeking to understand the effect for the average case, the goal is to obtain an estimate of the average effect in the population. In addition to the theoretical argument in favor of the observed-value approach, we illustrate via an empirical example and Monte Carlo simulations that the two approaches can produce substantively different results.}, 111 | doi = {10.1111/j.1540-5907.2012.00602.x}, 112 | publisher = {Blackwell Publishing Inc}, 113 | timestamp = {2017-08-06}, 114 | url = {http://dx.doi.org/10.1111/j.1540-5907.2012.00602.x}, 115 | } 116 | 117 | @Comment{jabref-meta: databaseType:bibtex;} 118 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • interplot 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
    24 |
    73 | 74 | 75 | 76 | 77 |
    78 |
    79 | 82 | 83 | Content not found. Please use links in the navbar. 84 | 85 |
    86 | 87 | 91 | 92 |
    93 | 94 | 95 | 96 |
    100 | 101 |
    102 |

    103 |

    Site built with pkgdown 2.0.7.

    104 |
    105 | 106 |
    107 |
    108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /man/interplot.lmerMod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot_mlm.R 3 | \name{interplot.lmerMod} 4 | \alias{interplot.lmerMod} 5 | \title{Plot Conditional Coefficients in Mixed-Effects Models with Interaction Terms} 6 | \usage{ 7 | \method{interplot}{lmerMod}( 8 | m, 9 | var1, 10 | var2, 11 | plot = TRUE, 12 | steps = NULL, 13 | ci = 0.95, 14 | adjCI = FALSE, 15 | hist = FALSE, 16 | var2_dt = NA, 17 | predPro = FALSE, 18 | var2_vals = NULL, 19 | point = FALSE, 20 | sims = 5000, 21 | xmin = NA, 22 | xmax = NA, 23 | ercolor = NA, 24 | esize = 0.5, 25 | ralpha = 0.5, 26 | rfill = "grey70", 27 | stats_cp = "none", 28 | txt_caption = NULL, 29 | facet_labs = NULL, 30 | ... 31 | ) 32 | } 33 | \arguments{ 34 | \item{m}{A model object including an interaction term, or, alternately, a data frame recording conditional coefficients.} 35 | 36 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 37 | 38 | \item{var2}{The name (as a string) of the other variable in the interaction term.} 39 | 40 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 41 | 42 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 43 | 44 | \item{ci}{A numeric value defining the confidence intervals. The default value is 95\% (0.95).} 45 | 46 | \item{adjCI}{Not working for `lmer` outputs yet.} 47 | 48 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 49 | 50 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 51 | 52 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an object of class `glmerMod` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 53 | 54 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 55 | 56 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 57 | 58 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 59 | 60 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 61 | 62 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 63 | 64 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 65 | 66 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 67 | 68 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 69 | 70 | \item{rfill}{A character value indicating the filling color of the ribbon.} 71 | 72 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 73 | 74 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 75 | 76 | \item{facet_labs}{An optional character vector of facet labels to be used when plotting an interaction with a factor variable.} 77 | 78 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 79 | } 80 | \value{ 81 | The function returns a \code{ggplot} object. 82 | } 83 | \description{ 84 | \code{interplot.mlm} is a method to calculate conditional coefficient estimates from the results of multilevel (mixed-effects) regression models with interaction terms. 85 | } 86 | \details{ 87 | \code{interplot.mlm} is a S3 method from the \code{interplot}. It works on mixed-effects objects with class \code{lmerMod} and \code{glmerMod}. 88 | 89 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 90 | 91 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 92 | \itemize{ 93 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 94 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 95 | } 96 | 97 | See an illustration in the package vignette. 98 | } 99 | -------------------------------------------------------------------------------- /vignettes/interplot-vignette.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE----------------------------------------------------- 2 | knitr::opts_chunk$set( 3 | message = FALSE, 4 | warning = FALSE, 5 | dpi = 300 6 | ) 7 | 8 | ## ----------------------------------------------------------------------------- 9 | data(mtcars) #load the data 10 | 11 | ## ----------------------------------------------------------------------------- 12 | m_cyl <- lm(mpg ~ wt * cyl, data = mtcars) 13 | summary(m_cyl) 14 | 15 | ## ----out.width="80%"---------------------------------------------------------- 16 | library(interplot) 17 | 18 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt") 19 | 20 | ## ----out.width="80%"---------------------------------------------------------- 21 | interplot(m = m_cyl, var1 = "wt", var2 = "cyl") 22 | 23 | ## ----out.width="80%"---------------------------------------------------------- 24 | interplot(m = m_cyl, var1 = "wt", var2 = "cyl", ci = .9, point = T) 25 | 26 | ## ----out.width="80%"---------------------------------------------------------- 27 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt", point = T) + 28 | # changing the angle of x labels for a clearer vision 29 | theme(axis.text.x = element_text(angle=90)) 30 | 31 | ## ----out.width="80%"---------------------------------------------------------- 32 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt") + 33 | # Add labels for X and Y axes 34 | xlab("Automobile Weight (thousands lbs)") + 35 | ylab("Estimated Coefficient for\nNumber of Cylinders") + 36 | # Change the background 37 | theme_bw() + 38 | # Add the title 39 | ggtitle("Estimated Coefficient of Engine Cylinders \non Mileage by Automobile Weight") + 40 | theme(plot.title = element_text(face="bold")) + 41 | # Add a horizontal line at y = 0 42 | geom_hline(yintercept = 0, linetype = "dashed") 43 | 44 | ## ----out.width="80%"---------------------------------------------------------- 45 | interplot(m = m_cyl, var1 = "wt", var2 = "cyl", ercolor = "blue", esize = 1.5) + 46 | geom_point(size = 2, color = "red") 47 | 48 | ## ----out.width="80%"---------------------------------------------------------- 49 | m_wt <- lm(mpg ~ wt + I(wt^2), data = mtcars) 50 | 51 | interplot(m = m_wt, var1 = "wt", var2 = "wt") 52 | 53 | ## ----out.width="80%"---------------------------------------------------------- 54 | mtcars$gear <- factor(mtcars$gear) 55 | m_gear <- lm(mpg ~ gear * wt, data = mtcars) 56 | 57 | interplot(m = m_gear, var1 = "wt", var2 = "gear") 58 | 59 | ## ----out.width="80%"---------------------------------------------------------- 60 | interplot(m = m_gear, var1 = "wt", var2 = "gear", facet_labs = c("4-speed", "5-speed")) 61 | 62 | ## ----out.width="80%"---------------------------------------------------------- 63 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt", hist = TRUE) + 64 | geom_hline(yintercept = 0, linetype = "dashed") 65 | 66 | ## ----out.width="80%"---------------------------------------------------------- 67 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt", hist = TRUE) + 68 | aes(color = "pink") + theme(legend.position="none") + # geom_line(color = "pink") + 69 | geom_hline(yintercept = 0, linetype = "dashed") 70 | 71 | ## ----------------------------------------------------------------------------- 72 | set.seed(313) 73 | 74 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt", stats_cp = "ci") 75 | 76 | ## ----------------------------------------------------------------------------- 77 | set.seed(313) 78 | 79 | interplot(m = m_cyl, var1 = "cyl", var2 = "wt", stats_cp = "ci", 80 | txt_caption = "\n Source: Motor Trend Car Road Tests 1973.") 81 | 82 | ## ----out.width="80%"---------------------------------------------------------- 83 | stdCI_plot <- interplot(m = m_wt, var1 = "wt", var2 = "wt", adjCI = FALSE) + 84 | ggtitle("Marginal Effects with Standard CIs") 85 | adjCI_plot <- interplot(m = m_wt, var1 = "wt", var2 = "wt", adjCI = TRUE) + 86 | ggtitle("Marginal Effects with Adjusted CIs") 87 | 88 | library(gridExtra) 89 | grid.arrange(stdCI_plot, adjCI_plot, ncol = 2) 90 | 91 | ## ----out.width="80%"---------------------------------------------------------- 92 | pew1.w <- read.csv("pew1_w.csv") 93 | 94 | m <- glm(formula=meritocracy~ginicnty+income_i+ginicnty:income_i+income_cnty+black_cnty+ 95 | perc_bush04+pop_cnty+educ_i+age_i+gender_i+unemp_i+union_i+partyid_i+ 96 | ideo_i+attend_i+survid2006+survid2007+survid2009, 97 | data=pew1.w,family=binomial(link="logit")) 98 | 99 | plot_avg <- interplot(m, var1 = "ginicnty",var2 = "income_i", predPro = FALSE) + 100 | ggtitle("Average Conditional Effects") 101 | 102 | plot_3val <- interplot(m, var1 = "ginicnty",var2 = "income_i", predPro = TRUE, var2_vals = c(min(pew1.w$income_i), max(pew1.w$income_i))) + 103 | ggtitle("Conditional Predicted Probabilities for \nCitizens with Low and High Incomes") + 104 | scale_colour_discrete(guide = guide_legend(title = "Income"), labels = c("Low", "High")) + 105 | scale_fill_discrete(guide = guide_legend(title = "Income"), labels = c("Low", "High")) + 106 | theme(legend.position = c(0, .8), legend.justification = c(0, .5)) 107 | 108 | grid.arrange(plot_avg, plot_3val, ncol = 2) 109 | 110 | ## ----out.width="80%"---------------------------------------------------------- 111 | # Create a fake dataset of conditional effects 112 | fake <- rnorm(100, 0, 1) 113 | coef1 <- fake * sample(.5:2.5, 100, replace = T) 114 | lb <- coef1 - .5 115 | ub <- coef1 + .5 116 | 117 | df_fake <- data.frame(cbind(fake, coef1, lb, ub)) 118 | 119 | # Use interplot directly with the dataset 120 | interplot(df_fake) 121 | 122 | ## ----out.width="80%"---------------------------------------------------------- 123 | var2_fake <- fake 124 | # Set `hist` to TRUE is required to superimpose a histogram. 125 | interplot(df_fake, hist = TRUE, var2_dt = var2_fake) 126 | ## The ribbon and histogram do not fit. This is just an illustration 127 | 128 | -------------------------------------------------------------------------------- /man/interplot.mlmmi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot_mlmmi.R 3 | \name{interplot.mlmmi} 4 | \alias{interplot.mlmmi} 5 | \title{Plot Conditional Coefficients in Mixed-Effects Models with Imputed Data and Interaction Terms} 6 | \usage{ 7 | \method{interplot}{mlmmi}( 8 | m, 9 | var1, 10 | var2, 11 | plot = TRUE, 12 | steps = NULL, 13 | ci = 0.95, 14 | adjCI = FALSE, 15 | hist = FALSE, 16 | var2_dt = NA, 17 | predPro = FALSE, 18 | var2_vals = NULL, 19 | point = FALSE, 20 | sims = 5000, 21 | xmin = NA, 22 | xmax = NA, 23 | ercolor = NA, 24 | esize = 0.5, 25 | ralpha = 0.5, 26 | rfill = "grey70", 27 | stats_cp = "none", 28 | txt_caption = NULL, 29 | facet_labs = NULL, 30 | ... 31 | ) 32 | } 33 | \arguments{ 34 | \item{m}{A model object including an interaction term, or, alternately, a data frame recording conditional coefficients.} 35 | 36 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 37 | 38 | \item{var2}{The name (as a string) of the other variable in the interaction term.} 39 | 40 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 41 | 42 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 43 | 44 | \item{ci}{A numeric value defining the confidence intervals. The default value is 95\% (0.95).} 45 | 46 | \item{adjCI}{Not working for `lmer` outputs yet.} 47 | 48 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 49 | 50 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 51 | 52 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an object of class `glmerMod` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 53 | 54 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 55 | 56 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 57 | 58 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 59 | 60 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 61 | 62 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 63 | 64 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 65 | 66 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 67 | 68 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 69 | 70 | \item{rfill}{A character value indicating the filling color of the ribbon.} 71 | 72 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 73 | 74 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 75 | 76 | \item{facet_labs}{An optional character vector of facet labels to be used when plotting an interaction with a factor variable.} 77 | 78 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 79 | } 80 | \value{ 81 | The function returns a \code{ggplot} object. 82 | } 83 | \description{ 84 | \code{interplot.mlmmi} is a method to calculate conditional coefficient estimates from the results of multilevel (mixed-effects) regression models with interaction terms and multiply imputed data. 85 | } 86 | \details{ 87 | \code{interplot.mlmmi} and \code{interplot.gmlmmi} are S3 methods from the \code{interplot}. It works on lists of mixed-effects objects with class \code{lmerMod} and \code{glmerMod} generated by \code{mitools} and \code{lme4}. 88 | 89 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 90 | 91 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 92 | \itemize{ 93 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 94 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 95 | } 96 | 97 | See an illustration in the package vignette. 98 | } 99 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 |
    56 | 59 | 60 | 61 |
    • 62 |

      Frederick Solt. Author. 63 |

      64 |
    • 65 |
    • 66 |

      Yue Hu. Author, maintainer. 67 |

      68 |
    • 69 |
    • 70 |

      Brenton Kenkel. Contributor. 71 |

      72 |
    • 73 |
    74 |
    75 |
    76 |

    Citation

    77 | Source: DESCRIPTION 78 |
    79 |
    80 | 81 | 82 |

    Solt F, Hu Y (2024). 83 | interplot: Plot the Effects of Variables in Interaction Terms. 84 | R package version 0.2.3. 85 |

    86 |
    @Manual{,
     87 |   title = {interplot: Plot the Effects of Variables in Interaction Terms},
     88 |   author = {Frederick Solt and Yue Hu},
     89 |   year = {2024},
     90 |   note = {R package version 0.2.3},
     91 | }
    92 | 93 |
    94 | 95 |
    96 | 97 | 98 | 99 |
    102 | 103 |
    104 |

    Site built with pkgdown 2.0.7.

    105 |
    106 | 107 |
    108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /man/interplot.plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot_plot.R 3 | \name{interplot.plot} 4 | \alias{interplot.plot} 5 | \title{Plot Conditional Coefficients in Models with Interaction Terms} 6 | \usage{ 7 | \method{interplot}{plot}( 8 | m, 9 | var1 = NULL, 10 | var2 = NULL, 11 | plot = TRUE, 12 | steps = NULL, 13 | ci = 0.95, 14 | adjCI = FALSE, 15 | hist = FALSE, 16 | var2_dt = NULL, 17 | predPro = FALSE, 18 | var2_vals = NULL, 19 | point = FALSE, 20 | sims = 5000, 21 | xmin = NA, 22 | xmax = NA, 23 | ercolor = NA, 24 | esize = 0.5, 25 | ralpha = 0.5, 26 | rfill = "grey70", 27 | stats_cp = "none", 28 | txt_caption = NULL, 29 | ci_diff = NULL, 30 | ks_diff = NULL, 31 | ... 32 | ) 33 | } 34 | \arguments{ 35 | \item{m}{A model object including an interaction term, or, alternately, a data frame recording conditional coefficients. This data frame should includes four columns: 36 | \itemize{ 37 | \item fake: The sequence of \code{var1} (the item whose effect will be conditioned on in the interaction); 38 | \item coef1: The point estimates of the coefficient of \code{var1} at each break point. 39 | \item ub: The upper bound of the simulated 95\% CI. 40 | \item lb: The lower bound of the simulated 95\% CI. 41 | }} 42 | 43 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 44 | 45 | \item{var2}{The name (as a string) of the other variable in the interaction term.} 46 | 47 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 48 | 49 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 50 | 51 | \item{ci}{is a numeric value inherited from the data wrangling functions in this package. Adding it here is just for the method consistency.} 52 | 53 | \item{adjCI}{Succeeded from the data management functions in `interplot` package.} 54 | 55 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 56 | 57 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 58 | 59 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an output of a general linear model (class `glm` or `glmerMod`) and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 60 | 61 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 62 | 63 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 64 | 65 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 66 | 67 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 68 | 69 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 70 | 71 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 72 | 73 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 74 | 75 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 76 | 77 | \item{rfill}{A character value indicating the filling color of the ribbon.} 78 | 79 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 80 | 81 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 82 | 83 | \item{ci_diff}{A numerical vector with a pair of values indicating the confidence intervals of the difference between \code{var1} and \code{var2}.} 84 | 85 | \item{ks_diff}{A \code{ks.test} object of the effect of \code{var1} conditioned on \code{var2}.} 86 | 87 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 88 | } 89 | \value{ 90 | The function returns a \code{ggplot} object. 91 | } 92 | \description{ 93 | Graph based on the data frame of statistics about the conditional effect of an interaction. 94 | } 95 | \details{ 96 | \code{interplot.plot} is a S3 method from the \code{interplot}. It generates plots of conditional coefficients. 97 | 98 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 99 | 100 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 101 | \itemize{ 102 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 103 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 104 | } 105 | 106 | See an illustration in the package vignette. 107 | } 108 | -------------------------------------------------------------------------------- /docs/CONDUCT.html: -------------------------------------------------------------------------------- 1 | 2 | Contributor Code of Conduct • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 |
    60 | 61 |

    As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

    62 |

    We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

    63 |

    Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

    64 |

    Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

    65 |

    Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

    66 |

    This Code of Conduct is adapted from the Contributor Covenant (http:contributor-covenant.org), version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/

    67 |
    68 | 69 |
    70 | 71 | 74 | 75 |
    76 | 77 | 78 | 79 |
    82 | 83 |
    84 |

    Site built with pkgdown 2.0.7.

    85 |
    86 | 87 |
    88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /man/interplot.default.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot_default.R 3 | \name{interplot.default} 4 | \alias{interplot.default} 5 | \title{Plot Conditional Coefficients in (Generalized) Linear Models with Interaction Terms} 6 | \source{ 7 | Benjamini, Yoav, and Yosef Hochberg. 1995. "Controlling the False 8 | Discovery Rate: A Practical and Powerful Approach to Multiple Testing". 9 | Journal of the Royal Statistical Society, Series B 57(1): 289--300. 10 | 11 | Brambor, Thomas, William Roberts Clark, and Matt Golder. 12 | "Understanding interaction models: Improving empirical analyses". Political 13 | Analysis 14.1 (2006): 63-82. 14 | 15 | Esarey, Justin, and Jane Lawrence Sumner. 2015. "Marginal Effects in 16 | Interaction Models: Determining and Controlling the False Positive Rate". 17 | URL: \url{http://jee3.web.rice.edu/interaction-overconfidence.pdf}. 18 | } 19 | \usage{ 20 | \method{interplot}{default}( 21 | m, 22 | var1, 23 | var2, 24 | plot = TRUE, 25 | steps = NULL, 26 | ci = 0.95, 27 | adjCI = FALSE, 28 | hist = FALSE, 29 | var2_dt = NA, 30 | predPro = FALSE, 31 | var2_vals = NULL, 32 | point = FALSE, 33 | sims = 1000, 34 | xmin = NA, 35 | xmax = NA, 36 | ercolor = NA, 37 | esize = 0.5, 38 | ralpha = 0.5, 39 | rfill = "grey70", 40 | stats_cp = "none", 41 | txt_caption = NULL, 42 | facet_labs = NULL, 43 | ... 44 | ) 45 | } 46 | \arguments{ 47 | \item{m}{A model object including an interaction term, or, alternately, a data frame recording conditional coefficients.} 48 | 49 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 50 | 51 | \item{var2}{The name (as a string) of the other variable in the interaction term.} 52 | 53 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 54 | 55 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 56 | 57 | \item{ci}{A numeric value defining the confidence intervals. The default value is 95\% (0.95).} 58 | 59 | \item{adjCI}{A logical value indication if applying the adjustment of confidence intervals to control the false discovery rate following the Esarey and Sumner (2017) procedure. (See also Benjamini and Hochberg 1995.) The default is FALSE; the plot presents the confidence intervals suggested by Brambor, Clark, and Golder (2006).} 60 | 61 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 62 | 63 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 64 | 65 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an object of class `glm` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 66 | 67 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 68 | 69 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 70 | 71 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 72 | 73 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 74 | 75 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 76 | 77 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 78 | 79 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 80 | 81 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 82 | 83 | \item{rfill}{A character value indicating the filling color of the ribbon.} 84 | 85 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 86 | 87 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 88 | 89 | \item{facet_labs}{An optional character vector of facet labels to be used when plotting an interaction with a factor variable.} 90 | 91 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 92 | } 93 | \value{ 94 | The function returns a \code{ggplot} object. 95 | } 96 | \description{ 97 | \code{interplot.default} is a method to calculate conditional coefficient estimates from the results of (generalized) linear regression models with interaction terms. 98 | } 99 | \details{ 100 | \code{interplot.default} is a S3 method from the \code{interplot}. It works on two classes of objects: 101 | \itemize{ 102 | \item Ordinary linear models (object class: \code{lm}); 103 | \item Generalized linear models (object class: \code{glm}). 104 | } 105 | 106 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 107 | 108 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 109 | \itemize{ 110 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 111 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 112 | } 113 | 114 | See an illustration in the package vignette. 115 | } 116 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 | 63 | 66 | 67 | 70 | 71 | 74 | 75 | 78 | 79 | 82 | 83 | 86 | 87 |
    60 |

    All functions

    61 |

    62 |
    64 |

    interplot(<default>)

    65 |

    Plot Conditional Coefficients in (Generalized) Linear Models with Interaction Terms

    68 |

    interplot(<lmerMod>)

    69 |

    Plot Conditional Coefficients in Mixed-Effects Models with Interaction Terms

    72 |

    interplot(<lmmi>)

    73 |

    Plot Conditional Coefficients in (Generalized) Linear Models with Imputed Data and Interaction Terms

    76 |

    interplot(<mlmmi>)

    77 |

    Plot Conditional Coefficients in Mixed-Effects Models with Imputed Data and Interaction Terms

    80 |

    interplot(<plot>)

    81 |

    Plot Conditional Coefficients in Models with Interaction Terms

    84 |

    interplot()

    85 |

    Plot Conditional Coefficients of a Variable in an Interaction Term

    88 | 89 | 92 |
    93 | 94 | 95 |
    98 | 99 |
    100 |

    Site built with pkgdown 2.0.7.

    101 |
    102 | 103 |
    104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /man/interplot.lmmi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot_mi.R 3 | \name{interplot.lmmi} 4 | \alias{interplot.lmmi} 5 | \title{Plot Conditional Coefficients in (Generalized) Linear Models with Imputed Data and Interaction Terms} 6 | \source{ 7 | Benjamini, Yoav, and Yosef Hochberg. 1995. "Controlling the False 8 | Discovery Rate: A Practical and Powerful Approach to Multiple Testing". 9 | Journal of the Royal Statistical Society, Series B 57(1): 289--300. 10 | 11 | Brambor, Thomas, William Roberts Clark, and Matt Golder. 12 | "Understanding interaction models: Improving empirical analyses". Political 13 | Analysis 14.1 (2006): 63-82. 14 | 15 | Esarey, Justin, and Jane Lawrence Sumner. 2015. "Marginal Effects in 16 | Interaction Models: Determining and Controlling the False Positive Rate". 17 | URL: \url{http://jee3.web.rice.edu/interaction-overconfidence.pdf}. 18 | } 19 | \usage{ 20 | \method{interplot}{lmmi}( 21 | m, 22 | var1, 23 | var2, 24 | plot = TRUE, 25 | steps = NULL, 26 | ci = 0.95, 27 | adjCI = FALSE, 28 | hist = FALSE, 29 | var2_dt = NA, 30 | predPro = FALSE, 31 | var2_vals = NULL, 32 | point = FALSE, 33 | sims = 5000, 34 | xmin = NA, 35 | xmax = NA, 36 | ercolor = NA, 37 | esize = 0.5, 38 | ralpha = 0.5, 39 | rfill = "grey70", 40 | stats_cp = "none", 41 | txt_caption = NULL, 42 | facet_labs = NULL, 43 | ... 44 | ) 45 | } 46 | \arguments{ 47 | \item{m}{A model object including an interaction term, or, alternately, a data frame recording conditional coefficients.} 48 | 49 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 50 | 51 | \item{var2}{The name (as a string) of the other variable in the interaction term.} 52 | 53 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 54 | 55 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 56 | 57 | \item{ci}{A numeric value defining the confidence intervals. The default value is 95\% (0.95).} 58 | 59 | \item{adjCI}{A logical value indication if applying the adjustment of confidence intervals to control the false discovery rate following the Esarey and Sumner (2017) procedure. (See also Benjamini and Hochberg 1995.) The default is FALSE; the plot presents the confidence intervals suggested by Brambor, Clark, and Golder (2006).} 60 | 61 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 62 | 63 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 64 | 65 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an object of class `glm` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 66 | 67 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 68 | 69 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 70 | 71 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 72 | 73 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 74 | 75 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 76 | 77 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 78 | 79 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 80 | 81 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 82 | 83 | \item{rfill}{A character value indicating the filling color of the ribbon.} 84 | 85 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 86 | 87 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 88 | 89 | \item{facet_labs}{An optional character vector of facet labels to be used when plotting an interaction with a factor variable.} 90 | 91 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 92 | } 93 | \value{ 94 | The function returns a \code{ggplot} object. 95 | } 96 | \description{ 97 | \code{interplot.mi} is a method to calculate conditional coefficient estimates from the results of (generalized) linear regression models with interaction terms and multiply imputed data. 98 | } 99 | \details{ 100 | \code{interplot.lmmi} and \code{interplot.glmmi} are S3 methods from the \code{interplot}. This function can work on interactions from results in the class of \code{list} generated by \code{mitools}. 101 | 102 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 103 | 104 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 105 | \itemize{ 106 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 107 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 108 | } 109 | 110 | 111 | See an illustration in the package vignette. 112 | } 113 | \examples{ 114 | 115 | library(interplot) 116 | library(mitools) 117 | 118 | data(smi) 119 | model1 <- with(smi, glm(drinkreg ~ wave * sex, family = binomial())) 120 | 121 | interplot(model1, var1 = "sex", var2 = "wave") 122 | 123 | } 124 | -------------------------------------------------------------------------------- /vignettes/vignette.bib: -------------------------------------------------------------------------------- 1 | % Encoding: UTF-8 2 | 3 | @Article{Brambor2006, 4 | author = {Brambor, Thomas and Clark, William Roberts and Golder, Matt}, 5 | title = {Understanding Interaction Models: Improving Empirical Analyses}, 6 | journal = {Political Analysis}, 7 | year = {2006}, 8 | volume = {14}, 9 | number = {1}, 10 | pages = {63--82}, 11 | __markedentry = {[Sammo:6]}, 12 | publisher = {SPM-PMSAPSA} 13 | } 14 | 15 | @Book{Aiken1991, 16 | title = {Multiple regression: Testing and interpreting interactionsMultiple Regression: Testing and Interpreting Interactions}, 17 | publisher = {Sage}, 18 | year = {1991}, 19 | author = {Aiken, Leona S and West, Stephen G and Reno, Raymond R} 20 | } 21 | 22 | @Article{WrightJr1976, 23 | author = {Wright Jr, Gerald C}, 24 | title = {Linear Models for Evaluating Conditional Relationships}, 25 | journal = {American Journal of Political Science}, 26 | year = {1976}, 27 | pages = {349--373}, 28 | __markedentry = {[Sammo:]}, 29 | publisher = {JSTOR} 30 | } 31 | 32 | @Article{Berry2012, 33 | author = {Berry, William D and Golder, Matt and Milton, Daniel}, 34 | title = {Improving Tests of Theories Positing Interaction}, 35 | journal = {Journal of Politics}, 36 | year = {2012}, 37 | volume = {74}, 38 | number = {3}, 39 | pages = {653--671}, 40 | publisher = {Cambridge Univ Press} 41 | } 42 | 43 | @Unpublished{Hainmueller2016, 44 | author = {Hainmueller, Jens and Mummolo, Jonathan and Xu, Yiqing}, 45 | title = {How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice}, 46 | year = {2016}, 47 | timestamp = {2017-07-20}, 48 | url = {https://www.ssrn.com/abstract=2739221}, 49 | } 50 | 51 | @Article{Clark2006, 52 | author = {Clark, William Roberts and Gilligan, Michael J and Golder, Matt}, 53 | title = {A Simple Multivariate Test for Asymmetric Hypotheses}, 54 | journal = {Political Analysis}, 55 | year = {2006}, 56 | volume = {14}, 57 | number = {3}, 58 | pages = {311--331}, 59 | publisher = {SPM-PMSAPSA} 60 | } 61 | 62 | @Article{Berry2016, 63 | author = {Berry, William D and DeMeritt, Jacqueline HR and Esarey, Justin}, 64 | title = {Bias and Overconfidence in Parametric Models of Interactive Processes}, 65 | journal = {American Journal of Political Science}, 66 | year = {2016}, 67 | volume = {60}, 68 | number = {2}, 69 | pages = {521--539}, 70 | publisher = {Wiley Online Library}, 71 | } 72 | 73 | @Unpublished{Esarey2017, 74 | author = {Esarey, Justin and Sumner, Jane Lawrence}, 75 | title = {Marginal Effects in Interaction Models: Determining and Controlling the False Positive Rate}, 76 | year = {2017}, 77 | timestamp = {2017-07-20}, 78 | url = {http://jee3.web.rice.edu/interaction-overconfidence.pdf}, 79 | } 80 | 81 | @Article{Braumoeller2004, 82 | author = {Braumoeller, Bear F}, 83 | title = {Hypothesis Testing and Multiplicative Interaction Terms}, 84 | journal = {International Organization}, 85 | year = {2004}, 86 | volume = {58}, 87 | number = {4}, 88 | pages = {807--820}, 89 | publisher = {Cambridge University Press}, 90 | } 91 | 92 | @Article{Benjamini1995, 93 | author = {Benjamini, Yoav and Hochberg, Yosef}, 94 | title = {Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing}, 95 | journal = {Journal of the Royal Statistical Society. Series B (Methodological)}, 96 | year = {1995}, 97 | pages = {289--300}, 98 | publisher = {JSTOR}, 99 | } 100 | 101 | @Article{Hanmer2013, 102 | author = {Hanmer, Michael J. and Ozan Kalkan, Kerem}, 103 | title = {Behind the Curve: Clarifying the Best Approach to Calculating Predicted Probabilities and Marginal Effects from Limited Dependent Variable Models}, 104 | journal = {American Journal of Political Science}, 105 | year = {2013}, 106 | volume = {57}, 107 | number = {1}, 108 | pages = {263--277}, 109 | issn = {1540-5907}, 110 | abstract = {Models designed for limited dependent variables are increasingly common in political science. Researchers estimating such models often give little attention to the coefficient estimates and instead focus on marginal effects, predicted probabilities, predicted counts, etc. Since the models are nonlinear, the estimated effects are sensitive to how one generates the predictions. The most common approach involves estimating the effect for the “average case.” But this approach creates a weaker connection between the results and the larger goals of the research enterprise and is thus less preferable than the observed-value approach. That is, rather than seeking to understand the effect for the average case, the goal is to obtain an estimate of the average effect in the population. In addition to the theoretical argument in favor of the observed-value approach, we illustrate via an empirical example and Monte Carlo simulations that the two approaches can produce substantively different results.}, 111 | doi = {10.1111/j.1540-5907.2012.00602.x}, 112 | publisher = {Blackwell Publishing Inc}, 113 | timestamp = {2017-08-06}, 114 | url = {http://dx.doi.org/10.1111/j.1540-5907.2012.00602.x}, 115 | } 116 | 117 | @Article{Solt2016, 118 | author = {Solt, Frederick and Hu, Yue and Hudson, Kevan and Song, Jungmin and Yu, Dong Erico}, 119 | title = {Economic Inequality and Belief in Meritocracy in the United States}, 120 | journal = {Research \& Politics}, 121 | year = {2016}, 122 | volume = {3}, 123 | number = {4}, 124 | pages = {1--7}, 125 | abstract = {How does the context of income inequality in which people live affect their belief in meritocracy, the ability to get ahead through hard work? A prominent recent study by Newman, Johnston, and Lown argues that, consistent with the conflict theory, exposure to higher levels of local income inequality leads lower-income people to become more likely to reject—and higher-income people to become more likely to accept—the dominant United States ideology of meritocracy. Here, we show that this conclusion is not supported by the studys own reported results and that even these results depend on pooling three distinctly different measures of meritocracy into a single analysis. We then demonstrate that analysis of a larger and more representative survey employing a single consistent measure of the dependent variable yields the opposite conclusion. Consistent with the relative power theory, among those with lower incomes, local contexts of greater inequality are associated with more widespread belief that people can get ahead if they are willing to work hard.}, 126 | date = {2017-06-14}, 127 | doi = {10.1177/2053168016672101}, 128 | eprint = {http://rap.sagepub.com/content/3/4/2053168016672101.full.pdf}, 129 | publisher = {SAGE Publications}, 130 | timestamp = {2017-06-14}, 131 | url = {http://rap.sagepub.com/content/3/4/2053168016672101}, 132 | urldate = {2017-06-14}, 133 | } 134 | 135 | @Comment{jabref-meta: databaseType:bibtex;} 136 | -------------------------------------------------------------------------------- /dev/jss/jss_interplot.bib: -------------------------------------------------------------------------------- 1 | % Encoding: UTF-8 2 | 3 | @Article{Brambor2006, 4 | author = {Brambor, Thomas and Clark, William Roberts and Golder, Matt}, 5 | title = {Understanding Interaction Models: Improving Empirical Analyses}, 6 | journal = {Political Analysis}, 7 | year = {2006}, 8 | volume = {14}, 9 | number = {1}, 10 | pages = {63--82}, 11 | __markedentry = {[Sammo:6]}, 12 | publisher = {SPM-PMSAPSA} 13 | } 14 | 15 | @Book{Aiken1991, 16 | title = {Multiple regression: Testing and interpreting interactionsMultiple Regression: Testing and Interpreting Interactions}, 17 | publisher = {Sage}, 18 | year = {1991}, 19 | author = {Aiken, Leona S and West, Stephen G and Reno, Raymond R} 20 | } 21 | 22 | @Article{WrightJr1976, 23 | author = {Wright Jr, Gerald C}, 24 | title = {Linear Models for Evaluating Conditional Relationships}, 25 | journal = {American Journal of Political Science}, 26 | year = {1976}, 27 | pages = {349--373}, 28 | __markedentry = {[Sammo:]}, 29 | publisher = {JSTOR} 30 | } 31 | 32 | @Article{Berry2012, 33 | author = {Berry, William D and Golder, Matt and Milton, Daniel}, 34 | title = {Improving Tests of Theories Positing Interaction}, 35 | journal = {Journal of Politics}, 36 | year = {2012}, 37 | volume = {74}, 38 | number = {3}, 39 | pages = {653--671}, 40 | publisher = {Cambridge University Press} 41 | } 42 | 43 | @Article{Hainmueller2019, 44 | author = {Hainmueller, Jens and Mummolo, Jonathan and Xu, Yiqing}, 45 | title = {How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice}, 46 | journal = {Political Analysis}, 47 | year = {2012}, 48 | volume = {27}, 49 | number = {2}, 50 | pages = {163-192}, 51 | publisher = {SAGE} 52 | } 53 | 54 | @Article{Clark2006, 55 | author = {Clark, William Roberts and Gilligan, Michael J and Golder, Matt}, 56 | title = {A Simple Multivariate Test for Asymmetric Hypotheses}, 57 | journal = {Political Analysis}, 58 | year = {2006}, 59 | volume = {14}, 60 | number = {3}, 61 | pages = {311--331}, 62 | publisher = {SPM-PMSAPSA} 63 | } 64 | 65 | @Article{Berry2016, 66 | author = {Berry, William D and DeMeritt, Jacqueline HR and Esarey, Justin}, 67 | title = {Bias and Overconfidence in Parametric Models of Interactive Processes}, 68 | journal = {American Journal of Political Science}, 69 | year = {2016}, 70 | volume = {60}, 71 | number = {2}, 72 | pages = {521--539}, 73 | publisher = {Wiley Online Library}, 74 | } 75 | 76 | @Article{Esarey2018, 77 | author = {Esarey, Justin and Sumner, Jane Lawrence}, 78 | title = {Marginal Effects in Interaction Models: Determining and Controlling the False Positive Rate}, 79 | journal = {Comparative Political Studies}, 80 | year = {2016}, 81 | volume = {51}, 82 | number = {9}, 83 | pages = {1144–1176}, 84 | publisher = {JSTOR}, 85 | } 86 | 87 | @Article{Braumoeller2004, 88 | author = {Braumoeller, Bear F}, 89 | title = {Hypothesis Testing and Multiplicative Interaction Terms}, 90 | journal = {International Organization}, 91 | year = {2004}, 92 | volume = {58}, 93 | number = {4}, 94 | pages = {807--820}, 95 | publisher = {Cambridge University Press}, 96 | } 97 | 98 | @Article{Benjamini1995, 99 | author = {Benjamini, Yoav and Hochberg, Yosef}, 100 | title = {Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing}, 101 | journal = {Journal of the Royal Statistical Society. Series B (Methodological)}, 102 | year = {1995}, 103 | pages = {289--300}, 104 | publisher = {JSTOR}, 105 | } 106 | 107 | @Article{Hanmer2013, 108 | author = {Hanmer, Michael J. and Ozan Kalkan, Kerem}, 109 | title = {Behind the Curve: Clarifying the Best Approach to Calculating Predicted Probabilities and Marginal Effects from Limited Dependent Variable Models}, 110 | journal = {American Journal of Political Science}, 111 | year = {2013}, 112 | volume = {57}, 113 | number = {1}, 114 | pages = {263--277}, 115 | issn = {1540-5907}, 116 | abstract = {Models designed for limited dependent variables are increasingly common in political science. Researchers estimating such models often give little attention to the coefficient estimates and instead focus on marginal effects, predicted probabilities, predicted counts, etc. Since the models are nonlinear, the estimated effects are sensitive to how one generates the predictions. The most common approach involves estimating the effect for the “average case.” But this approach creates a weaker connection between the results and the larger goals of the research enterprise and is thus less preferable than the observed-value approach. That is, rather than seeking to understand the effect for the average case, the goal is to obtain an estimate of the average effect in the population. In addition to the theoretical argument in favor of the observed-value approach, we illustrate via an empirical example and Monte Carlo simulations that the two approaches can produce substantively different results.}, 117 | doi = {10.1111/j.1540-5907.2012.00602.x}, 118 | publisher = {Blackwell Publishing Inc}, 119 | timestamp = {2017-08-06}, 120 | url = {http://dx.doi.org/10.1111/j.1540-5907.2012.00602.x}, 121 | } 122 | 123 | @Article{Solt2016, 124 | author = {Solt, Frederick and Hu, Yue and Hudson, Kevan and Song, Jungmin and Yu, Dong Erico}, 125 | title = {Economic Inequality and Belief in Meritocracy in the United States}, 126 | journal = {Research \& Politics}, 127 | year = {2016}, 128 | volume = {3}, 129 | number = {4}, 130 | pages = {1--7}, 131 | abstract = {How does the context of income inequality in which people live affect their belief in meritocracy, the ability to get ahead through hard work? A prominent recent study by Newman, Johnston, and Lown argues that, consistent with the conflict theory, exposure to higher levels of local income inequality leads lower-income people to become more likely to reject—and higher-income people to become more likely to accept—the dominant United States ideology of meritocracy. Here, we show that this conclusion is not supported by the studys own reported results and that even these results depend on pooling three distinctly different measures of meritocracy into a single analysis. We then demonstrate that analysis of a larger and more representative survey employing a single consistent measure of the dependent variable yields the opposite conclusion. Consistent with the relative power theory, among those with lower incomes, local contexts of greater inequality are associated with more widespread belief that people can get ahead if they are willing to work hard.}, 132 | date = {2017-06-14}, 133 | doi = {10.1177/2053168016672101}, 134 | eprint = {http://rap.sagepub.com/content/3/4/2053168016672101.full.pdf}, 135 | publisher = {SAGE Publications}, 136 | timestamp = {2017-06-14}, 137 | url = {http://rap.sagepub.com/content/3/4/2053168016672101}, 138 | urldate = {2017-06-14}, 139 | } 140 | 141 | @Comment{jabref-meta: databaseType:bibtex;} 142 | 143 | @Article{Wright1976, 144 | title = {Linear models for evaluating conditional relationships}, 145 | author = {Wright, Gerald C.}, 146 | year = {1976}, 147 | date = {1976}, 148 | journal = {American Journal of Political Science}, 149 | pages = {349}, 150 | volume = {20}, 151 | number = {2}, 152 | doi = {10.2307/2110649}, 153 | url = {https://www.jstor.org/stable/2110649?origin=crossref}, 154 | langid = {en} 155 | } 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Plot the Effects of Variables in Interaction Terms • interplot 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 21 | 22 | 23 | 24 | 25 |
    26 |
    75 | 76 | 77 | 78 | 79 |
    80 |
    81 | 82 |

    pkgdown

    83 |

    CRAN version

    84 |
    85 |
    86 | 88 |

    interplot is a tool for plotting the conditional coefficients (“marginal effects”) of variables included in multiplicative interaction terms. The function plots the changes in the coefficient of one variable in a two-way interaction term conditional on the value of the other included variable. The plot also includes simulated 95% confidential intervals of these coefficients.

    89 |

    To install:

    90 |
      91 |
    • the latest released version: install.packages("interplot").
    • 92 |
    • the latest developing version: remotes::install_github("sammo3182/interplot").
    • 93 |
    94 |

    More details are available at:

    95 |

    http://cran.r-project.org/web/packages/interplot/vignettes/interplot-vignette.html

    96 |

    Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

    97 |
    98 | 99 |
    100 | 101 | 140 |
    141 | 142 | 143 |
    147 | 148 |
    149 |

    150 |

    Site built with pkgdown 2.0.7.

    151 |
    152 | 153 |
    154 |
    155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /man/interplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Interplot.R 3 | \name{interplot} 4 | \alias{interplot} 5 | \title{Plot Conditional Coefficients of a Variable in an Interaction Term} 6 | \source{ 7 | Benjamini, Yoav, and Yosef Hochberg. 1995. "Controlling the False 8 | Discovery Rate: A Practical and Powerful Approach to Multiple Testing". 9 | Journal of the Royal Statistical Society, Series B 57(1): 289--300. 10 | 11 | Brambor, Thomas, William Roberts Clark, and Matt Golder. 12 | "Understanding interaction models: Improving empirical analyses". Political 13 | Analysis 14.1 (2006): 63-82. 14 | 15 | Esarey, Justin, and Jane Lawrence Sumner. 2015. "Marginal Effects in 16 | Interaction Models: Determining and Controlling the False Positive Rate". 17 | URL: \url{https://jee3.web.rice.edu/interaction-overconfidence.pdf}. 18 | } 19 | \usage{ 20 | interplot( 21 | m, 22 | var1, 23 | var2, 24 | plot = TRUE, 25 | steps = NULL, 26 | ci = 0.95, 27 | adjCI = FALSE, 28 | hist = FALSE, 29 | var2_dt = NA, 30 | predPro = FALSE, 31 | var2_vals = NULL, 32 | point = FALSE, 33 | sims = 1000, 34 | xmin = NA, 35 | xmax = NA, 36 | ercolor = NA, 37 | esize = 0.5, 38 | ralpha = 0.5, 39 | rfill = "grey70", 40 | stats_cp = "none", 41 | txt_caption = NULL, 42 | ... 43 | ) 44 | } 45 | \arguments{ 46 | \item{m}{A model object including an interaction term, or, alternately, a data frame generated by an earlier call to interplot using the argument plot = FALSE.} 47 | 48 | \item{var1}{The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.} 49 | 50 | \item{var2}{The name (as a string) of the other variable in the interaction term} 51 | 52 | \item{plot}{A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.} 53 | 54 | \item{steps}{Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}).} 55 | 56 | \item{ci}{A numeric value defining the confidence intervals. The default value is 95\% (0.95).} 57 | 58 | \item{adjCI}{A logical value indication if applying the adjustment of confidence intervals to control the false discovery rate following the Esarey and Sumner (2017) procedure. (See also Benjamini and Hochberg 1995.) The default is FALSE; the plot presents the confidence intervals suggested by Brambor, Clark, and Golder (2006). The functions dealing with multilevel model outputs in this package do not equip with this argument, because there is the controversy on the accurate degrees of freedom for multilevel models, esp. when random effect is engaged and the degrees of freedom is a necessary information to conduct the CI adjustment. See e.g., https://stat.ethz.ch/pipermail/r-help/2006-May/094765.html and https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q1/000517.html.} 59 | 60 | \item{hist}{A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.} 61 | 62 | \item{var2_dt}{A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.} 63 | 64 | \item{predPro}{A logical value with default of `FALSE`. When the `m` is an object of class `glm` or `glmerMod` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.} 65 | 66 | \item{var2_vals}{A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.} 67 | 68 | \item{point}{A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.} 69 | 70 | \item{sims}{Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.} 71 | 72 | \item{xmin}{A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.} 73 | 74 | \item{xmax}{A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.} 75 | 76 | \item{ercolor}{A character value indicating the outline color of the whisker or ribbon.} 77 | 78 | \item{esize}{A numerical value indicating the size of the whisker or ribbon.} 79 | 80 | \item{ralpha}{A numerical value indicating the transparency of the ribbon.} 81 | 82 | \item{rfill}{A character value indicating the filling color of the ribbon.} 83 | 84 | \item{stats_cp}{A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.} 85 | 86 | \item{txt_caption}{A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}.} 87 | 88 | \item{...}{Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.} 89 | } 90 | \value{ 91 | The function returns a \code{ggplot} object. 92 | } 93 | \description{ 94 | \code{interplot} is a generic function to produce a plot of the coefficient estimates of one variable in a two-way interaction conditional on the values of the other variable in the interaction term. The function invokes particular \code{methods} which depend on the \code{\link{class}} of the first argument. 95 | } 96 | \details{ 97 | \code{interplot} visualizes the changes in the coefficient of one term in a two-way interaction conditioned by the other term. In the current version, the function works with interactions in the following classes of models: 98 | \itemize{ 99 | \item Ordinary linear models (object class: \code{lm}); 100 | \item Generalized linear models (object class: \code{glm}); 101 | \item Linear mixed-effects models (object class: \code{lmerMod}); 102 | \item Generalized linear mixed-effects models (object class: \code{glmerMod}); 103 | \item Ordinary linear models with imputed data (object class: \code{list}); 104 | \item Generalized linear models with imputed data (object class: \code{list}) 105 | \item Linear mixed-effects models with imputed data (object class: \code{list}); 106 | \item Generalized linear mixed-effects models with imputed data (object class: \code{list}). 107 | } 108 | 109 | The examples below illustrate how methods invoked by this generic deal with different type of objects. 110 | 111 | Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 112 | 113 | \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 114 | \itemize{ 115 | \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 116 | \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 117 | } 118 | 119 | See an illustration in the package vignette. 120 | } 121 | \examples{ 122 | data(mtcars) 123 | m_cyl <- lm(mpg ~ wt * cyl, data = mtcars) 124 | library(interplot) 125 | 126 | # Plot interactions with a continous conditioning variable 127 | interplot(m = m_cyl, var1 = 'cyl', var2 = 'wt') + 128 | xlab('Automobile Weight (thousands lbs)') + 129 | ylab('Estimated Coefficient for Number of Cylinders') + 130 | ggtitle('Estimated Coefficient of Engine Cylinders\non Mileage by Automobile Weight') + 131 | theme(plot.title = element_text(face='bold')) 132 | 133 | 134 | # Plot interactions with a categorical conditioning variable 135 | interplot(m = m_cyl, var1 = 'wt', var2 = 'cyl') + 136 | xlab('Number of Cylinders') + 137 | ylab('Estimated Coefficient for Automobile Weight (thousands lbs)') + 138 | ggtitle('Estimated Coefficient of Automobile Weight \non Mileage by Engine Cylinders') + 139 | theme(plot.title = element_text(face='bold')) 140 | 141 | } 142 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /R/Interplot.R: -------------------------------------------------------------------------------- 1 | #' Plot Conditional Coefficients of a Variable in an Interaction Term 2 | #' 3 | #' \code{interplot} is a generic function to produce a plot of the coefficient estimates of one variable in a two-way interaction conditional on the values of the other variable in the interaction term. The function invokes particular \code{methods} which depend on the \code{\link{class}} of the first argument. 4 | #' 5 | #' @param m A model object including an interaction term, or, alternately, a data frame generated by an earlier call to interplot using the argument plot = FALSE. 6 | #' @param var1 The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted. 7 | #' @param var2 The name (as a string) of the other variable in the interaction term 8 | #' @param plot A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2. 9 | #' @param steps Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the \code{var2} (when it is less than 100. Also see \code{\link{unique}}). 10 | #' @param ci A numeric value defining the confidence intervals. The default value is 95\% (0.95). 11 | #' @param adjCI A logical value indication if applying the adjustment of confidence intervals to control the false discovery rate following the Esarey and Sumner (2017) procedure. (See also Benjamini and Hochberg 1995.) The default is FALSE; the plot presents the confidence intervals suggested by Brambor, Clark, and Golder (2006). The functions dealing with multilevel model outputs in this package do not equip with this argument, because there is the controversy on the accurate degrees of freedom for multilevel models, esp. when random effect is engaged and the degrees of freedom is a necessary information to conduct the CI adjustment. See e.g., https://stat.ethz.ch/pipermail/r-help/2006-May/094765.html and https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q1/000517.html. 12 | #' @param hist A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot. 13 | #' @param var2_dt A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model. 14 | #' @param predPro A logical value with default of `FALSE`. When the `m` is an object of class `glm` or `glmerMod` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`. 15 | #' @param var2_vals A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`. 16 | #' @param point A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot. 17 | #' @param sims Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves. 18 | #' @param xmin A numerical value indicating the minimum value shown of x shown in the graph. Rarely used. 19 | #' @param xmax A numerical value indicating the maximum value shown of x shown in the graph. Rarely used. 20 | #' @param ercolor A character value indicating the outline color of the whisker or ribbon. 21 | #' @param esize A numerical value indicating the size of the whisker or ribbon. 22 | #' @param ralpha A numerical value indicating the transparency of the ribbon. 23 | #' @param rfill A character value indicating the filling color of the ribbon. 24 | #' @param stats_cp A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information. 25 | #' @param txt_caption A character string to add a note for the plot, a value will sending to \code{ggplot2::labs(caption = txt_caption))}. 26 | #' @param ... Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used. 27 | #' 28 | #' @details \code{interplot} visualizes the changes in the coefficient of one term in a two-way interaction conditioned by the other term. In the current version, the function works with interactions in the following classes of models: 29 | #' \itemize{ 30 | #' \item Ordinary linear models (object class: \code{lm}); 31 | #' \item Generalized linear models (object class: \code{glm}); 32 | #' \item Linear mixed-effects models (object class: \code{lmerMod}); 33 | #' \item Generalized linear mixed-effects models (object class: \code{glmerMod}); 34 | #' \item Ordinary linear models with imputed data (object class: \code{list}); 35 | #' \item Generalized linear models with imputed data (object class: \code{list}) 36 | #' \item Linear mixed-effects models with imputed data (object class: \code{list}); 37 | #' \item Generalized linear mixed-effects models with imputed data (object class: \code{list}). 38 | #' } 39 | #' 40 | #' The examples below illustrate how methods invoked by this generic deal with different type of objects. 41 | #' 42 | #' Because the output function is based on \code{\link[ggplot2]{ggplot}}, any additional arguments and layers supported by \code{ggplot2} can be added with the \code{+}. 43 | #' 44 | #' \code{interplot} visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (\code{var2}) at every preset values (including the minimum and maximum values) of the conditioned variable (\code{var1}), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \eqn{Emax - Emin} covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument \code{stats_cp} to "ci" or "ks". 45 | #' \itemize{ 46 | #' \item "ci" provides the confidence interval of the difference of \eqn{Emax - Emin}. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa. 47 | #' \item "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level. 48 | #' } 49 | #' 50 | #' See an illustration in the package vignette. 51 | #' 52 | #' @return The function returns a \code{ggplot} object. 53 | #' 54 | #' 55 | #' @examples 56 | #' data(mtcars) 57 | #' m_cyl <- lm(mpg ~ wt * cyl, data = mtcars) 58 | #' library(interplot) 59 | #' 60 | #' # Plot interactions with a continous conditioning variable 61 | #' interplot(m = m_cyl, var1 = 'cyl', var2 = 'wt') + 62 | #' xlab('Automobile Weight (thousands lbs)') + 63 | #' ylab('Estimated Coefficient for Number of Cylinders') + 64 | #' ggtitle('Estimated Coefficient of Engine Cylinders\non Mileage by Automobile Weight') + 65 | #' theme(plot.title = element_text(face='bold')) 66 | #' 67 | #' 68 | #' # Plot interactions with a categorical conditioning variable 69 | #' interplot(m = m_cyl, var1 = 'wt', var2 = 'cyl') + 70 | #' xlab('Number of Cylinders') + 71 | #' ylab('Estimated Coefficient for Automobile Weight (thousands lbs)') + 72 | #' ggtitle('Estimated Coefficient of Automobile Weight \non Mileage by Engine Cylinders') + 73 | #' theme(plot.title = element_text(face='bold')) 74 | #' 75 | #' @source Benjamini, Yoav, and Yosef Hochberg. 1995. "Controlling the False 76 | #' Discovery Rate: A Practical and Powerful Approach to Multiple Testing". 77 | #' Journal of the Royal Statistical Society, Series B 57(1): 289--300. 78 | #' 79 | #' Brambor, Thomas, William Roberts Clark, and Matt Golder. 80 | #' "Understanding interaction models: Improving empirical analyses". Political 81 | #' Analysis 14.1 (2006): 63-82. 82 | #' 83 | #' Esarey, Justin, and Jane Lawrence Sumner. 2015. "Marginal Effects in 84 | #' Interaction Models: Determining and Controlling the False Positive Rate". 85 | #' URL: \url{https://jee3.web.rice.edu/interaction-overconfidence.pdf}. 86 | #' 87 | #' @export 88 | 89 | 90 | interplot <- function(m, var1, var2, plot = TRUE, steps = NULL, ci = .95, adjCI = FALSE, hist = FALSE, var2_dt = NA, predPro = FALSE, var2_vals = NULL, point = FALSE, sims = 1000, xmin = NA, xmax = NA, ercolor = NA, esize = 0.5, ralpha = 0.5, rfill = "grey70", stats_cp = "none", txt_caption = NULL, ...) { 91 | 92 | 93 | if (class(m)[1] == "list") { 94 | if (class(m[[1]])[1] == "lmerMod") { 95 | class(m) <- "mlmmi" 96 | } 97 | if (class(m[[1]])[1] == "glmerMod") { 98 | class(m) <- "gmlmmi" 99 | } 100 | if (class(m[[1]])[1] == "lm") { 101 | class(m) <- "lmmi" 102 | } 103 | if (class(m[[1]])[1] == "glm") { 104 | class(m) <- "glmmi" 105 | } 106 | } 107 | 108 | if (class(m)[1] == "data.frame") 109 | class(m) <- "plot" 110 | 111 | 112 | UseMethod("interplot", m) 113 | } 114 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /docs/reference/interplot.lmerMod.html: -------------------------------------------------------------------------------- 1 | 2 | Plot Conditional Coefficients in Mixed-Effects Models with Interaction Terms — interplot.lmerMod • interplot 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    interplot.mlm is a method to calculate conditional coefficient estimates from the results of multilevel (mixed-effects) regression models with interaction terms.

    63 |
    64 | 65 |
    66 |
    # S3 method for lmerMod
     67 | interplot(
     68 |   m,
     69 |   var1,
     70 |   var2,
     71 |   plot = TRUE,
     72 |   steps = NULL,
     73 |   ci = 0.95,
     74 |   adjCI = FALSE,
     75 |   hist = FALSE,
     76 |   var2_dt = NA,
     77 |   predPro = FALSE,
     78 |   var2_vals = NULL,
     79 |   point = FALSE,
     80 |   sims = 5000,
     81 |   xmin = NA,
     82 |   xmax = NA,
     83 |   ercolor = NA,
     84 |   esize = 0.5,
     85 |   ralpha = 0.5,
     86 |   rfill = "grey70",
     87 |   stats_cp = "none",
     88 |   txt_caption = NULL,
     89 |   facet_labs = NULL,
     90 |   ...
     91 | )
    92 |
    93 | 94 |
    95 |

    Arguments

    96 |
    m
    97 |

    A model object including an interaction term, or, alternately, a data frame recording conditional coefficients.

    98 | 99 | 100 |
    var1
    101 |

    The name (as a string) of the variable of interest in the interaction term; its conditional coefficient estimates will be plotted.

    102 | 103 | 104 |
    var2
    105 |

    The name (as a string) of the other variable in the interaction term.

    106 | 107 | 108 |
    plot
    109 |

    A logical value indicating whether the output is a plot or a dataframe including the conditional coefficient estimates of var1, their upper and lower bounds, and the corresponding values of var2.

    110 | 111 | 112 |
    steps
    113 |

    Desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional. The default is 100 or the unique categories in the var2 (when it is less than 100. Also see unique).

    114 | 115 | 116 |
    ci
    117 |

    A numeric value defining the confidence intervals. The default value is 95% (0.95).

    118 | 119 | 120 |
    adjCI
    121 |

    Not working for `lmer` outputs yet.

    122 | 123 | 124 |
    hist
    125 |

    A logical value indicating if there is a histogram of `var2` added at the bottom of the conditional effect plot.

    126 | 127 | 128 |
    var2_dt
    129 |

    A numerical value indicating the frequency distribution of `var2`. It is only used when `hist == TRUE`. When the object is a model, the default is the distribution of `var2` of the model.

    130 | 131 | 132 |
    predPro
    133 |

    A logical value with default of `FALSE`. When the `m` is an object of class `glmerMod` and the argument is set to `TRUE`, the function will plot predicted probabilities at the values given by `var2_vals`.

    134 | 135 | 136 |
    var2_vals
    137 |

    A numerical value indicating the values the predicted probabilities are estimated, when `predPro` is `TRUE`.

    138 | 139 | 140 |
    point
    141 |

    A logical value determining the format of plot. By default, the function produces a line plot when var2 takes on ten or more distinct values and a point (dot-and-whisker) plot otherwise; option TRUE forces a point plot.

    142 | 143 | 144 |
    sims
    145 |

    Number of independent simulation draws used to calculate upper and lower bounds of coefficient estimates: lower values run faster; higher values produce smoother curves.

    146 | 147 | 148 |
    xmin
    149 |

    A numerical value indicating the minimum value shown of x shown in the graph. Rarely used.

    150 | 151 | 152 |
    xmax
    153 |

    A numerical value indicating the maximum value shown of x shown in the graph. Rarely used.

    154 | 155 | 156 |
    ercolor
    157 |

    A character value indicating the outline color of the whisker or ribbon.

    158 | 159 | 160 |
    esize
    161 |

    A numerical value indicating the size of the whisker or ribbon.

    162 | 163 | 164 |
    ralpha
    165 |

    A numerical value indicating the transparency of the ribbon.

    166 | 167 | 168 |
    rfill
    169 |

    A character value indicating the filling color of the ribbon.

    170 | 171 | 172 |
    stats_cp
    173 |

    A character value indicating what statistics to present as the plot note. Three options are available: "none", "ci", and "ks". The default is "none". See the Details for more information.

    174 | 175 | 176 |
    txt_caption
    177 |

    A character string to add a note for the plot, a value will sending to ggplot2::labs(caption = txt_caption)).

    178 | 179 | 180 |
    facet_labs
    181 |

    An optional character vector of facet labels to be used when plotting an interaction with a factor variable.

    182 | 183 | 184 |
    ...
    185 |

    Other ggplot aesthetics arguments for points in the dot-whisker plot or lines in the line-ribbon plots. Not currently used.

    186 | 187 |
    188 |
    189 |

    Value

    190 | 191 | 192 |

    The function returns a ggplot object.

    193 |
    194 |
    195 |

    Details

    196 |

    interplot.mlm is a S3 method from the interplot. It works on mixed-effects objects with class lmerMod and glmerMod.

    197 |

    Because the output function is based on ggplot, any additional arguments and layers supported by ggplot2 can be added with the +.

    198 |

    interplot visualizes the conditional effect based on simulated marginal effects. The simulation provides a probabilistic distribution of moderation effect of the conditioning variable (var2) at every preset values (including the minimum and maximum values) of the conditioned variable (var1), denoted as Emin and Emax. This output allows the function to further examine the conditional effect statistically in two ways. One is to examine if the distribution of \(Emax - Emin\) covers zero. The other is to directly compare Emin and Emax through statistical tools for distributional comparisons. Users can choose either method by setting the argument stats_cp to "ci" or "ks".

    • "ci" provides the confidence interval of the difference of \(Emax - Emin\). An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

    • 199 |
    • "ks" presents the result of a two-sample Kolmogorov-Smirnov test of the simulated distributions of Emin and Emax. The output includes a D statistics and a p-value of the null hypothesis that the two distributions come from the same distribution at the 0.05 level.

    • 200 |

    See an illustration in the package vignette.

    201 |
    202 | 203 |
    204 | 207 |
    208 | 209 | 210 |
    219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | --------------------------------------------------------------------------------