setup_ellipse_plot {robmed} | R 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 |
... |
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 ( |
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 |
ellipse |
a data frame containing the coordinates of the tolerance
ellipse on the horizontal axis (column |
line |
a data frame with columns |
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
( |
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)