Learn R Programming

robmed (version 1.2.1)

ellipse_plot: 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, ...)

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

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

Value

An object of class "ggplot".

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.

Author

Andreas Alfons

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.

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

Run this code
data("BSG2014")

# obtain robust fit of mediation model
robust_fit <- fit_mediation(BSG2014,
                            x = "ValueDiversity",
                            y = "TeamCommitment",
                            m = "TaskConflict",
                            robust = TRUE)

# create plot for robust model fit
ellipse_plot(robust_fit)

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

# obtain OLS fit of mediation model
ols_fit <- fit_mediation(BSG2014,
                         x = "ValueDiversity",
                         y = "TeamCommitment",
                         m = "TaskConflict",
                         robust = FALSE)

# compare robust and OLS model fits
fit_list <- list("OLS bootstrap" = ols_fit,
                 "ROBMED" = robust_fit)
ellipse_plot(fit_list)

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

Run the code above in your browser using DataLab