Package 'interplot'

Title: Plot the Effects of Variables in Interaction Terms
Description: Plots the conditional coefficients ("marginal effects") of variables included in multiplicative interaction terms.
Authors: Frederick Solt [aut], Yue Hu [aut, cre], Brenton Kenkel [ctb]
Maintainer: Yue Hu <[email protected]>
License: MIT + file LICENSE
Version: 0.2.3
Built: 2024-10-29 03:01:14 UTC
Source: https://github.com/sammo3182/interplot

Help Index


Plot Conditional Coefficients of a Variable in an Interaction Term

Description

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 methods which depend on the class of the first argument.

Usage

interplot(
  m,
  var1,
  var2,
  plot = TRUE,
  steps = NULL,
  ci = 0.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,
  ...
)

Arguments

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.

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

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

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.

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

...

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

Details

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:

  • Ordinary linear models (object class: lm);

  • Generalized linear models (object class: glm);

  • Linear mixed-effects models (object class: lmerMod);

  • Generalized linear mixed-effects models (object class: glmerMod);

  • Ordinary linear models with imputed data (object class: list);

  • Generalized linear models with imputed data (object class: list)

  • Linear mixed-effects models with imputed data (object class: list);

  • Generalized linear mixed-effects models with imputed data (object class: list).

The examples below illustrate how methods invoked by this generic deal with different type of objects.

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.

Source

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: https://jee3.web.rice.edu/interaction-overconfidence.pdf.

Examples

data(mtcars)
m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
library(interplot)

# Plot interactions with a continous conditioning variable
interplot(m = m_cyl, var1 = 'cyl', var2 = 'wt') +
xlab('Automobile Weight (thousands lbs)') +
ylab('Estimated Coefficient for Number of Cylinders') +
ggtitle('Estimated Coefficient of Engine Cylinders\non Mileage by Automobile Weight') +
theme(plot.title = element_text(face='bold'))


# Plot interactions with a categorical conditioning variable
interplot(m = m_cyl, var1 = 'wt', var2 = 'cyl') +
xlab('Number of Cylinders') +
ylab('Estimated Coefficient for Automobile Weight (thousands lbs)') +
ggtitle('Estimated Coefficient of Automobile Weight \non Mileage by Engine Cylinders') +
theme(plot.title = element_text(face='bold'))

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

Description

interplot.default is a method to calculate conditional coefficient estimates from the results of (generalized) linear regression models with interaction terms.

Usage

## Default S3 method:
interplot(
  m,
  var1,
  var2,
  plot = TRUE,
  steps = NULL,
  ci = 0.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,
  facet_labs = NULL,
  ...
)

Arguments

m

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

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

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

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).

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

facet_labs

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

...

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

Details

interplot.default is a S3 method from the interplot. It works on two classes of objects:

  • Ordinary linear models (object class: lm);

  • Generalized linear models (object class: glm).

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.

Source

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.


Plot Conditional Coefficients in Mixed-Effects Models with Interaction Terms

Description

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

Usage

## S3 method for class 'lmerMod'
interplot(
  m,
  var1,
  var2,
  plot = TRUE,
  steps = NULL,
  ci = 0.95,
  adjCI = FALSE,
  hist = FALSE,
  var2_dt = NA,
  predPro = FALSE,
  var2_vals = NULL,
  point = FALSE,
  sims = 5000,
  xmin = NA,
  xmax = NA,
  ercolor = NA,
  esize = 0.5,
  ralpha = 0.5,
  rfill = "grey70",
  stats_cp = "none",
  txt_caption = NULL,
  facet_labs = NULL,
  ...
)

Arguments

m

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

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

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

adjCI

Not working for 'lmer' outputs yet.

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

facet_labs

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

...

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

Details

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

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.


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

Description

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.

Usage

