setup_ellipse_plot: Set up a diagnostic plot with a tolerance ellipse

View source: R/setup_ellipse_plot.R

setup_ellipse_plotR Documentation

Set up a diagnostic plot with a tolerance ellipse

Description

Extract the relevant information for a diagnostic plot with a tolerance ellipse from results of (robust) mediation analysis.

Usage

setup_ellipse_plot(object, ...)

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

## S3 method for class 'reg_fit_mediation'
setup_ellipse_plot(
  object,
  horizontal = NULL,
  vertical = NULL,
  partial = FALSE,
  level = 0.975,
  npoints = 100,
  ...
)

## S3 method for class 'cov_fit_mediation'
setup_ellipse_plot(
  object,
  horizontal = NULL,
  vertical = NULL,
  partial = FALSE,
  level = 0.975,
  npoints = 100,
  ...
)

## S3 method for class 'list'
setup_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 to extract the observed values of the selected variable for the vertical axis (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 the ellipse. The default is to use 100 grid points.

Details

This function is used internally by ellipse_plot(). It may also be useful for users who want to produce a similar plot, but who want more control over what information to display or how to display that information.

Value

An object of class "setup_ellipse_plot" with the following components:

data

a data frame containing the coordinates of the data points to be plotted on the horizontal axis (column x) and the coordinates on the vertical axis (column y). For robust methods that assign outlyingness weights to each data point, those weights are given in column Weight. If a list of objects has been supplied and there are multiple objects from such robust methods, or if partial residuals are to be plotted on the vertical axis, there is also a column Method, which takes the names or indices of the list elements to indicate the different methods.

ellipse

a data frame containing the coordinates of the tolerance ellipse on the horizontal axis (column x) and on the vertical axis (column y). If a list of objects has been supplied, there is also a column Method, which takes the names or indices of the list elements to indicate the different methods.

line

a data frame with columns intercept and slope containing the intercept and slope, respectively, of the regression line to be plotted. If a list of objects has been supplied, there is also a column Method, which takes the names or indices of the list elements to indicate the different methods. This is only returned 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.

horizontal

a character string giving the variable to be plotted on the horizontal axis.

vertical

a character string giving the variable to be plotted on the vertical axis

partial

a logical indicating whether the values to be plotted on the vertical axis correspond to the observed values of the selected variable (FALSE), or the partial residuals with respect to the variable on the horizontal axis (TRUE).

robust

a logical indicating whether the object contains results from a robust method, or a vector of such logicals if a list of objects has been supplied.

have_methods

a logical indicating whether a list of objects has been supplied.

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(), ellipse_plot()

Examples

data("BSG2014")

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

# set up information for plot
setup <- setup_ellipse_plot(boot)

# plot only data and tolerance ellipse
ggplot() +
  geom_path(aes(x = x, y = y), data = setup$ellipse,
            color = "#00BFC4") +
  geom_point(aes(x = x, y = y, fill = Weight),
             data = setup$data, shape = 21) +
  scale_fill_gradient(limits = 0:1, low = "white",
                      high = "black") +
  labs(x = setup$horizontal, y = setup$vertical)


robmed documentation built on July 9, 2023, 6:29 p.m.