使用 semPaths() 建立圖形

在 R 中使用 lavaan 的結構方程模型

Erin Buchanan

Professor

semPlot 與 semPaths()

library(lavaan)
library(semPlot)
twofactor.model <- 'text =~ x4 + x5 + x6
    speed =~ x7 + x8 + x9'
twofactor.fit <- cfa(model = twofactor.model, 
                     data = HolzingerSwineford1939)
semPaths(object = twofactor.fit)
在 R 中使用 lavaan 的結構方程模型

semPaths() 的預設輸出

semPaths 的預設圖

在 R 中使用 lavaan 的結構方程模型

編修圖形

semPaths(object = twofactor.fit,
         whatLabels = "std", 
         edge.label.cex = 1)
#whatLabels 也可用 "par" 

加上邊標籤的更新模型圖

在 R 中使用 lavaan 的結構方程模型

圖形版面

semPaths(object = twofactor.fit,
          whatLabels = "std", 
          edge.label.cex = 1, 
          layout = "circle")
#layout 選項:tree、circle、spring、tree2、circle2

版面改為圓形配置

在 R 中使用 lavaan 的結構方程模型

圖形旋轉

semPaths(object = twofactor.fit,
          whatLabels = "std", 
          edge.label.cex = 1, 
          layout = "tree", rotation = 2)
#tree 版面的 rotation 選項為 1、2、3、4

樹狀旋轉後,潛在變數在左側

在 R 中使用 lavaan 的結構方程模型

色彩視覺化

semPaths(object = twofactor.fit,
         whatLabels = "std", 
         edge.label.cex = 1, 
         layout = "tree", rotation = 2,
         what = "std", edge.color = "purple")
#what 選項包含 par 與 std

色彩更新為淡紫

在 R 中使用 lavaan 的結構方程模型

一起來練習吧!

在 R 中使用 lavaan 的結構方程模型

Preparing Video For Download...