| Type: | Package | 
| Title: | Plot Marginal Effects from Linear Models | 
| Description: | Plot marginal effects for interactions estimated from linear models. | 
| Version: | 0.1.5 | 
| Date: | 2018-05-28 | 
| BugReports: | https://github.com/christophergandrud/plotMElm/issues | 
| License: | GPL (≥ 3) | 
| Imports: | ggplot2, interactionTest | 
| LazyData: | TRUE | 
| RoxygenNote: | 6.0.1 | 
| NeedsCompilation: | no | 
| Packaged: | 2018-05-28 14:49:39 UTC; christophergandrud | 
| Author: | Christopher Gandrud [aut, cre] | 
| Maintainer: | Christopher Gandrud <christopher.gandrud@gmail.com> | 
| Repository: | CRAN | 
| Date/Publication: | 2018-05-28 19:09:38 UTC | 
Plot marginal effects from two-way interactions in linear regressions
Description
Plot marginal effects from two-way interactions in linear regressions
Usage
plot_me(obj, term1, term2, fitted2, ci = 95, ci_type = "standard",
  t_statistic, plot = TRUE)
Arguments
| obj | fitted model object from  | 
| term1 | character string of the first constitutive term of the interaction's variable name. | 
| term2 | character string of the second constitutive term of the interaction's variable name. | 
| fitted2 | numeric vector of fitted values of  | 
| ci | numeric. confidence interval level, expressed on the ]0, 100[
interval. The default is  | 
| ci_type | character string specifying the type of confidence interval
to find and plot. If  | 
| t_statistic | numeric. Custom t-statistic for finding the confidence interval.
May be useful if the user want to use a funciton like  | 
| plot | boolean. return plot if  | 
Value
a gg class ggplot2 object
Source
Inspired by: http://www.statsblogs.com/2013/08/27/creating-marginal-effect-plots-for-linear-regression-models-in-r/
Benjamini, Yoav, and Yosef Hochberg. 1995. "Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing". Journal of the Royal Statistical Society, Series B 57(1): 289–300.
Brambor, Thomas, William Roberts Clark, and Matt Golder. "Understanding interaction models: Improving empirical analyses". Political Analysis 14.1 (2006): 63-82.
Esarey, Justin, and Jane Lawrence Sumner. 2015. "Marginal Effects in Interaction Models: Determining and Controlling the False Positive Rate". URL: http://jee3.web.rice.edu/interaction-overconfidence.pdf.
Examples
## Continuous Term1 and Term2
# Estimate model
states <- as.data.frame(state.x77)
m1 <- lm(Murder ~ Income * Population, data = states)
# Plot marginal effect of Income across the observed range of Population
# on the Murder rate
plot_me(m1, 'Income', 'Population', ci = 95)
# CI created using false discovery rate limiting t-statistic
plot_me(m1, 'Income', 'Population', ci_type = 'fdr')
# Return marginal effects as a data frame
plot_me(m1, 'Income', 'Population', plot = FALSE)
## Term 2 with <= 5 unique values
# Estimate model
m2 <- lm(mpg ~ wt * cyl, data = mtcars)
# Plot marginal effect of Weight across the Number of Cylinders (continuous)
plot_me(m2, 'wt', 'cyl')
## Categorical (factor) Term2
# Set Term 2 as a factor variable
mtcars$cyl <- factor(mtcars$cyl,
                 labels = c('4 Cyl', '6 Cyl', '8 Cyl'))
# Estimate model
m3 <- lm(mpg ~ wt * cyl, data = mtcars)
# Plot marginal effect of Weight across the Number of Cylinders (factor)
plot_me(m3, 'wt', 'cyl')