View source: R/setup_ellipse_plot.R
setup_ellipse_plot | R Documentation |
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 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, ...)
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. |
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.
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. |
Andreas Alfons
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.