## S3 method for class 'lmmi'
interplot(
  m,
  var1,
  var2,
  plot = TRUE,
  steps = NULL,
  ci = 0.95,
  adjCI = FALSE,
  hist = FALSE,
  var2_dt = NA,
  predPro = FALSE,
  var2_vals = NULL,
  point = FALSE,
  sims = 5000,
  xmin = NA,
  xmax = NA,
  ercolor = NA,
  esize = 0.5,
  ralpha = 0.5,
  rfill = "grey70",
  stats_cp = "none",
  txt_caption = NULL,
  facet_labs = NULL,
  ...
)

Arguments

m

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

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

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

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).

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

facet_labs

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

...

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

Details

interplot.lmmi and interplot.glmmi are S3 methods from the interplot. This function can work on interactions from results in the class of list generated by mitools.

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.

Source

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

library(interplot)
library(mitools)

data(smi)
model1 <- with(smi, glm(drinkreg ~ wave * sex, family = binomial()))

interplot(model1, var1 = "sex", var2 = "wave")

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

Description

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.

Usage

## S3 method for class 'mlmmi'
interplot(
  m,
  var1,
  var2,
  plot = TRUE,
  steps = NULL,
  ci = 0.95,
  adjCI = FALSE,
  hist = FALSE,
  var2_dt = NA,
  predPro = FALSE,
  var2_vals = NULL,
  point = FALSE,
  sims = 5000,
  xmin = NA,
  xmax = NA,
  ercolor = NA,
  esize = 0.5,
  ralpha = 0.5,
  rfill = "grey70",
  stats_cp = "none",
  txt_caption = NULL,
  facet_labs = NULL,
  ...
)

Arguments

m

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

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

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

adjCI

Not working for 'lmer' outputs yet.

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

facet_labs

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

...

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

Details

interplot.mlmmi and interplot.gmlmmi are S3 methods from the interplot. It works on lists of mixed-effects objects with class lmerMod and glmerMod generated by mitools and lme4.

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.


Plot Conditional Coefficients in Models with Interaction Terms

Description

Graph based on the data frame of statistics about the conditional effect of an interaction.

Usage

## S3 method for class 'plot'
interplot(
  m,
  var1 = NULL,
  var2 = NULL,
  plot = TRUE,
  steps = NULL,
  ci = 0.95,
  adjCI = FALSE,
  hist = FALSE,
  var2_dt = NULL,
  predPro = FALSE,
  var2_vals = NULL,
  point = FALSE,
  sims = 5000,
  xmin = NA,
  xmax = NA,
  ercolor = NA,
  esize = 0.5,
  ralpha = 0.5,
  rfill = "grey70",
  stats_cp = "none",
  txt_caption = NULL,
  ci_diff = NULL,
  ks_diff = NULL,
  ...
)

Arguments

m

A model object including an interaction term, or, alternately, a data frame recording conditional coefficients. This data frame should includes four columns:

  • fake: The sequence of var1 (the item whose effect will be conditioned on in the interaction);

  • coef1: The point estimates of the coefficient of var1 at each break point.

  • ub: The upper bound of the simulated 95% CI.

  • lb: The lower bound of the simulated 95% CI.

var1

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

var2

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

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.

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 var2 (when it is less than 100. Also see unique).

ci

is a numeric value inherited from the data wrangling functions in this package. Adding it here is just for the method consistency.

adjCI

Succeeded from the data management functions in 'interplot' package.

hist

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

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.

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'.

var2_vals

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

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.

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.

xmin

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

xmax

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

ercolor

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

esize

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

ralpha

A numerical value indicating the transparency of the ribbon.

rfill

A character value indicating the filling color of the ribbon.

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.

txt_caption

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

ci_diff

A numerical vector with a pair of values indicating the confidence intervals of the difference between var1 and var2.

ks_diff

A ks.test object of the effect of var1 conditioned on var2.

...

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

Details

interplot.plot is a S3 method from the interplot. It generates plots of conditional coefficients.

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

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 EmaxEminEmax - 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 EmaxEminEmax - Emin. An interval including 0 suggests no statistical difference before and after the conditional effect is applied, and vise versa.

  • "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.

See an illustration in the package vignette.

Value

The function returns a ggplot object.