nice_tidySEM {lavaanExtra} | R Documentation |
Make a quick tidySEM
plot
Description
Make a quick and decent-looking tidySEM
plot.
Usage
nice_tidySEM(
fit,
layout = NULL,
hide_nonsig_edges = FALSE,
hide_var = TRUE,
hide_cov = FALSE,
hide_mean = TRUE,
est_std = TRUE,
label,
label_location = NULL,
reduce_items = NULL,
plot = TRUE,
...
)
Arguments
fit |
SEM or CFA model fit to plot. |
layout |
A matrix (or data.frame) that describes the structure; see
tidySEM::get_layout. If a named list is provided,
with names "IV" (independent variables), "M" (mediator), and
"DV" (dependent variables), |
hide_nonsig_edges |
Logical, hides non-significant edges. Defaults to FALSE. |
hide_var |
Logical, hides variances. Defaults to TRUE. |
hide_cov |
Logical, hides co-variances. Defaults to FALSE. |
hide_mean |
Logical, hides means/node labels. Defaults to TRUE. |
est_std |
Logical, whether to use the standardized coefficients. Defaults to TRUE. |
label |
Labels to be used on the plot. As elsewhere in
|
label_location |
Location of label along the path, as a percentage (defaults to middle, 0.5). |
reduce_items |
A numeric vector of length 1 (x) or 2 (x & y) defining
how much space to trim from the nodes (boxes) of the
items defining the latent variables. Can be provided
either as |
plot |
Logical, whether to plot the result (default). If |
... |
Arguments to be passed to tidySEM::prepare_graph. |
Value
A tidySEM plot, of class ggplot, representing the specified
lavaan
model.
Illustrations
Examples
# Calculate scale averages
library(lavaan)
data <- HolzingerSwineford1939
data$visual <- rowMeans(data[paste0("x", 1:3)])
data$textual <- rowMeans(data[paste0("x", 4:6)])
data$speed <- rowMeans(data[paste0("x", 7:9)])
# Define our variables
IV <- c("sex", "ageyr", "agemo", "school")
M <- c("visual", "grade")
DV <- c("speed", "textual")
# Define our lavaan lists
mediation <- list(speed = M, textual = M, visual = IV, grade = IV)
# Define indirect object
structure <- list(IV = IV, M = M, DV = DV)
# Write the model, and check it
model <- write_lavaan(mediation, indirect = structure, label = TRUE)
cat(model)
# Fit model
fit <- sem(model, data)
# Plot model
nice_tidySEM(fit, layout = structure)