rr-lavaanstructural-equation-modelcausalitysemplot

Path diagram in r


I am trying to plot a path diagram of a Structural Equation Model(SEM) in R. I was able to plot it using semPlot::semPaths(). The output is similar to enter image description here The SEM was modeled using lavaan package.

I want a plot similar to enter image description here. with estimates and p values. Can anyone help me out?


Solution

  • My suggestion would be lavaanPlot (see more of it in the author's personal website):

    library(lavaan)
    library(lavaanPlot)
    # path model
    model <- 'mpg ~ cyl + disp + hp
              qsec ~ disp + hp + wt'
    
    fit1 <- sem(model, data = mtcars)
    labels1 <- list(mpg = "Miles Per Gallon", cyl = "Cylinders", disp = "Displacement", hp = "Horsepower", qsec = "Speed", wt = "Weight") #define labels
    lavaanPlot(model = fit1, labels = labels1, coefs = TRUE, stand = TRUE, sig = 0.05) #standardized regression paths, showing only paths with p<= .05
    

    enter image description here