Learn R Programming

tidySEM (version 0.1.9)

get_edges: Extract edges from a SEM model object

Description

Attempts to extract edges from a SEM model object, where edges are defined as regression paths and covariances between variables (nodes).

Usage

get_edges(x, label = "est_sig", ...)

Arguments

x

A model object of class mplusObject or lavaan.

label

Either a character, indicating which column to use for edge labels, or an expression. See Details. Defaults to "est_sig", which labels edges with the estimated value with significance asterisks, as obtained from table_results. See Details and examples for more information.

...

Additional parameters passed to table_results. For example, users can pass the digits argument to control the number of digits in the edge label, or pass the columns argument to retain auxiliary columns in the tidy_edges data.frame for further processing (see Examples).

Value

An object of class 'tidy_edges'

Details

The function get_edges identifies all regression paths, latent variable definitions, and covariances in the model as edges. The output of table_results for those paths is used to label the edges.

## Custom labels

One way to create custom edge labels is by passing an expression to label. When an expression is passed to label, it is evaluated in the context of a data.frame containing the results of a call to table_results on the x argument.

Another way to create custom labels is by requesting auxiliary variables using the columns argument (which is passed to table_results), and then using these columns to construct a new label. See examples.

Examples

Run this code
# NOT RUN {
# Standard use
library(lavaan)
res <- sem("dist ~ speed", cars)
get_edges(res)

# Pass an expression to the 'label' argument for custom labels
get_edges(res, label = paste(est_sig, confint))

# Pass the argument 'columns' to table_results through '...' to retain
# auxiliary columns for further processing
edg <- get_edges(res, columns = c("est_sig", "confint"))
edg
edg <- within(edg, {label <- paste(est_sig, confint)})
edg
# }

Run the code above in your browser using DataLab