Tài liệu phục vụ HỘI THẢO THỐNG KÊ TRONG KHOA HỌC XÃ HỘI VỚI PHẦN MỀM MÃ NGUỒN MỞ R Chi tiết tại: https://sites.google.com/view/tkud https://viasm.edu.vn/

GIỚI THIỆU

Dữ liệu sử dụng trong hướng dẫn này là của PGS.TS Trần Văn Trang (Đại học Thương mại).

Bài báo gốc lấy tại: http://tckhtm.tmu.edu.vn/vi/news/cac-so-tap-chi/tap-chi-khoa-hoc-thuong-mai-so-141-153.html

Dữ liệu tải tại google diver: https://drive.google.com/drive/folders/1Npip6h8WyZjI9JGf5wonnU_scBUYj4sP?usp=sharing

Load các gói cần thiết và nhập liệu

setwd("D:/Tap huan VIASM/HoiThao_KHXH_2021/Projects/Y_Dinh_Hanh_Vi")

library(foreign)
require(tidyverse)
require(lavaan)
require(semPlot)
d <- read.spss("Case study Behavior Intention.sav",
               use.value.label=TRUE, to.data.frame=TRUE)

1. Lọc các biến quan sát (items)

d1 <-  d %>% select(-c("STT",  "FAM", "Formation",
                       "Work",  "Year",
                       "BI1",     "BIRecode", "BI4"))

2. Tìm hiểu các hàm trong gói semPlot tại:

https://cran.r-project.org/web/packages/semPlot/semPlot.pdf

3.Fit model CFA

cfa.model4a <- ' BEINTEN =~  BI2 + BI3 + BI5 + BI6 
              RELA =~ REL1 + REL2 + REL3+ REL4
              EDUC =~ EDU1 + EDU2 + EDU3 + EDU4 + EDU5 + EDU6 + EDU7  +  EDU8
              GOVE =~ GOV1 + GOV2 + GOV3 + GOV4 + GOV5
              ENDO =~   END2 + END3 + END4 + END5  
#  Covariance
BI2 ~~ BI3
REL4  ~~ REL1 + REL3
EDU2 ~~ EDU1 + EDU3 + EDU6
EDU5 ~~ EDU6
EDU7 ~~ EDU8
GOV4 ~~ GOV5
END5 ~~ END4 ' 
cfa.d4a <- cfa(cfa.model4a, data = d1)

4. Vẽ digram

semPaths(cfa.d4a, "std", edge.label.cex = 0.8, 
         curvePivot = TRUE, rotation = 1,
         intercepts = FALSE,
         fade = FALSE,
         #sizeMan2 = 1.8, # size box of items
         edge.width = 0.9,# width size of edge.x
         covAtResiduals = FALSE,
         node.width = 1, # size of latent circle
         esize = 0.1, # Size of circle correlation
         #asize = 2.5, # size arrow
         residScale = 1, 
         layout = "spring") 

5. Vẽ với tham số điều chỉnh layout = “tree”

semPaths(cfa.d4a, "std", edge.label.cex = 0.8, 
         curvePivot = TRUE, rotation = 1,
         intercepts = FALSE,
         fade = FALSE,
         #sizeMan2 = 1.8, # size box of items
         edge.width = 0.9,# width size of edge.x
         covAtResiduals = FALSE,
         node.width = 1, # size of latent circle
         esize = 0.1, # Size of circle correlation
         #asize = 2.5, # size arrow
         residScale = 1, 
         layout = "tree") 

Trân trọng cảm ơn!