ellipse_plot: Diagnostic plot with a tolerance ellipse

View source: R/ellipse_plot.R

ellipse_plotR Documentation

Diagnostic plot with a tolerance ellipse

Description

Produce a scatter plot of two variables used in (robust) mediation analysis together with a tolerance ellipse. Exploiting the relationship between the regression coefficients and the covariance matrix, that tolerance ellipse illustrates how well the regression results represent the data. In addition, a line that visualizes the estimated regression coefficient is added when relevant.

Usage

ellipse_plot(object, ...)

## Default S3 method:
ellipse_plot(
  object,
  horizontal = NULL,
  vertical = NULL,
  partial = FALSE,
  level = 0.975,
  npoints = 100,
  ...
)

## S3 method for class 'setup_ellipse_plot'
ellipse_plot(object, ...)

Arguments

object

an object inheriting from class "fit_mediation" or "test_mediation" containing results from (robust) mediation analysis, or a list of such objects.

...

additional arguments to be passed down.

horizontal

a character string specifying the variable to be plotted on the horizontal axis. If the dependent variable is chosen for the vertical axis, a hypothsized mediator or an independent variable must be selected for the horizontal axis. If a hypothesized mediator is chosen for the vertical axis, an independent variable must be selected for the horizontal axis (in case of a serial multiple mediator model, a hypothesized mediator occurring earlier in the sequence is also allowed). The default is to plot the first independent variable on the horizontal axis.

vertical

a character string specifying the variable to be plotted on the vertical axis: the dependent variable or a hypothesized mediator. The default is to plot the first hypothesized mediator on the vertical axis.

partial

a logical indicating whether the vertical axis should display the observed values of the selected variable (FALSE), or the partial residuals with respect to the variable on the horizontal axis (TRUE). The latter allows to display the corresponding regression coefficient by a line.

level

numeric; the confidence level of the tolerance ellipse. It gives the percentage of observations that are expected to lie within the ellipse under the assumption of a normal distribution, and therefore it controls the size of the ellipse. The default is such that the ellipse is expected to contain 97.5% of the observations.

npoints

the number of grid points used to evaluate and draw the ellipse. The default is to use 100 grid points.

Details

A line to visualize the corresponding regression coefficient is added if partial = TRUE, or in case of a simple mediation model (without control variables) when the hypothesized mediator is plotted on the vertical axis and the independent variable is plotted on the horizontal axis.

For robust estimation methods that return outlyingness weights for each data point, those weights are visualized by coloring the points on a grey scale. If a list of objects has been supplied and there are multiple objects from such robust methods, each method is placed in a separate panel.

Methods first call setup_ellipse_plot() to extract all necessary information to produce the plot, then the "setup_ellipse_plot" method is called to produce the plot.

Value

An object of class "ggplot".

Author(s)

Andreas Alfons

References

Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2022) Robust Mediation Analysis: The R Package robmed. Journal of Statistical Software, 103(13), 1–45. doi:10.18637/jss.v103.i13.

See Also

fit_mediation(), test_mediation(), setup_ellipse_plot()

ci_plot(), density_plot(), weight_plot(), plot()

Examples

data("BSG2014")

# run fast-and-robust bootstrap test
robust_boot <- test_mediation(BSG2014,
                              x = "ValueDiversity",
                              y = "TeamCommitment",
                              m = "TaskConflict",
                              robust = TRUE)

# create plot for robust bootstrap test
ellipse_plot(robust_boot)

# original data and partial residuals
ellipse_plot(robust_boot, horizontal = "TaskConflict",
             vertical = "TeamCommitment")
ellipse_plot(robust_boot, horizontal = "TaskConflict",
             vertical = "TeamCommitment", partial = TRUE)

# run OLS bootstrap test
ols_boot <- test_mediation(BSG2014,
                           x = "ValueDiversity",
                           y = "TeamCommitment",
                           m = "TaskConflict",
                           robust = FALSE)

# compare robust and OLS bootstrap tests
boot_list <- list("OLS bootstrap" = ols_boot,
                  "ROBMED" = robust_boot)
ellipse_plot(boot_list)

# the plot can be customized in the usual way
ellipse_plot(boot_list) + theme_bw() +
  labs(title = "OLS vs robust estimation")


aalfons/robmed documentation built on July 4, 2023, 7:48 a.m.