MyNixOS website logo
Description

Plot Marginal Effects from Linear Models.

Plot marginal effects for interactions estimated from linear models.

plotMElm

A simple R package to plot marginal effects from interactions estimated from linear models.

BuildStatus CRANVersion

Examples

Continuous Term 2

The package contains one simply function: plot_me for plotting marginal effects from interactions estimated from models estimated with the lm function in base R. For example, when the second term is continuous:

# Load package
library(plotMElm)

# 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
plot_me(m1, 'Income', 'Population')

## Categorical (Factor) Term 2

When the second term in the interaction is a categorical (factor) variable then point-ranges are plotted. Note that the marginal effect is in terms of the reference category:

# Set Term 2 as a factor variable
mtcars$cyl <- factor(mtcars$cyl, 
                     labels = c('4 Cyl', '6 Cyl', '8 Cyl'))

# Estimate model
m2 <- lm(mpg ~ wt * cyl, data = mtcars)

# Plot marginal effect of Weight across the Number of Cylinders
plot_me(m2, 'wt', 'cyl')

Note that point ranges will also be used if there are five or fewer fitted values.

Determining the False Positive Rate

Esarey and Sumner show that pointwise confidence intervals from marginal effect plots produce statistically significant findings at a rate that can be larger or smaller than is warrented. plot_me allows users to specify ci_type = 'fdr' to find confidence intervals that correct for overly confident marginal effects in the face of multiple comparisons. FDR stands for “False Discovery Rate”. For example:

# Plot marginal effect of Income across the observed range of Population
# with false discovery rate limited confidence intervals
plot_me(m1, 'Income', 'Population', ci_type = 'fdr')

Here is the result compared with standard confidence intervals:

## t-statistic used: 2.269

You can also use the t_statistic argument to supply custom t-statistics for creating the marginal effect confidence intervals. This is useful if you want to use a funciton like findMultiLims from the interactTest package to find t-statistics that can be used to correct confidence intervals for underconfidence.

See also

The interplot package also has some of the same capabilities as plotMElm.

Metadata

Version

0.1.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows