Skip to contents

Add a fit object (e.g., 'lavaan' output) to the a 'qgraph' object as an attribute.

Usage

add_object(semPaths_plot, object)

Arguments

semPaths_plot

A qgraph::qgraph object generated by semPlot::semPaths(), or a similar qgraph::qgraph object modified by other semptools functions.

object

Should be the object, such as the output of lavaan::sem() or lavaan::cfa(), used by semPlot::semPaths() to generate semPaths_plot. Note that this function will not check whether the object is appropriate because there is no way to do so reliably.

Value

The original qgraph::qgraph object set to semPaths_plot, with the attribute "semptools_fit_object" set to object.

Details

It adds an object to a qgraph::qgraph object as the attribute "semptools_fit_object", to be retrieved by other functions that need to access the original output used in semPlot::semPaths() to create a diagram.

Examples


library(lavaan)
#> This is lavaan 0.6-19
#> lavaan is FREE software! Please report any bugs.
library(semPlot)

mod <-
  'f1 =~ x01 + x02 + x03 + x06
   f2 =~ x04 + x05 + x06 + x07
   f3 =~ x08 + x09 + x10 + x03
   f4 =~ x11 + x12 + x13 + x14
  '
fit <- lavaan::cfa(mod, cfa_example)
p <- semPaths(fit,
              whatLabels = "est",
              sizeMan = 3.25,
              node.width = 1,
              edge.label.cex = .75,
              mar = c(10, 5, 10, 5),
              DoNotPlot = TRUE)
p <- add_object(p, fit)
attr(p, "semptools_fit_object")
#> lavaan 0.6-19 ended normally after 41 iterations
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                        36
#> 
#>   Number of observations                           200
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                75.495
#>   Degrees of freedom                                69
#>   P-value (Chi-square)                           0.277