Extract the relevant information for a diagnostic plot with a tolerance ellipse from results of (robust) mediation analysis.
setup_ellipse_plot(object, ...)# S3 method for test_mediation
setup_ellipse_plot(object, ...)
# S3 method for reg_fit_mediation
setup_ellipse_plot(
object,
horizontal = NULL,
vertical = NULL,
partial = FALSE,
level = 0.975,
npoints = 100,
...
)
# S3 method for cov_fit_mediation
setup_ellipse_plot(
object,
horizontal = NULL,
vertical = NULL,
partial = FALSE,
level = 0.975,
npoints = 100,
...
)
# S3 method for list
setup_ellipse_plot(object, ...)
An object of class "setup_ellipse_plot"
with the following
components:
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.
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.
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.
a character string giving the variable to be plotted on the horizontal axis.
a character string giving the variable to be plotted on the vertical axis
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
).
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.
a logical indicating whether a list of objects has been supplied.
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.
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.
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.
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.
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.
the number of grid points used to evaluate the ellipse. The default is to use 100 grid points.
Andreas Alfons
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.
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.
fit_mediation()
, test_mediation()
,
ellipse_plot()
data("BSG2014")
# fit mediation model
fit <- fit_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
# set up information for plot
setup <- setup_ellipse_plot(fit)
# 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)
Run the code above in your browser using DataLab