influence_plot {semfindr} | R Documentation |
Plots of Influence Measures
Description
Gets an influence_stat()
output and plots selected
statistics.
Usage
gcd_plot(
influence_out,
cutoff_gcd = NULL,
largest_gcd = 1,
point_aes = list(),
vline_aes = list(),
cutoff_line_aes = list(),
case_label_aes = list()
)
md_plot(
influence_out,
cutoff_md = FALSE,
cutoff_md_qchisq = 0.975,
largest_md = 1,
point_aes = list(),
vline_aes = list(),
cutoff_line_aes = list(),
case_label_aes = list()
)
gcd_gof_plot(
influence_out,
fit_measure,
cutoff_gcd = NULL,
cutoff_fit_measure = NULL,
largest_gcd = 1,
largest_fit_measure = 1,
point_aes = list(),
hline_aes = list(),
cutoff_line_gcd_aes = list(),
cutoff_line_fit_measures_aes = list(),
case_label_aes = list()
)
gcd_gof_md_plot(
influence_out,
fit_measure,
cutoff_md = FALSE,
cutoff_fit_measure = NULL,
circle_size = 2,
cutoff_md_qchisq = 0.975,
cutoff_gcd = NULL,
largest_gcd = 1,
largest_md = 1,
largest_fit_measure = 1,
point_aes = list(),
hline_aes = list(),
cutoff_line_md_aes = list(),
cutoff_line_gcd_aes = list(),
cutoff_line_fit_measures_aes = list(),
case_label_aes = list()
)
Arguments
influence_out |
The output from |
cutoff_gcd |
Cases with generalized Cook's distance or
approximate generalized Cook's distance larger
than this value will be labeled. Default is |
largest_gcd |
The number of cases with the largest generalized Cook's distance or approximate generalized Cook's distance to be labelled. Default is 1. If not an integer, it will be rounded to the nearest integer. |
point_aes |
A named list of
arguments to be passed to
|
vline_aes |
A named list of
arguments to be passed to
|
cutoff_line_aes |
A named list
of arguments to be passed to
|
case_label_aes |
A named list of
arguments to be passed to
|
cutoff_md |
Cases with Mahalanobis distance larger than this
value will be labeled. If it is |
cutoff_md_qchisq |
This value multiplied by 100 is the percentile to be used for labeling case based on Mahalanobis distance. Default is .975. |
largest_md |
The number of cases with the largest Mahalanobis distance to be labelled. Default is 1. If not an integer, it will be rounded to the nearest integer. |
fit_measure |
The fit measure to be used in a
plot. Use the name in the |
cutoff_fit_measure |
Cases with |
largest_fit_measure |
The number of cases with the largest selected fit measure change in magnitude to be labelled. Default is
|
hline_aes |
A named list of
arguments to be passed to
|
cutoff_line_gcd_aes |
Similar
to |
cutoff_line_fit_measures_aes |
Similar
to |
circle_size |
The size of the largest circle when the size of a circle is controlled by a statistic. |
cutoff_line_md_aes |
Similar
to |
Details
The output of influence_stat()
is simply a matrix.
Therefore, these functions will work for any matrix provided. Row
number will be used on the x-axis if applicable. However, case
identification values in the output from influence_stat()
will
be used for labeling individual cases.
The default settings for the plots
should be good enough for diagnostic
purpose. If so desired, users can
use the *_aes
arguments to nearly
fully customize all the major
elements of the plots, as they would
do for building a ggplot2 plot.
Value
A ggplot2 plot. Plotted by default. If assigned to a variable
or called inside a function, it will not be plotted. Use plot()
to
plot it.
Functions
-
gcd_plot()
: Index plot of generalized Cook's distance. -
md_plot()
: Index plot of Mahalanobis distance. -
gcd_gof_plot()
: Plot the case influence of the selected fit measure against generalized Cook's distance. -
gcd_gof_md_plot()
: Bubble plot of the case influence of the selected fit measure against Mahalanobis distance, with the size of a bubble determined by generalized Cook's distance.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448.
References
Pek, J., & MacCallum, R. (2011). Sensitivity analysis in structural equation models: Cases and their influence. Multivariate Behavioral Research, 46(2), 202-228. doi:10.1080/00273171.2011.561068
See Also
Examples
library(lavaan)
dat <- pa_dat
# The model
mod <-
"
m1 ~ a1 * iv1 + a2 * iv2
dv ~ b * m1
a1b := a1 * b
a2b := a2 * b
"
# Fit the model
fit <- lavaan::sem(mod, dat)
summary(fit)
# Fit the model n times. Each time with one case removed.
# For illustration, do this only for selected cases.
fit_rerun <- lavaan_rerun(fit, parallel = FALSE,
to_rerun = 1:10)
# Get all default influence stats
out <- influence_stat(fit_rerun)
head(out)
# Plot generalized Cook's distance. Label the 3 cases with the largest distances.
gcd_plot(out, largest_gcd = 3)
# Plot Mahalanobis distance. Label the 3 cases with the largest distances.
md_plot(out, largest_md = 3)
# Plot case influence on model chi-square against generalized Cook's distance.
# Label the 3 cases with the largest absolute influence.
# Label the 3 cases with the largest generalized Cook's distance.
gcd_gof_plot(out, fit_measure = "chisq", largest_gcd = 3,
largest_fit_measure = 3)
# Plot case influence on model chi-square against Mahalanobis distance.
# Size of bubble determined by generalized Cook's distance.
# Label the 3 cases with the largest absolute influence.
# Label the 3 cases with the largest Mahalanobis distance.
# Label the 3 cases with the largest generalized Cook's distance.
gcd_gof_md_plot(out, fit_measure = "chisq",
largest_gcd = 3,
largest_fit_measure = 3,
largest_md = 3,
circle_size = 10)
# Use the approximate method that does not require refitting the model.
# Fit the model
fit <- lavaan::sem(mod, dat)
summary(fit)
out <- influence_stat(fit)
head(out)
# Plot approximate generalized Cook's distance.
# Label the 3 cases with the largest values.
gcd_plot(out, largest_gcd = 3)
# Plot Mahalanobis distance.
# Label the 3 cases with the largest values.
md_plot(out, largest_md = 3)
# Plot approximate case influence on model chi-square against
# approximate generalized Cook's distance.
# Label the 3 cases with the largest absolute approximate case influence.
# Label the 3 cases with the largest approximate generalized Cook's distance.
gcd_gof_plot(out, fit_measure = "chisq", largest_gcd = 3,
largest_fit_measure = 3)
# Plot approximate case influence on model chi-square against Mahalanobis distance.
# The size of a bubble determined by approximate generalized Cook's distance.
# Label the 3 cases with the largest absolute approximate case influence.
# Label the 3 cases with the largest Mahalanobis distance.
# Label the 3 cases with the largest approximate generalized Cook's distance.
gcd_gof_md_plot(out, fit_measure = "chisq",
largest_gcd = 3,
largest_fit_measure = 3,
largest_md = 3,
circle_size = 10)
# Customize elements in the plot.
# For example, change the color and shape of the points.
gcd_gof_plot(out, fit_measure = "chisq", largest_gcd = 3,
largest_fit_measure = 3,
point_aes = list(shape = 3, color = "red"))