Bước 1: Load packages cần thiết cho quá trình phân tích.
# install.packages("tm")
# install.packages("SnowballC")
# install.packages("wordcloud")
# install.packages("wordcloud2")
library(readxl)
library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
library(SensoMineR)
library(FactoMineR)
library(wordcloud2)
library(tidyverse)
Bước 2: Import data
JapTea_VNConsu <- read_excel("2015-Data Tra Viet Tra Nhat-QMFS/Tea_WordCloud.xlsx", sheet = "Japantea-VNthink")
print(JapTea_VNConsu)
## # A tibble: 95 x 3
## Word Frequence English
## <chr> <dbl> <chr>
## 1 Tra dao 30 Tea ceremony
## 2 Mui thom 18 Odor
## 3 Vi dang 15 Bitter
## 4 Matcha 12 Matcha
## 5 Cach pha doc dao va ti ~ 10 Making a cup of tea is original and metic~
## 6 Dat tien 10 Expensive
## 7 Kimono 9 Kimono
## 8 Mau xanh 8 Green
## 9 Van hoa tra Nhat 8 Japan tea culture
## 10 Cach pha tra 8 Making a cup of tea
## # ... with 85 more rows
Bước 3: Plot wordcloud Bạn có thể thay đổi 2 arguments sau để làm phong phú cách trình bày của wordcloud: max.words=80
, rot.per=0.35
, colors=brewer.pal(8, "Paired"))
.
# plot wordcloud
set.seed(1234) # for reproducibility
wordcloud(words = JapTea_VNConsu$Word, freq = JapTea_VNConsu$Frequence,
min.freq = 2, max.words=30, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
Bước 1.1. Load các packages cần thiết
library(readxl)
library(semPlot)
library(lavaan)
library(psy)
library(psych)
Bước 1.2. Nhập dữ liệu từ file excel, quan sát cấu trúc dữ liệu.
# Import data
library(readxl)
greentea <- read.table("D:/Dropbox/Luan van TS-Le Thuy Linh/08. Data/greenteaFCQ.txt", header=TRUE, row.names=1)
summary(greentea)
## Se1 Se2 Se3 Se4 He1
## Min. :2.000 Min. :1.000 Min. :1 Min. :1.00 Min. :1.000
## 1st Qu.:4.000 1st Qu.:4.000 1st Qu.:3 1st Qu.:3.00 1st Qu.:3.000
## Median :4.000 Median :4.000 Median :4 Median :4.00 Median :4.000
## Mean :4.314 Mean :4.279 Mean :4 Mean :4.04 Mean :4.057
## 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:5 3rd Qu.:5.00 3rd Qu.:5.000
## Max. :5.000 Max. :5.000 Max. :5 Max. :5.00 Max. :5.000
## He2 He3 Tra1 Tra2 Tra3
## Min. :1.00 Min. :1.000 Min. :1.000 Min. :1.00 Min. :1.000
## 1st Qu.:4.00 1st Qu.:3.000 1st Qu.:4.000 1st Qu.:3.00 1st Qu.:3.000
## Median :4.00 Median :4.000 Median :4.000 Median :4.00 Median :3.000
## Mean :4.17 Mean :3.881 Mean :4.247 Mean :3.64 Mean :3.556
## 3rd Qu.:5.00 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:4.00 3rd Qu.:4.000
## Max. :5.00 Max. :5.000 Max. :6.000 Max. :5.00 Max. :5.000
## Tra4 Tra5 Qu1 Qu2
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:3.000 1st Qu.:3.000 1st Qu.:3.000 1st Qu.:4.000
## Median :4.000 Median :4.000 Median :4.000 Median :4.000
## Mean :4.012 Mean :3.721 Mean :4.074 Mean :4.079
## 3rd Qu.:5.000 3rd Qu.:4.000 3rd Qu.:5.000 3rd Qu.:5.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
## Qu3 Qu4 Pr1 Pr2
## Min. :2.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:4.000 1st Qu.:3.000 1st Qu.:3.000 1st Qu.:3.000
## Median :5.000 Median :4.000 Median :4.000 Median :4.000
## Mean :4.417 Mean :3.904 Mean :4.022 Mean :3.953
## 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:5.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
## Pr3 Co1 Co2 Co3 Co4
## Min. :1.000 Min. :1.00 Min. :1.00 Min. :1.000 Min. :1.000
## 1st Qu.:4.000 1st Qu.:4.00 1st Qu.:4.00 1st Qu.:4.000 1st Qu.:4.000
## Median :4.000 Median :4.00 Median :4.00 Median :4.000 Median :5.000
## Mean :4.289 Mean :4.22 Mean :4.23 Mean :4.242 Mean :4.306
## 3rd Qu.:5.000 3rd Qu.:5.00 3rd Qu.:5.00 3rd Qu.:5.000 3rd Qu.:5.000
## Max. :5.000 Max. :5.00 Max. :5.00 Max. :5.000 Max. :5.000
# Step 1: specifying the model
gtmod1_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4
healthy =~ He1 + He2 + He3
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
'
# Step 2: fiting model
gtmod1_cfa_fit <- cfa(model = gtmod1_cfa, data= greentea)
## Warning in lav_object_post_check(object): lavaan WARNING: covariance matrix of latent variables
## is not positive definite;
## use lavInspect(fit, "cov.lv") to investigate.
summary(gtmod1_cfa_fit, standardized = TRUE, fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 67 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 61
##
## Number of observations 405
##
## Model Test User Model:
##
## Test statistic 858.600
## Degrees of freedom 215
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 3119.049
## Degrees of freedom 253
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.775
## Tucker-Lewis Index (TLI) 0.736
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -10751.368
## Loglikelihood unrestricted model (H1) -10322.067
##
## Akaike (AIC) 21624.735
## Bayesian (BIC) 21868.972
## Sample-size adjusted Bayesian (BIC) 21675.412
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.086
## 90 Percent confidence interval - lower 0.080
## 90 Percent confidence interval - upper 0.092
## P-value RMSEA <= 0.05 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.074
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.395 0.569
## Se2 0.871 0.121 7.194 0.000 0.344 0.437
## Se3 1.596 0.165 9.646 0.000 0.631 0.655
## Se4 1.555 0.156 9.992 0.000 0.615 0.694
## healthy =~
## He1 1.000 0.644 0.767
## He2 0.848 0.087 9.762 0.000 0.546 0.606
## He3 1.039 0.099 10.463 0.000 0.669 0.694
## tradition =~
## Tra1 1.000 0.430 0.517
## Tra2 1.311 0.160 8.186 0.000 0.564 0.568
## Tra3 1.345 0.157 8.554 0.000 0.579 0.612
## Tra4 0.767 0.122 6.305 0.000 0.330 0.391
## Tra5 1.175 0.148 7.914 0.000 0.506 0.538
## quality =~
## Qu1 1.000 0.614 0.688
## Qu2 0.886 0.088 10.010 0.000 0.543 0.606
## Qu3 0.695 0.071 9.815 0.000 0.427 0.592
## Qu4 0.775 0.093 8.335 0.000 0.475 0.490
## price =~
## Pr1 1.000 0.478 0.564
## Pr2 1.028 0.129 7.996 0.000 0.492 0.498
## Pr3 0.859 0.099 8.667 0.000 0.411 0.556
## convenience =~
## Co1 1.000 0.512 0.623
## Co2 1.156 0.108 10.688 0.000 0.592 0.692
## Co3 1.085 0.104 10.421 0.000 0.555 0.667
## Co4 1.046 0.106 9.855 0.000 0.535 0.618
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory ~~
## healthy 0.091 0.020 4.631 0.000 0.356 0.356
## tradition 0.140 0.021 6.691 0.000 0.822 0.822
## quality 0.165 0.024 6.909 0.000 0.679 0.679
## price 0.166 0.023 7.086 0.000 0.879 0.879
## convenience 0.163 0.022 7.277 0.000 0.808 0.808
## healthy ~~
## tradition 0.164 0.026 6.279 0.000 0.592 0.592
## quality 0.170 0.031 5.572 0.000 0.431 0.431
## price 0.128 0.027 4.816 0.000 0.415 0.415
## convenience 0.081 0.023 3.502 0.000 0.246 0.246
## tradition ~~
## quality 0.215 0.030 7.110 0.000 0.814 0.814
## price 0.172 0.026 6.594 0.000 0.835 0.835
## convenience 0.118 0.021 5.730 0.000 0.538 0.538
## quality ~~
## price 0.221 0.031 7.035 0.000 0.752 0.752
## convenience 0.212 0.029 7.202 0.000 0.675 0.675
## price ~~
## convenience 0.212 0.029 7.360 0.000 0.868 0.868
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.326 0.026 12.740 0.000 0.326 0.676
## .Se2 0.502 0.037 13.519 0.000 0.502 0.809
## .Se3 0.530 0.045 11.815 0.000 0.530 0.571
## .Se4 0.406 0.036 11.154 0.000 0.406 0.518
## .He1 0.291 0.039 7.527 0.000 0.291 0.412
## .He2 0.515 0.045 11.537 0.000 0.515 0.633
## .He3 0.481 0.050 9.677 0.000 0.481 0.518
## .Tra1 0.509 0.039 13.080 0.000 0.509 0.733
## .Tra2 0.668 0.053 12.684 0.000 0.668 0.677
## .Tra3 0.559 0.046 12.230 0.000 0.559 0.625
## .Tra4 0.604 0.044 13.683 0.000 0.604 0.847
## .Tra5 0.627 0.048 12.927 0.000 0.627 0.710
## .Qu1 0.418 0.039 10.628 0.000 0.418 0.526
## .Qu2 0.508 0.042 11.961 0.000 0.508 0.633
## .Qu3 0.338 0.028 12.132 0.000 0.338 0.650
## .Qu4 0.715 0.055 13.020 0.000 0.715 0.760
## .Pr1 0.489 0.040 12.213 0.000 0.489 0.681
## .Pr2 0.731 0.056 12.955 0.000 0.731 0.752
## .Pr3 0.377 0.031 12.327 0.000 0.377 0.691
## .Co1 0.414 0.034 12.199 0.000 0.414 0.612
## .Co2 0.380 0.034 11.235 0.000 0.380 0.521
## .Co3 0.384 0.033 11.635 0.000 0.384 0.555
## .Co4 0.464 0.038 12.253 0.000 0.464 0.619
## sensory 0.156 0.027 5.694 0.000 1.000 1.000
## healthy 0.415 0.056 7.432 0.000 1.000 1.000
## tradition 0.185 0.037 5.068 0.000 1.000 1.000
## quality 0.376 0.054 6.945 0.000 1.000 1.000
## price 0.229 0.042 5.411 0.000 1.000 1.000
## convenience 0.262 0.041 6.325 0.000 1.000 1.000
fitMeasures(gtmod1_cfa_fit, c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.775 0.736 0.086 0.074
# Step 3: improving model
modificationindices(gtmod1_cfa_fit, sort=TRUE)
gtmod2_cfa <- '
healthy =~ He1 + He2 + He3
quality =~ Qu1 + Qu2 + Qu3
convenience =~ Co1 + Co2 + Co3
tradition =~ Tra2 + Tra3 + Tra5
'
gtmod2_cfa_fit <- cfa(model = gtmod2_cfa, data= greentea)
summary(gtmod2_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 33 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 30
##
## Number of observations 405
##
## Model Test User Model:
##
## Test statistic 196.504
## Degrees of freedom 48
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1255.252
## Degrees of freedom 66
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.875
## Tucker-Lewis Index (TLI) 0.828
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -5747.150
## Loglikelihood unrestricted model (H1) -5648.899
##
## Akaike (AIC) 11554.301
## Bayesian (BIC) 11674.417
## Sample-size adjusted Bayesian (BIC) 11579.224
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.087
## 90 Percent confidence interval - lower 0.075
## 90 Percent confidence interval - upper 0.100
## P-value RMSEA <= 0.05 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.067
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## healthy =~
## He1 1.000 0.650 0.774
## He2 0.823 0.086 9.615 0.000 0.535 0.593
## He3 1.034 0.099 10.442 0.000 0.672 0.697
## quality =~
## Qu1 1.000 0.655 0.735
## Qu2 0.904 0.093 9.729 0.000 0.592 0.660
## Qu3 0.604 0.070 8.686 0.000 0.396 0.549
## convenience =~
## Co1 1.000 0.586 0.713
## Co2 1.095 0.111 9.892 0.000 0.642 0.751
## Co3 0.747 0.088 8.484 0.000 0.438 0.527
## tradition =~
## Tra2 1.000 0.614 0.618
## Tra3 0.970 0.113 8.580 0.000 0.596 0.630
## Tra5 0.820 0.105 7.802 0.000 0.504 0.536
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## healthy ~~
## quality 0.140 0.031 4.498 0.000 0.330 0.330
## convenience 0.115 0.027 4.187 0.000 0.302 0.302
## tradition 0.239 0.036 6.558 0.000 0.599 0.599
## quality ~~
## convenience 0.206 0.032 6.370 0.000 0.535 0.535
## tradition 0.260 0.039 6.693 0.000 0.647 0.647
## convenience ~~
## tradition 0.171 0.032 5.434 0.000 0.476 0.476
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .He1 0.283 0.039 7.243 0.000 0.283 0.401
## .He2 0.527 0.045 11.725 0.000 0.527 0.648
## .He3 0.477 0.050 9.566 0.000 0.477 0.514
## .Qu1 0.366 0.045 8.183 0.000 0.366 0.460
## .Qu2 0.453 0.045 10.173 0.000 0.453 0.564
## .Qu3 0.363 0.030 12.056 0.000 0.363 0.699
## .Co1 0.331 0.038 8.687 0.000 0.331 0.491
## .Co2 0.318 0.042 7.532 0.000 0.318 0.436
## .Co3 0.500 0.040 12.362 0.000 0.500 0.723
## .Tra2 0.609 0.057 10.648 0.000 0.609 0.618
## .Tra3 0.539 0.052 10.403 0.000 0.539 0.603
## .Tra5 0.629 0.053 11.943 0.000 0.629 0.713
## healthy 0.423 0.057 7.478 0.000 1.000 1.000
## quality 0.429 0.062 6.965 0.000 1.000 1.000
## convenience 0.344 0.051 6.712 0.000 1.000 1.000
## tradition 0.377 0.066 5.675 0.000 1.000 1.000
fitMeasures(gtmod2_cfa_fit, c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.875 0.828 0.087 0.067
modificationindices(gtmod2_cfa_fit, sort=TRUE)
lavInspect(gtmod2_cfa_fit, "cov.lv") # no negative or zero variances
## helthy qualty cnvnnc tradtn
## healthy 0.423
## quality 0.140 0.429
## convenience 0.115 0.206 0.344
## tradition 0.239 0.260 0.171 0.377
## model comparison
anova(gtmod1_cfa_fit, gtmod2_cfa_fit)
## Warning in lavTestLRT(object = new("lavaan", version = "0.6.6", call =
## lavaan::lavaan(model = gtmod1_cfa, : lavaan WARNING: some models are based on a
## different set of observed variables
library(semPlot)
semPaths(gtmod2_cfa_fit,
whatLabels = "std",
edge.label.cex = 1,
layout = "tree",
rotation = 2)
library(readxl)
library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
library(SensoMineR)
library(FactoMineR)
library(wordcloud2)
library(tidyverse)
fishsauce.wa <- read_excel("2019-QMFS-CFA fish sauce/Wordcloud-fish sauce/Wordcloud-fish sauce-english.xlsx",
sheet = "runwordcloud")
## New names:
## * `` -> ...1
print(fishsauce.wa)
## # A tibble: 43 x 3
## ...1 word Frequence
## <dbl> <chr> <dbl>
## 1 1 delicious 192
## 2 2 tasty 85
## 3 3 salty 74
## 4 4 smell 38
## 5 5 traditional 36
## 6 6 safety 34
## 7 7 quality 23
## 8 8 brown 22
## 9 9 fish 17
## 10 10 nutrient 17
## # ... with 33 more rows
set.seed(1234) # for reproducibility
wordcloud(words = fishsauce.wa$word, freq = fishsauce.wa$Frequence,
min.freq = 1, max.words=40, random.order=FALSE, rot.per=0,
colors=brewer.pal(8, "Dark2"))
Bước 1.1. Load các packages cần thiết
# require packages
library(readxl)
library(semPlot)
library(lavaan)
library(psy)
library(psych)
getOption("max.print")
## [1] 99999
Bước 1.2. Nhập dữ liệu từ file excel, quan sát cấu trúc dữ liệu.
# Import data
fishsauce <- read_excel("2019-QMFS-CFA fish sauce/CFA-data-fish sauce/fishsauce.xls")
fishsauce
Trong bảng dữ liệu là thông tin thu thập từ 6 factors với số lượng items tương ứng như sau: Sensory (Se1, Se2, Se3, Se4, Se5), Health (He1, He2, He3), Traditional value (Tra1, Tra2, Tra3), Quality and Safety (Qu1, Qu2, Qu3, Qu4), Price (Pr1, Pr2, Pr3) và Convenience (Co1, Co2, Co3, Co4). Nội dung chi tiết các items như sau:
Kiểm tra hệ số Cronbach's alpha
và hệ số tương quan biến tổng
Mục đích: xem xét tính đặc trưng của các items trong factor. Tiêu chuẩn lựa chọn:
Cronbach's alpha
\(> 0.3\) sẽ được giữ lạicronchbach alpha
\(< 0.3\) sẽ được loại bỏ# Cronchbach alpha
alpha_Se <- psy::cronbach(fishsauce[,1:5])[[3]] # Sensory
alpha_He <- psy::cronbach(fishsauce[,6:8])[[3]] # Health
alpha_Tra <- round(psy::cronbach(fishsauce[,9:13])[[3]],3) # Tradition
alpha_Qu <- round(psy::cronbach(fishsauce[,14:17])[[3]],3) # Quality
alpha_Pr <- round(psy::cronbach(fishsauce[,18:20])[[3]],3) # Price
alpha_Co <- round(psy::cronbach(fishsauce[,21:24])[[3]],3) # Convenience
cat("croch.alpha_Sensory = ", round(alpha_Se,3), "\n")
## croch.alpha_Sensory = 0.744
cat("croch.alpha_Healthy = ", round(alpha_He,3), "\n")
## croch.alpha_Healthy = 0.451
cat("croch.alpha_Traditional value = ", round(alpha_Tra,3), "\n")
## croch.alpha_Traditional value = 0.651
cat("croch.alpha_Quality and safety = ", round(alpha_Qu,3), "\n")
## croch.alpha_Quality and safety = 0.632
cat("croch.alpha_Price = ", round(alpha_Pr,3), "\n")
## croch.alpha_Price = 0.628
cat("croch.alpha_Convenience = ", round(alpha_Co,3), "\n")
## croch.alpha_Convenience = 0.704
Kết quả phân tích cho thấy hệ số Cronbach’s alpha của bảng câu hỏi dược thiết kế tốt.
Phần bên dưới trình bày cách thức các bạn viết mô hình trong môi trường R
. Trong đó, latent variable
lần lượt là sensory
, healthy
, tradition
, quality
, price
và convenience
.
=~
: tạo biến latent variables
dựa trên manifest variables
.+
: biểu diễn sự liên kết giữa các items trong cùng một factor.~
: định nghĩa mối quan hệ trực tiếp giữa các biếny~~ 0*x
Tiến trình phân tích qua 4 bước:
Bước 1: Định nghĩa mô hình lý thuyết Mô hình lý thuyết là mô hình biểu diễn mối quan hệ giữa các biến. Trong mô hình này, mối quan hệ giữa latent variable
và manifest variables
được thiết lập bằng toán tử =~
. Mô hình lý thuyết được đặt vào dấu ngoặc (''
).
# Step 1: specifying the model
model1_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4 + Se5
healthy =~ He1 + He2 + He3
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
'
Bước 2: Phân tích mô hình Phân tích mô hình nghĩa là đánh giá độ phù hợp của dữ liệu với mô hình lý thuyết. Phương pháp phân tích nhân tố khẳng định (Confirmatory factor analysis) được sử dụng. Mục đích của phương pháp nhằm đánh giá mức độ phù hợp của dữ liệu thu thập được với mô hình lý thuyết.
Trong môi trường R, phân tích nhân tố khẳng định được thực hiện bằng hàm cfa()
kèm theo \(02\) arguments:
model =
: tên mô hình lý thuyết được đề xuất.data =
: tên dữ liệu chứa các biến được định nghĩa.# Step 2: fitting the model
model1_cfa_fit <- cfa(model = model1_cfa,
data = fishsauce)
Bước 3: Đánh giá mức độ phù hợp của mô hình Mức độ phù hợp của mô hình thường được đánh giá thông qua 4 chỉ số thống kê (model fit indices). Trong đó, có 4 chỉ số thống kê quan trọng thường được đề cập trong các bài báo khoa học và các phần mềm thống kê gồm: Tucker-Lewis Index(TLI), Comparative Fit Index (CFI), Root Mean Square Error of Approximation (RMSEA) và Standardized Root Mean Square Residual (SRMR). Bên dưới là các thông tin lưu ý khi giải thích các chỉ số thống kê này:
Có hai cách để truy xuất chỉ số thống kê của mô hình. Cách thứ 1, sử dụng argument fit.measure=TRUE
trong function summary()
. Cách thứ 2, sử dụng function fitMeasure()
.
# Step 3: assessing GOF
summary(model1_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 98 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 63
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 493.890
## Degrees of freedom 237
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1778.017
## Degrees of freedom 276
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.829
## Tucker-Lewis Index (TLI) 0.801
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -8311.620
## Loglikelihood unrestricted model (H1) -8064.675
##
## Akaike (AIC) 16749.239
## Bayesian (BIC) 16982.578
## Sample-size adjusted Bayesian (BIC) 16782.779
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.060
## 90 Percent confidence interval - lower 0.053
## 90 Percent confidence interval - upper 0.068
## P-value RMSEA <= 0.05 0.014
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.066
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.345 0.425
## Se2 0.825 0.175 4.708 0.000 0.285 0.343
## Se3 2.195 0.300 7.322 0.000 0.758 0.875
## Se4 1.008 0.189 5.336 0.000 0.348 0.415
## Se5 2.134 0.292 7.318 0.000 0.737 0.901
## healthy =~
## He1 1.000 0.406 0.486
## He2 0.807 0.211 3.826 0.000 0.328 0.363
## He3 1.169 0.261 4.480 0.000 0.475 0.507
## tradition =~
## Tra1 1.000 0.275 0.375
## Tra2 1.909 0.379 5.039 0.000 0.526 0.628
## Tra3 1.573 0.329 4.777 0.000 0.433 0.527
## Tra4 1.416 0.306 4.625 0.000 0.390 0.485
## Tra5 1.716 0.351 4.892 0.000 0.473 0.565
## quality =~
## Qu1 1.000 0.431 0.470
## Qu2 1.422 0.229 6.205 0.000 0.613 0.722
## Qu3 1.214 0.202 5.996 0.000 0.523 0.603
## Qu4 1.008 0.197 5.115 0.000 0.435 0.442
## price =~
## Pr1 1.000 0.637 0.708
## Pr2 0.909 0.129 7.064 0.000 0.579 0.622
## Pr3 0.647 0.101 6.388 0.000 0.412 0.507
## convenience =~
## Co1 1.000 0.370 0.534
## Co2 1.085 0.167 6.486 0.000 0.402 0.544
## Co3 1.631 0.221 7.390 0.000 0.604 0.737
## Co4 1.383 0.197 7.024 0.000 0.512 0.628
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory ~~
## healthy 0.009 0.013 0.667 0.505 0.062 0.062
## tradition 0.007 0.007 0.901 0.368 0.069 0.069
## quality 0.075 0.018 4.156 0.000 0.503 0.503
## price 0.010 0.017 0.625 0.532 0.047 0.047
## convenience -0.007 0.009 -0.795 0.427 -0.058 -0.058
## healthy ~~
## tradition 0.070 0.019 3.647 0.000 0.629 0.629
## quality -0.005 0.018 -0.259 0.795 -0.027 -0.027
## price 0.131 0.034 3.864 0.000 0.504 0.504
## convenience 0.057 0.018 3.122 0.002 0.375 0.375
## tradition ~~
## quality -0.003 0.010 -0.328 0.743 -0.028 -0.028
## price 0.076 0.021 3.655 0.000 0.435 0.435
## convenience 0.049 0.013 3.732 0.000 0.481 0.481
## quality ~~
## price 0.041 0.024 1.691 0.091 0.150 0.150
## convenience -0.007 0.013 -0.570 0.569 -0.047 -0.047
## price ~~
## convenience 0.114 0.025 4.600 0.000 0.485 0.485
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.540 0.045 11.919 0.000 0.540 0.819
## .Se2 0.608 0.050 12.050 0.000 0.608 0.882
## .Se3 0.176 0.032 5.457 0.000 0.176 0.235
## .Se4 0.584 0.049 11.939 0.000 0.584 0.828
## .Se5 0.126 0.029 4.342 0.000 0.126 0.189
## .He1 0.534 0.058 9.228 0.000 0.534 0.764
## .He2 0.706 0.065 10.820 0.000 0.706 0.868
## .He3 0.651 0.074 8.831 0.000 0.651 0.742
## .Tra1 0.463 0.041 11.417 0.000 0.463 0.859
## .Tra2 0.424 0.048 8.881 0.000 0.424 0.605
## .Tra3 0.489 0.048 10.275 0.000 0.489 0.722
## .Tra4 0.495 0.046 10.676 0.000 0.495 0.765
## .Tra5 0.477 0.049 9.835 0.000 0.477 0.681
## .Qu1 0.654 0.061 10.809 0.000 0.654 0.779
## .Qu2 0.346 0.052 6.692 0.000 0.346 0.479
## .Qu3 0.478 0.052 9.212 0.000 0.478 0.636
## .Qu4 0.777 0.070 11.023 0.000 0.777 0.804
## .Pr1 0.403 0.060 6.713 0.000 0.403 0.499
## .Pr2 0.531 0.061 8.662 0.000 0.531 0.613
## .Pr3 0.490 0.047 10.373 0.000 0.490 0.743
## .Co1 0.344 0.033 10.560 0.000 0.344 0.715
## .Co2 0.384 0.037 10.466 0.000 0.384 0.704
## .Co3 0.307 0.043 7.178 0.000 0.307 0.457
## .Co4 0.403 0.043 9.415 0.000 0.403 0.605
## sensory 0.119 0.033 3.656 0.000 1.000 1.000
## healthy 0.165 0.053 3.120 0.002 1.000 1.000
## tradition 0.076 0.027 2.824 0.005 1.000 1.000
## quality 0.186 0.052 3.603 0.000 1.000 1.000
## price 0.405 0.076 5.323 0.000 1.000 1.000
## convenience 0.137 0.032 4.281 0.000 1.000 1.000
Kết quả output
của cfa()
được chia thành 3 phần chính để giải thích: (1) tính xác thực và độ phù hợp của mô hình, (2) mối quan hệ giữa latent variable và manifest variable và (3)
manifest variables
đủ để đo lường các latent variables
. Về mặt toán học, mô hình được gọi là xác thực khi bậc tự do của mô hình lớn hơn không (\(df>0\)). Bậc tự do được tính toán dựa trên số lượng manifest variables
, không phải cỡ mẫu (sample size). Liên quan đến hệ số đánh giá sự phù hợp của mô hình CFI, TLI dao động trong khoảng \(0.8 \le CFI, TLI \le 0.9\) và hệ số đánh giá mức độ không phù hợp của mô hình RMSEA, SRMR dao động trong khoảng \(0.0 \le RMSEA, SRMR \le 0.1\) cho thấy mức độ phù hợp của mô hình đề xuất phù hợp khá tốt dữ liệu thực tế.latent variables
và manifest variables
(Estimates). Mối quan hệ từng đôi một giữa latent variable
và manifest variable
được ước lượng và thể hiện thông qua hệ số ước lượng Estimate
(còn gọi là Correlation coefficients). Về mặt toán học, có hai phương pháp để thiết lập điều kiện trong tính toán các hệ số ước lượng. Phương pháp 1 – thiết lập phương sai của latent variable
bằng \(1\), và phương pháp 2 – thiết lập phương sai của một biến manifest variable
bằng 1. Phương pháp thứ 2 được sử dụng phổ biến, và vì vậy được lựa chọn mặc định cho các phần mềm, ví dụ như R package lavaan
, SPSS.Trong quá trình phân tích dữ liệu, thao tác truy xuất các chỉ số thống kê phản ảnh sự phù hợp của mô hình được thực hiện thường xuyên. Để giảm thiểu tối đa thời gian tìm kiếm các chỉ số này giữa muôn vàng kết quả output và cũng để cô đọng kết quả trong quá trình phân tích, hàm fitMeasures()
được khuyến nghị sử dụng. Hàm fitMeasures()
cho phép truy suất trực tiếp các chỉ số thống kê được quan tâm trong mô hình. Đoạn code bên dưới minh họa cách sử dụng hàm fitMeasure()
để truy xuất 4 chỉ số thống kê cfi
, tli
, rmsea
và srmr
.
fitMeasures(model1_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.829 0.801 0.060 0.066
Như chúng ta nhận định thông qua hệ số CFI, TLI, RMSEA, SRMR trong bước 3, mô hình lý thuyết được đề xuất phù hợp khá tốt với dữ liệu thu thập. Làm sao cải tiến mức độ phù hợp của mô hình ?
Bước 1: xem xét hệ số tải (loadings) và phương sai (variances).
Xem xét hệ số tải (loadings) và phương sai (variances) của từng biến nhằm phát hiện những biến manifest variables
không tương quan tốt với latent variables
. Hệ số loadings giữa manifest variable
và latent variables
được tìm thấy trong output từ hàm cfa()
, mục Latent Variables
, cột Std.all
. Một manifest variable
được xem là tương quan tốt với latent variable
khi hệ số loading của manifest variable
lên latent variable
phải \(>0.3\). Hệ số loading \(<0.3\) có nghĩa là gì ? Nghĩa là câu hỏi mà manifest variable
đặt ra không phản ảnh được nội hàm của latent variable
; và vì vậy, chúng ta nên suy xét loại bỏ manifest variable
không liên quan này nếu cần thiết.
Bước 2: bổ sung các mối quan hệ phụ thuộc mới vào mô hình dựa trên chỉ số cải tiến.
Chỉ số cải tiến có thuật ngữ tiếng anh là modification indices, viết tắt là mi
. Về mặt ý nghĩa, mô hình sẽ càng ngày càng chính xác nếu có càng nhiều mối quan hệ giữa các biến được tích hợp vào mô hình. Tuy vậy, khi mô hình có càng nhiều mối quan hệ, mô hình cũng trở nên phức tạp hơn, khó giải thích hơn và cũng khó ứng dụng vào thực tiễn hơn. Ocam’s razor.
Hàm modificationindices()
cùng với argument sort=TRUE
được sử dụng để truy xuất các chỉ số cải tiến trong môi trường R. Kết quả phân tích bên dưới được chia thành 2 phần để giải thích.
lhs
(left hand side), op
(operator), rhs
(right hand side) muốn đề cập đến vị trí các thành tố và mối quan hệ nên được bổ sung vào mô hình. Cột mi
(modification index) thực chất là giá trị chi-square, mức độ phù hợp tăng lên của mô hình khi mối quan hệ mới được tích hợp vào mô hình hiện tại.Kết quả phân tích trong bước 2 cho chúng ta một gợi ý: cần cân nhắc sự tương quan giữa 2 biến Se3
và Se5
. Nếu mối quan hệ này được tính đến trong mô hình (tăng 1 bậc tự do), mức độ giải thích của mô hình sẽ tăng lên 69 (\(\chi^{2}=69\)).
## exploring modification indices
modificationindices(model1_cfa_fit, sort=TRUE)
correlation between Se3 and Se5
#********************************************************
# Model 2 ------------------------------------
#********************************************************
# Step 1: specifying the model
model2_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4 + Se5
healthy =~ He1 + He2 + He3
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
'
# Step 2: fitting the model
model2_cfa_fit <- cfa(model = model2_cfa,
data = fishsauce)
# Step 3: assessing GOF
summary(model2_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 89 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 64
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 431.500
## Degrees of freedom 236
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1778.017
## Degrees of freedom 276
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.870
## Tucker-Lewis Index (TLI) 0.848
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -8280.425
## Loglikelihood unrestricted model (H1) -8064.675
##
## Akaike (AIC) 16688.850
## Bayesian (BIC) 16925.892
## Sample-size adjusted Bayesian (BIC) 16722.922
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.053
## 90 Percent confidence interval - lower 0.045
## 90 Percent confidence interval - upper 0.060
## P-value RMSEA <= 0.05 0.289
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.059
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.477 0.587
## Se2 0.851 0.139 6.141 0.000 0.406 0.489
## Se3 1.012 0.153 6.622 0.000 0.483 0.557
## Se4 1.051 0.151 6.964 0.000 0.501 0.597
## Se5 1.015 0.147 6.904 0.000 0.484 0.592
## healthy =~
## He1 1.000 0.404 0.484
## He2 0.826 0.215 3.852 0.000 0.334 0.370
## He3 1.173 0.264 4.448 0.000 0.474 0.506
## tradition =~
## Tra1 1.000 0.275 0.375
## Tra2 1.900 0.379 5.018 0.000 0.523 0.625
## Tra3 1.585 0.332 4.776 0.000 0.436 0.530
## Tra4 1.418 0.307 4.615 0.000 0.390 0.485
## Tra5 1.723 0.353 4.884 0.000 0.474 0.566
## quality =~
## Qu1 1.000 0.438 0.478
## Qu2 1.327 0.207 6.416 0.000 0.582 0.684
## Qu3 1.243 0.199 6.257 0.000 0.545 0.628
## Qu4 1.003 0.191 5.255 0.000 0.440 0.447
## price =~
## Pr1 1.000 0.636 0.708
## Pr2 0.910 0.129 7.057 0.000 0.579 0.622
## Pr3 0.647 0.101 6.382 0.000 0.412 0.507
## convenience =~
## Co1 1.000 0.371 0.535
## Co2 1.073 0.166 6.472 0.000 0.398 0.539
## Co3 1.629 0.219 7.424 0.000 0.605 0.738
## Co4 1.382 0.196 7.056 0.000 0.513 0.629
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.333 0.043 7.685 0.000 0.333 0.702
## sensory ~~
## healthy -0.011 0.020 -0.544 0.587 -0.058 -0.058
## tradition -0.009 0.012 -0.788 0.431 -0.069 -0.069
## quality 0.152 0.030 5.013 0.000 0.728 0.728
## price 0.008 0.026 0.320 0.749 0.028 0.028
## convenience -0.029 0.015 -1.864 0.062 -0.161 -0.161
## healthy ~~
## tradition 0.070 0.019 3.627 0.000 0.626 0.626
## quality -0.004 0.019 -0.202 0.840 -0.021 -0.021
## price 0.130 0.034 3.852 0.000 0.505 0.505
## convenience 0.056 0.018 3.113 0.002 0.375 0.375
## tradition ~~
## quality -0.004 0.010 -0.377 0.706 -0.033 -0.033
## price 0.076 0.021 3.653 0.000 0.436 0.436
## convenience 0.049 0.013 3.730 0.000 0.480 0.480
## quality ~~
## price 0.041 0.025 1.638 0.101 0.146 0.146
## convenience -0.007 0.013 -0.491 0.624 -0.041 -0.041
## price ~~
## convenience 0.115 0.025 4.605 0.000 0.485 0.485
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.432 0.045 9.670 0.000 0.432 0.655
## .Se2 0.524 0.049 10.725 0.000 0.524 0.761
## .Se3 0.517 0.052 9.924 0.000 0.517 0.689
## .Se4 0.454 0.048 9.536 0.000 0.454 0.644
## .Se5 0.434 0.045 9.557 0.000 0.434 0.650
## .He1 0.535 0.058 9.251 0.000 0.535 0.766
## .He2 0.702 0.065 10.742 0.000 0.702 0.863
## .He3 0.652 0.074 8.829 0.000 0.652 0.744
## .Tra1 0.463 0.041 11.413 0.000 0.463 0.860
## .Tra2 0.427 0.048 8.923 0.000 0.427 0.610
## .Tra3 0.487 0.048 10.228 0.000 0.487 0.719
## .Tra4 0.495 0.046 10.664 0.000 0.495 0.765
## .Tra5 0.476 0.049 9.799 0.000 0.476 0.679
## .Qu1 0.648 0.060 10.851 0.000 0.648 0.771
## .Qu2 0.384 0.048 7.993 0.000 0.384 0.532
## .Qu3 0.455 0.050 9.093 0.000 0.455 0.606
## .Qu4 0.772 0.070 11.072 0.000 0.772 0.800
## .Pr1 0.403 0.060 6.713 0.000 0.403 0.499
## .Pr2 0.530 0.061 8.650 0.000 0.530 0.613
## .Pr3 0.490 0.047 10.371 0.000 0.490 0.743
## .Co1 0.343 0.033 10.556 0.000 0.343 0.713
## .Co2 0.387 0.037 10.520 0.000 0.387 0.709
## .Co3 0.306 0.043 7.172 0.000 0.306 0.455
## .Co4 0.402 0.043 9.413 0.000 0.402 0.604
## sensory 0.227 0.049 4.636 0.000 1.000 1.000
## healthy 0.163 0.053 3.099 0.002 1.000 1.000
## tradition 0.076 0.027 2.817 0.005 1.000 1.000
## quality 0.192 0.052 3.714 0.000 1.000 1.000
## price 0.405 0.076 5.318 0.000 1.000 1.000
## convenience 0.138 0.032 4.298 0.000 1.000 1.000
fitMeasures(model2_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.870 0.848 0.053 0.059
# cfi tli rmsea srmr
# 0.870 0.848 0.053 0.059
modificationindices(model2_cfa_fit, sort=TRUE)
anova(model2_cfa_fit, model1_cfa_fit)
## Results: Model 2 is better than Model 1
#********************************************************
# Model 3 ------------------------------------
#********************************************************
# Update: set up the relationship between sensory and quality
model3_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4 + Se5
healthy =~ He1 + He2 + He3
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
sensory~quality
healthy~~tradition
'
# Step 2: fitting the model
model3_cfa_fit <- cfa(model = model3_cfa,
data = fishsauce)
# Step 3: assessing GOF
summary(model3_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 84 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 60
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 434.728
## Degrees of freedom 240
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1778.017
## Degrees of freedom 276
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.870
## Tucker-Lewis Index (TLI) 0.851
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -8282.039
## Loglikelihood unrestricted model (H1) -8064.675
##
## Akaike (AIC) 16684.078
## Bayesian (BIC) 16906.305
## Sample-size adjusted Bayesian (BIC) 16716.020
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.052
## 90 Percent confidence interval - lower 0.044
## 90 Percent confidence interval - upper 0.060
## P-value RMSEA <= 0.05 0.328
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.059
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.477 0.587
## Se2 0.844 0.139 6.086 0.000 0.402 0.485
## Se3 1.024 0.154 6.640 0.000 0.488 0.564
## Se4 1.047 0.151 6.924 0.000 0.499 0.595
## Se5 1.023 0.148 6.901 0.000 0.488 0.596
## healthy =~
## He1 1.000 0.404 0.484
## He2 0.826 0.214 3.853 0.000 0.334 0.370
## He3 1.172 0.263 4.447 0.000 0.474 0.506
## tradition =~
## Tra1 1.000 0.275 0.375
## Tra2 1.899 0.378 5.017 0.000 0.522 0.624
## Tra3 1.585 0.332 4.776 0.000 0.436 0.530
## Tra4 1.418 0.307 4.615 0.000 0.390 0.485
## Tra5 1.723 0.353 4.884 0.000 0.474 0.566
## quality =~
## Qu1 1.000 0.436 0.475
## Qu2 1.342 0.210 6.392 0.000 0.585 0.688
## Qu3 1.240 0.200 6.211 0.000 0.540 0.623
## Qu4 1.017 0.193 5.265 0.000 0.443 0.451
## price =~
## Pr1 1.000 0.637 0.709
## Pr2 0.908 0.129 7.053 0.000 0.579 0.622
## Pr3 0.646 0.101 6.378 0.000 0.412 0.507
## convenience =~
## Co1 1.000 0.370 0.534
## Co2 1.079 0.167 6.467 0.000 0.400 0.541
## Co3 1.638 0.221 7.395 0.000 0.606 0.740
## Co4 1.383 0.197 7.024 0.000 0.512 0.628
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory ~
## quality 0.797 0.148 5.367 0.000 0.728 0.728
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.328 0.043 7.566 0.000 0.328 0.699
## healthy ~~
## tradition 0.070 0.019 3.627 0.000 0.626 0.626
## quality -0.006 0.018 -0.330 0.742 -0.034 -0.034
## price 0.130 0.034 3.852 0.000 0.504 0.504
## convenience 0.056 0.018 3.111 0.002 0.374 0.374
## tradition ~~
## quality -0.005 0.010 -0.535 0.593 -0.045 -0.045
## price 0.076 0.021 3.653 0.000 0.435 0.435
## convenience 0.049 0.013 3.726 0.000 0.480 0.480
## quality ~~
## price 0.034 0.024 1.449 0.147 0.123 0.123
## convenience -0.013 0.013 -0.974 0.330 -0.079 -0.079
## price ~~
## convenience 0.114 0.025 4.598 0.000 0.485 0.485
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.432 0.045 9.642 0.000 0.432 0.655
## .Se2 0.527 0.049 10.743 0.000 0.527 0.765
## .Se3 0.511 0.052 9.811 0.000 0.511 0.682
## .Se4 0.455 0.048 9.535 0.000 0.455 0.646
## .Se5 0.431 0.046 9.455 0.000 0.431 0.644
## .He1 0.535 0.058 9.247 0.000 0.535 0.766
## .He2 0.702 0.065 10.740 0.000 0.702 0.863
## .He3 0.652 0.074 8.832 0.000 0.652 0.744
## .Tra1 0.463 0.041 11.413 0.000 0.463 0.860
## .Tra2 0.428 0.048 8.929 0.000 0.428 0.610
## .Tra3 0.486 0.048 10.225 0.000 0.486 0.719
## .Tra4 0.495 0.046 10.663 0.000 0.495 0.765
## .Tra5 0.476 0.049 9.796 0.000 0.476 0.679
## .Qu1 0.650 0.060 10.868 0.000 0.650 0.774
## .Qu2 0.380 0.048 7.908 0.000 0.380 0.527
## .Qu3 0.460 0.050 9.169 0.000 0.460 0.612
## .Qu4 0.769 0.070 11.045 0.000 0.769 0.797
## .Pr1 0.402 0.060 6.686 0.000 0.402 0.498
## .Pr2 0.531 0.061 8.655 0.000 0.531 0.613
## .Pr3 0.490 0.047 10.375 0.000 0.490 0.743
## .Co1 0.344 0.033 10.564 0.000 0.344 0.715
## .Co2 0.386 0.037 10.497 0.000 0.386 0.707
## .Co3 0.304 0.043 7.110 0.000 0.304 0.453
## .Co4 0.403 0.043 9.422 0.000 0.403 0.606
## .sensory 0.107 0.030 3.529 0.000 0.469 0.469
## healthy 0.164 0.053 3.100 0.002 1.000 1.000
## tradition 0.076 0.027 2.816 0.005 1.000 1.000
## quality 0.190 0.051 3.691 0.000 1.000 1.000
## price 0.406 0.076 5.322 0.000 1.000 1.000
## convenience 0.137 0.032 4.280 0.000 1.000 1.000
fitMeasures(model3_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.870 0.851 0.052 0.059
modificationindices(model3_cfa_fit, sort=TRUE)
#********************************************************
# Model 4 ------------------------------------
#********************************************************
# Update: set up the relationship between sensory and quality
model4_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4 + Se5
healthy =~ He1 + He2 + He3
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
healthy~tradition
'
# Step 2: fitting the model
model4_cfa_fit <- cfa(model = model4_cfa,
data = fishsauce)
# Step 3: assessing GOF
summary(model4_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 79 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 60
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 436.823
## Degrees of freedom 240
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1778.017
## Degrees of freedom 276
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.869
## Tucker-Lewis Index (TLI) 0.849
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -8283.086
## Loglikelihood unrestricted model (H1) -8064.675
##
## Akaike (AIC) 16686.173
## Bayesian (BIC) 16908.400
## Sample-size adjusted Bayesian (BIC) 16718.115
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.052
## 90 Percent confidence interval - lower 0.044
## 90 Percent confidence interval - upper 0.060
## P-value RMSEA <= 0.05 0.307
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.060
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.477 0.587
## Se2 0.851 0.139 6.141 0.000 0.406 0.489
## Se3 1.012 0.153 6.621 0.000 0.482 0.557
## Se4 1.051 0.151 6.964 0.000 0.501 0.597
## Se5 1.015 0.147 6.906 0.000 0.484 0.592
## healthy =~
## He1 1.000 0.442 0.529
## He2 0.779 0.201 3.883 0.000 0.345 0.382
## He3 0.999 0.234 4.275 0.000 0.442 0.472
## tradition =~
## Tra1 1.000 0.271 0.369
## Tra2 1.919 0.385 4.979 0.000 0.520 0.621
## Tra3 1.580 0.335 4.714 0.000 0.428 0.520
## Tra4 1.425 0.312 4.569 0.000 0.386 0.480
## Tra5 1.751 0.361 4.853 0.000 0.474 0.566
## quality =~
## Qu1 1.000 0.438 0.478
## Qu2 1.326 0.207 6.412 0.000 0.581 0.684
## Qu3 1.245 0.199 6.258 0.000 0.545 0.629
## Qu4 1.004 0.191 5.255 0.000 0.440 0.448
## price =~
## Pr1 1.000 0.644 0.716
## Pr2 0.904 0.130 6.960 0.000 0.583 0.626
## Pr3 0.625 0.100 6.238 0.000 0.402 0.495
## convenience =~
## Co1 1.000 0.371 0.535
## Co2 1.074 0.166 6.473 0.000 0.399 0.540
## Co3 1.629 0.220 7.419 0.000 0.605 0.738
## Co4 1.382 0.196 7.051 0.000 0.513 0.629
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## healthy ~
## tradition 1.059 0.269 3.944 0.000 0.648 0.648
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.333 0.043 7.684 0.000 0.333 0.702
## sensory ~~
## tradition -0.009 0.011 -0.843 0.399 -0.073 -0.073
## quality 0.152 0.030 5.013 0.000 0.729 0.729
## price 0.008 0.027 0.313 0.754 0.027 0.027
## convenience -0.028 0.015 -1.863 0.062 -0.161 -0.161
## tradition ~~
## quality -0.004 0.010 -0.412 0.680 -0.035 -0.035
## price 0.082 0.021 3.803 0.000 0.469 0.469
## convenience 0.049 0.013 3.765 0.000 0.492 0.492
## quality ~~
## price 0.040 0.025 1.618 0.106 0.143 0.143
## convenience -0.007 0.013 -0.488 0.626 -0.040 -0.040
## price ~~
## convenience 0.115 0.025 4.592 0.000 0.481 0.481
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.432 0.045 9.671 0.000 0.432 0.655
## .Se2 0.524 0.049 10.726 0.000 0.524 0.761
## .Se3 0.517 0.052 9.925 0.000 0.517 0.690
## .Se4 0.454 0.048 9.537 0.000 0.454 0.644
## .Se5 0.434 0.045 9.555 0.000 0.434 0.650
## .He1 0.503 0.061 8.197 0.000 0.503 0.720
## .He2 0.695 0.066 10.532 0.000 0.695 0.854
## .He3 0.681 0.073 9.300 0.000 0.681 0.777
## .Tra1 0.466 0.041 11.467 0.000 0.466 0.864
## .Tra2 0.430 0.047 9.093 0.000 0.430 0.614
## .Tra3 0.494 0.047 10.391 0.000 0.494 0.729
## .Tra4 0.498 0.046 10.755 0.000 0.498 0.770
## .Tra5 0.476 0.048 9.875 0.000 0.476 0.679
## .Qu1 0.648 0.060 10.851 0.000 0.648 0.772
## .Qu2 0.385 0.048 8.008 0.000 0.385 0.533
## .Qu3 0.455 0.050 9.080 0.000 0.455 0.605
## .Qu4 0.772 0.070 11.070 0.000 0.772 0.800
## .Pr1 0.394 0.062 6.381 0.000 0.394 0.487
## .Pr2 0.526 0.062 8.491 0.000 0.526 0.608
## .Pr3 0.498 0.048 10.473 0.000 0.498 0.755
## .Co1 0.343 0.033 10.556 0.000 0.343 0.714
## .Co2 0.387 0.037 10.513 0.000 0.387 0.709
## .Co3 0.306 0.043 7.170 0.000 0.306 0.455
## .Co4 0.402 0.043 9.411 0.000 0.402 0.604
## sensory 0.227 0.049 4.636 0.000 1.000 1.000
## .healthy 0.113 0.045 2.531 0.011 0.580 0.580
## tradition 0.073 0.026 2.783 0.005 1.000 1.000
## quality 0.192 0.052 3.713 0.000 1.000 1.000
## price 0.415 0.078 5.315 0.000 1.000 1.000
## convenience 0.138 0.032 4.296 0.000 1.000 1.000
fitMeasures(model4_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.869 0.849 0.052 0.060
modificationindices(model4_cfa_fit, sort=TRUE)
semPaths(model4_cfa_fit,
whatLabels = "std",
edge.label.cex = 1,
layout = "tree",
rotation = 2)
#********************************************************
# Model 5 ------------------------------------
#********************************************************
# Update: set up the relationship between sensory and quality
# drop out latent variable health
model5_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se4 + Se5
tradition =~ Tra1 + Tra2 + Tra3 + Tra4 + Tra5
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
sensory ~~ tradition
'
# Step 2: fitting the model
model5_cfa_fit <- cfa(model = model5_cfa,
data = fishsauce)
# Step 3: assessing GOF
summary(model5_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 69 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 53
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 306.373
## Degrees of freedom 178
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 1568.381
## Degrees of freedom 210
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.905
## Tucker-Lewis Index (TLI) 0.889
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -7150.059
## Loglikelihood unrestricted model (H1) -6996.872
##
## Akaike (AIC) 14406.117
## Bayesian (BIC) 14602.418
## Sample-size adjusted Bayesian (BIC) 14434.333
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.049
## 90 Percent confidence interval - lower 0.040
## 90 Percent confidence interval - upper 0.058
## P-value RMSEA <= 0.05 0.557
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.056
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.477 0.587
## Se2 0.851 0.139 6.142 0.000 0.406 0.489
## Se3 1.012 0.153 6.622 0.000 0.483 0.557
## Se4 1.050 0.151 6.963 0.000 0.501 0.597
## Se5 1.016 0.147 6.907 0.000 0.484 0.592
## tradition =~
## Tra1 1.000 0.309 0.421
## Tra2 1.600 0.302 5.295 0.000 0.494 0.590
## Tra3 1.458 0.283 5.156 0.000 0.450 0.547
## Tra4 1.269 0.259 4.905 0.000 0.392 0.487
## Tra5 1.510 0.291 5.190 0.000 0.466 0.557
## quality =~
## Qu1 1.000 0.438 0.478
## Qu2 1.325 0.207 6.415 0.000 0.581 0.684
## Qu3 1.243 0.199 6.259 0.000 0.545 0.628
## Qu4 1.003 0.191 5.257 0.000 0.440 0.448
## price =~
## Pr1 1.000 0.649 0.721
## Pr2 0.898 0.131 6.875 0.000 0.583 0.626
## Pr3 0.615 0.100 6.161 0.000 0.399 0.491
## convenience =~
## Co1 1.000 0.368 0.531
## Co2 1.083 0.168 6.439 0.000 0.399 0.540
## Co3 1.643 0.223 7.364 0.000 0.605 0.738
## Co4 1.401 0.199 7.024 0.000 0.516 0.633
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.333 0.043 7.681 0.000 0.333 0.702
## sensory ~~
## tradition -0.010 0.013 -0.757 0.449 -0.067 -0.067
## quality 0.152 0.030 5.014 0.000 0.729 0.729
## price 0.008 0.027 0.311 0.755 0.027 0.027
## convenience -0.028 0.015 -1.864 0.062 -0.161 -0.161
## tradition ~~
## quality -0.004 0.012 -0.305 0.761 -0.026 -0.026
## price 0.087 0.023 3.827 0.000 0.437 0.437
## convenience 0.055 0.014 3.889 0.000 0.480 0.480
## quality ~~
## price 0.040 0.025 1.609 0.108 0.142 0.142
## convenience -0.007 0.013 -0.491 0.623 -0.041 -0.041
## price ~~
## convenience 0.114 0.025 4.568 0.000 0.478 0.478
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.432 0.045 9.672 0.000 0.432 0.655
## .Se2 0.524 0.049 10.725 0.000 0.524 0.761
## .Se3 0.517 0.052 9.922 0.000 0.517 0.689
## .Se4 0.454 0.048 9.540 0.000 0.454 0.644
## .Se5 0.434 0.045 9.551 0.000 0.434 0.649
## .Tra1 0.444 0.040 11.051 0.000 0.444 0.823
## .Tra2 0.457 0.049 9.232 0.000 0.457 0.652
## .Tra3 0.474 0.048 9.842 0.000 0.474 0.701
## .Tra4 0.493 0.047 10.507 0.000 0.493 0.763
## .Tra5 0.484 0.050 9.717 0.000 0.484 0.690
## .Qu1 0.648 0.060 10.846 0.000 0.648 0.771
## .Qu2 0.385 0.048 8.005 0.000 0.385 0.533
## .Qu3 0.455 0.050 9.083 0.000 0.455 0.605
## .Qu4 0.772 0.070 11.069 0.000 0.772 0.800
## .Pr1 0.388 0.063 6.177 0.000 0.388 0.480
## .Pr2 0.526 0.062 8.425 0.000 0.526 0.608
## .Pr3 0.501 0.048 10.502 0.000 0.501 0.759
## .Co1 0.345 0.033 10.590 0.000 0.345 0.718
## .Co2 0.387 0.037 10.507 0.000 0.387 0.708
## .Co3 0.306 0.043 7.152 0.000 0.306 0.455
## .Co4 0.399 0.043 9.346 0.000 0.399 0.600
## sensory 0.227 0.049 4.636 0.000 1.000 1.000
## tradition 0.095 0.030 3.136 0.002 1.000 1.000
## quality 0.192 0.052 3.716 0.000 1.000 1.000
## price 0.421 0.079 5.301 0.000 1.000 1.000
## convenience 0.136 0.032 4.256 0.000 1.000 1.000
fitMeasures(model5_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.905 0.889 0.049 0.056
modificationindices(model5_cfa_fit, sort=TRUE)
semPaths(model5_cfa_fit,
whatLabels = "std",
edge.label.cex = 1,
layout = "tree",
rotation = 2)
#********************************************************
# Model 6 ------------------------------------
#********************************************************
# Update: set up the relationship between sensory and quality
# drop out latent variable health
model6_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se5
tradition =~ Tra1 + Tra3 + Tra4
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
sensory ~~ tradition
'
# Step 2: fitting the model
model6_cfa_fit <- cfa(model = model6_cfa,
data = fishsauce)
# Step 3: assessing GOF
summary(model6_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 65 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 47
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 169.488
## Degrees of freedom 124
## P-value (Chi-square) 0.004
##
## Model Test Baseline Model:
##
## Test statistic 1245.053
## Degrees of freedom 153
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.958
## Tucker-Lewis Index (TLI) 0.949
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -6125.426
## Loglikelihood unrestricted model (H1) -6040.682
##
## Akaike (AIC) 12344.852
## Bayesian (BIC) 12518.930
## Sample-size adjusted Bayesian (BIC) 12369.873
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.035
## 90 Percent confidence interval - lower 0.020
## 90 Percent confidence interval - upper 0.047
## P-value RMSEA <= 0.05 0.978
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.048
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.537 0.662
## Se2 0.861 0.135 6.367 0.000 0.463 0.558
## Se3 0.845 0.141 6.010 0.000 0.454 0.524
## Se5 0.877 0.137 6.421 0.000 0.471 0.576
## tradition =~
## Tra1 1.000 0.376 0.512
## Tra3 1.342 0.274 4.892 0.000 0.504 0.613
## Tra4 1.118 0.229 4.882 0.000 0.420 0.522
## quality =~
## Qu1 1.000 0.430 0.469
## Qu2 1.397 0.228 6.134 0.000 0.600 0.706
## Qu3 1.256 0.209 6.002 0.000 0.540 0.622
## Qu4 0.998 0.198 5.036 0.000 0.429 0.436
## price =~
## Pr1 1.000 0.661 0.735
## Pr2 0.852 0.126 6.760 0.000 0.563 0.605
## Pr3 0.616 0.099 6.211 0.000 0.407 0.501
## convenience =~
## Co1 1.000 0.363 0.523
## Co2 1.092 0.173 6.313 0.000 0.396 0.536
## Co3 1.670 0.232 7.195 0.000 0.606 0.739
## Co4 1.445 0.208 6.941 0.000 0.524 0.642
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.353 0.047 7.523 0.000 0.353 0.715
## sensory ~~
## tradition 0.017 0.020 0.895 0.371 0.087 0.087
## quality 0.137 0.030 4.603 0.000 0.592 0.592
## price 0.027 0.031 0.863 0.388 0.076 0.076
## convenience -0.032 0.017 -1.855 0.064 -0.163 -0.163
## tradition ~~
## quality 0.008 0.015 0.562 0.574 0.052 0.052
## price 0.098 0.028 3.560 0.000 0.396 0.396
## convenience 0.045 0.015 3.080 0.002 0.331 0.331
## quality ~~
## price 0.041 0.025 1.644 0.100 0.144 0.144
## convenience -0.007 0.013 -0.548 0.584 -0.045 -0.045
## price ~~
## convenience 0.113 0.025 4.528 0.000 0.471 0.471
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.371 0.050 7.460 0.000 0.371 0.562
## .Se2 0.475 0.050 9.480 0.000 0.475 0.689
## .Se3 0.544 0.056 9.758 0.000 0.544 0.726
## .Se5 0.447 0.049 9.138 0.000 0.447 0.668
## .Tra1 0.398 0.044 9.137 0.000 0.398 0.738
## .Tra3 0.423 0.060 7.020 0.000 0.423 0.625
## .Tra4 0.470 0.053 8.942 0.000 0.470 0.727
## .Qu1 0.655 0.061 10.791 0.000 0.655 0.780
## .Qu2 0.362 0.052 6.992 0.000 0.362 0.501
## .Qu3 0.461 0.052 8.813 0.000 0.461 0.613
## .Qu4 0.782 0.071 11.038 0.000 0.782 0.809
## .Pr1 0.372 0.064 5.779 0.000 0.372 0.460
## .Pr2 0.549 0.062 8.811 0.000 0.549 0.634
## .Pr3 0.494 0.048 10.386 0.000 0.494 0.749
## .Co1 0.350 0.033 10.617 0.000 0.350 0.727
## .Co2 0.389 0.037 10.495 0.000 0.389 0.713
## .Co3 0.305 0.044 6.975 0.000 0.305 0.454
## .Co4 0.391 0.043 9.084 0.000 0.391 0.588
## sensory 0.289 0.059 4.852 0.000 1.000 1.000
## tradition 0.141 0.041 3.400 0.001 1.000 1.000
## quality 0.185 0.052 3.576 0.000 1.000 1.000
## price 0.437 0.082 5.355 0.000 1.000 1.000
## convenience 0.131 0.032 4.162 0.000 1.000 1.000
fitMeasures(model6_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.958 0.949 0.035 0.048
modificationindices(model6_cfa_fit, sort=TRUE)
semPaths(model6_cfa_fit,
whatLabels = "std",
edge.label.cex = 1,
layout = "tree",
rotation = 2)
#********************************************************
# Model 7 ------------------------------------
#********************************************************
# Update: set up the relationship between sensory and quality
# drop out latent variable health
model7_cfa <- '
sensory =~ Se1 + Se2 + Se3 + Se5
tradition =~ Tra1 + Tra3 + Tra4
quality =~ Qu1 + Qu2 + Qu3 + Qu4
price =~ Pr1 + Pr2 + Pr3
convenience =~ Co1 + Co2 + Co3 + Co4
Se3 ~~ Se5
sensory ~~ tradition
choice =~ sensory + quality
'
## SEM
model7_cfa_fit <- cfa(model = model7_cfa,
data = fishsauce)
summary(model7_cfa_fit,
standardized = TRUE,
fit.measures = TRUE)
## lavaan 0.6-6 ended normally after 66 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 46
##
## Number of observations 300
##
## Model Test User Model:
##
## Test statistic 170.938
## Degrees of freedom 125
## P-value (Chi-square) 0.004
##
## Model Test Baseline Model:
##
## Test statistic 1245.053
## Degrees of freedom 153
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.958
## Tucker-Lewis Index (TLI) 0.949
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -6126.151
## Loglikelihood unrestricted model (H1) -6040.682
##
## Akaike (AIC) 12344.302
## Bayesian (BIC) 12514.676
## Sample-size adjusted Bayesian (BIC) 12368.791
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.035
## 90 Percent confidence interval - lower 0.020
## 90 Percent confidence interval - upper 0.047
## P-value RMSEA <= 0.05 0.978
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.049
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## sensory =~
## Se1 1.000 0.537 0.662
## Se2 0.858 0.135 6.345 0.000 0.461 0.556
## Se3 0.847 0.141 6.007 0.000 0.455 0.525
## Se5 0.878 0.137 6.411 0.000 0.472 0.577
## tradition =~
## Tra1 1.000 0.376 0.512
## Tra3 1.343 0.274 4.905 0.000 0.505 0.613
## Tra4 1.119 0.229 4.893 0.000 0.420 0.523
## quality =~
## Qu1 1.000 0.429 0.469
## Qu2 1.398 0.228 6.120 0.000 0.601 0.707
## Qu3 1.252 0.209 5.985 0.000 0.538 0.620
## Qu4 1.007 0.199 5.056 0.000 0.433 0.440
## price =~
## Pr1 1.000 0.665 0.739
## Pr2 0.845 0.125 6.737 0.000 0.562 0.604
## Pr3 0.610 0.099 6.187 0.000 0.406 0.499
## convenience =~
## Co1 1.000 0.362 0.521
## Co2 1.093 0.174 6.295 0.000 0.395 0.535
## Co3 1.680 0.234 7.182 0.000 0.607 0.741
## Co4 1.448 0.209 6.929 0.000 0.524 0.642
## choice =~
## sensory 1.000 0.893 0.893
## quality 0.593 0.326 1.821 0.069 0.663 0.663
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se3 ~~
## .Se5 0.352 0.047 7.490 0.000 0.352 0.715
## .sensory ~~
## tradition 0.012 0.024 0.484 0.628 0.130 0.130
## tradition ~~
## price 0.099 0.028 3.576 0.000 0.397 0.397
## convenience 0.045 0.015 3.093 0.002 0.333 0.333
## choice 0.008 0.025 0.326 0.745 0.045 0.045
## price ~~
## convenience 0.113 0.025 4.519 0.000 0.468 0.468
## choice 0.040 0.030 1.318 0.188 0.124 0.124
## convenience ~~
## choice -0.026 0.016 -1.599 0.110 -0.149 -0.149
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Se1 0.370 0.050 7.436 0.000 0.370 0.562
## .Se2 0.476 0.050 9.500 0.000 0.476 0.691
## .Se3 0.543 0.056 9.726 0.000 0.543 0.724
## .Se5 0.446 0.049 9.107 0.000 0.446 0.667
## .Tra1 0.398 0.044 9.146 0.000 0.398 0.738
## .Tra3 0.423 0.060 7.022 0.000 0.423 0.624
## .Tra4 0.470 0.053 8.946 0.000 0.470 0.727
## .Qu1 0.656 0.061 10.786 0.000 0.656 0.780
## .Qu2 0.361 0.052 6.961 0.000 0.361 0.501
## .Qu3 0.463 0.052 8.842 0.000 0.463 0.616
## .Qu4 0.778 0.071 11.005 0.000 0.778 0.806
## .Pr1 0.367 0.065 5.656 0.000 0.367 0.454
## .Pr2 0.550 0.062 8.834 0.000 0.550 0.636
## .Pr3 0.495 0.048 10.409 0.000 0.495 0.751
## .Co1 0.350 0.033 10.632 0.000 0.350 0.728
## .Co2 0.390 0.037 10.509 0.000 0.390 0.714
## .Co3 0.303 0.044 6.914 0.000 0.303 0.451
## .Co4 0.391 0.043 9.086 0.000 0.391 0.588
## .sensory 0.058 0.123 0.473 0.636 0.202 0.202
## tradition 0.141 0.041 3.406 0.001 1.000 1.000
## .quality 0.103 0.052 1.978 0.048 0.561 0.561
## price 0.442 0.082 5.368 0.000 1.000 1.000
## convenience 0.131 0.031 4.150 0.000 1.000 1.000
## choice 0.230 0.130 1.774 0.076 1.000 1.000
fitMeasures(model6_cfa_fit,
c("cfi","tli","rmsea","srmr"))
## cfi tli rmsea srmr
## 0.958 0.949 0.035 0.048
modificationindices(model7_cfa_fit, sort=TRUE)
semPaths(model7_cfa_fit,
whatLabels = "std",
edge.label.cex = 1,
layout = "tree",
rotation = 1)
Bước 1 Nhập dữ liệu
### Import data
library(readxl)
pur_int <- read_excel("2019-QMFS-CFA fish sauce/Hedonic-Purchase Intension-Fish sauce/Data.Exp3.xlsx", sheet = "RUN")
pur_int$panelist <- as.factor(pur_int$panelist)
pur_int$Fishsauce <- as.factor(pur_int$Fishsauce)
colnames(pur_int) <- c("subject", "product", "hedonic",
"purchase", "Se", "Tra",
"Qu", "Pr", "Co", "He")
str(pur_int)
## tibble [420 x 10] (S3: tbl_df/tbl/data.frame)
## $ subject : Factor w/ 60 levels "KS_1","KS_10",..: 1 1 1 1 1 1 1 2 2 2 ...
## $ product : Factor w/ 7 levels "3.Mien","Chinsu.Gold",..: 5 3 2 7 4 1 6 5 3 2 ...
## $ hedonic : num [1:420] 5 5 5 3 3 4 3 4 2 5 ...
## $ purchase: num [1:420] 5 4 3 2 2 4 2 4 2 4 ...
## $ Se : num [1:420] 5 4 5 2 2 4 3 5 3 4 ...
## $ Tra : num [1:420] 4 4 5 5 4 4 3 2 4 4 ...
## $ Qu : num [1:420] 4 4 5 5 4 4 3 3 4 5 ...
## $ Pr : num [1:420] 5 3 2 2 3 5 4 5 4 3 ...
## $ Co : num [1:420] 5 3 4 4 4 5 4 4 4 5 ...
## $ He : num [1:420] 5 3 4 4 4 5 4 3 4 4 ...
Bước 2 Plot correlation matrix
## correlation among variables
library(tidyverse)
cor_dat <- pur_int %>% select(hedonic:He)
res.cor <- round(cor(cor_dat),2)
print(res.cor)
## hedonic purchase Se Tra Qu Pr Co He
## hedonic 1.00 0.65 0.56 0.39 0.33 0.23 0.29 0.37
## purchase 0.65 1.00 0.55 0.38 0.35 0.34 0.29 0.35
## Se 0.56 0.55 1.00 0.50 0.48 0.29 0.29 0.45
## Tra 0.39 0.38 0.50 1.00 0.64 0.17 0.35 0.63
## Qu 0.33 0.35 0.48 0.64 1.00 0.18 0.28 0.69
## Pr 0.23 0.34 0.29 0.17 0.18 1.00 0.41 0.17
## Co 0.29 0.29 0.29 0.35 0.28 0.41 1.00 0.35
## He 0.37 0.35 0.45 0.63 0.69 0.17 0.35 1.00
library(corrplot)
## corrplot 0.84 loaded
corrplot(res.cor, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
Bước 3: Regression model and pos-hoc test
## linear model
colnames(pur_int)
## [1] "subject" "product" "hedonic" "purchase" "Se" "Tra"
## [7] "Qu" "Pr" "Co" "He"
## differences between products in terms of purchase
res.aov.pur <- aov(purchase ~ product, data=pur_int)
summary(res.aov.pur)
## Df Sum Sq Mean Sq F value Pr(>F)
## product 6 33.1 5.515 4.948 6.61e-05 ***
## Residuals 413 460.3 1.115
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(res.aov.pur)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = purchase ~ product, data = pur_int)
##
## $product
## diff lwr upr p adj
## Chinsu.Gold-3.Mien 0.45000000 -0.121094190 1.02109419 0.2300250
## Chinsu.Red-3.Mien 0.25000000 -0.321094190 0.82109419 0.8531570
## Hanh.Phuc-3.Mien -0.06666667 -0.637760856 0.50442752 0.9998629
## Nam.Ngu-3.Mien 0.56666667 -0.004427523 1.13776086 0.0533404
## Nha.Trang-3.Mien -0.30000000 -0.871094190 0.27109419 0.7101573
## Phu.Quoc-3.Mien 0.06666667 -0.504427523 0.63776086 0.9998629
## Chinsu.Red-Chinsu.Gold -0.20000000 -0.771094190 0.37109419 0.9450045
## Hanh.Phuc-Chinsu.Gold -0.51666667 -1.087760856 0.05442752 0.1057985
## Nam.Ngu-Chinsu.Gold 0.11666667 -0.454427523 0.68776086 0.9966369
## Nha.Trang-Chinsu.Gold -0.75000000 -1.321094190 -0.17890581 0.0022205
## Phu.Quoc-Chinsu.Gold -0.38333333 -0.954427523 0.18776086 0.4233483
## Hanh.Phuc-Chinsu.Red -0.31666667 -0.887760856 0.25442752 0.6544486
## Nam.Ngu-Chinsu.Red 0.31666667 -0.254427523 0.88776086 0.6544486
## Nha.Trang-Chinsu.Red -0.55000000 -1.121094190 0.02109419 0.0676496
## Phu.Quoc-Chinsu.Red -0.18333333 -0.754427523 0.38776086 0.9637842
## Nam.Ngu-Hanh.Phuc 0.63333333 0.062239144 1.20442752 0.0188538
## Nha.Trang-Hanh.Phuc -0.23333333 -0.804427523 0.33776086 0.8899161
## Phu.Quoc-Hanh.Phuc 0.13333333 -0.437760856 0.70442752 0.9930196
## Nha.Trang-Nam.Ngu -0.86666667 -1.437760856 -0.29557248 0.0001813
## Phu.Quoc-Nam.Ngu -0.50000000 -1.071094190 0.07109419 0.1304127
## Phu.Quoc-Nha.Trang 0.36666667 -0.204427523 0.93776086 0.4798973
plot(TukeyHSD(res.aov.pur))
res.aov.hedo <- aov(hedonic ~ product, data=pur_int)
summary(res.aov.hedo)
## Df Sum Sq Mean Sq F value Pr(>F)
## product 6 59.9 9.982 8.044 3.15e-08 ***
## Residuals 413 512.5 1.241
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(res.aov.hedo)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hedonic ~ product, data = pur_int)
##
## $product
## diff lwr upr p adj
## Chinsu.Gold-3.Mien 9.000000e-01 0.29738318 1.50261682 0.0002479
## Chinsu.Red-3.Mien 6.166667e-01 0.01404984 1.21928349 0.0410050
## Hanh.Phuc-3.Mien 1.666667e-01 -0.43595016 0.76928349 0.9829036
## Nam.Ngu-3.Mien 8.666667e-01 0.26404984 1.46928349 0.0005000
## Nha.Trang-3.Mien -6.666667e-02 -0.66928349 0.53595016 0.9998999
## Phu.Quoc-3.Mien 1.666667e-01 -0.43595016 0.76928349 0.9829036
## Chinsu.Red-Chinsu.Gold -2.833333e-01 -0.88595016 0.31928349 0.8054367
## Hanh.Phuc-Chinsu.Gold -7.333333e-01 -1.33595016 -0.13071651 0.0063907
## Nam.Ngu-Chinsu.Gold -3.333333e-02 -0.63595016 0.56928349 0.9999984
## Nha.Trang-Chinsu.Gold -9.666667e-01 -1.56928349 -0.36404984 0.0000566
## Phu.Quoc-Chinsu.Gold -7.333333e-01 -1.33595016 -0.13071651 0.0063907
## Hanh.Phuc-Chinsu.Red -4.500000e-01 -1.05261682 0.15261682 0.2909487
## Nam.Ngu-Chinsu.Red 2.500000e-01 -0.35261682 0.85261682 0.8825167
## Nha.Trang-Chinsu.Red -6.833333e-01 -1.28595016 -0.08071651 0.0148274
## Phu.Quoc-Chinsu.Red -4.500000e-01 -1.05261682 0.15261682 0.2909487
## Nam.Ngu-Hanh.Phuc 7.000000e-01 0.09738318 1.30261682 0.0112820
## Nha.Trang-Hanh.Phuc -2.333333e-01 -0.83595016 0.36928349 0.9129268
## Phu.Quoc-Hanh.Phuc 8.881784e-16 -0.60261682 0.60261682 1.0000000
## Nha.Trang-Nam.Ngu -9.333333e-01 -1.53595016 -0.33071651 0.0001199
## Phu.Quoc-Nam.Ngu -7.000000e-01 -1.30261682 -0.09738318 0.0112820
## Phu.Quoc-Nha.Trang 2.333333e-01 -0.36928349 0.83595016 0.9129268
plot(TukeyHSD(res.aov.hedo))
res.lm <- lm(purchase ~ Se + Tra + Qu + Pr + Co + He,
data = pur_int)
summary(res.lm)
##
## Call:
## lm(formula = purchase ~ Se + Tra + Qu + Pr + Co + He, data = pur_int)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3607 -0.5757 -0.0056 0.6068 2.9094
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.43551 0.20841 2.090 0.0373 *
## Se 0.40623 0.04888 8.310 1.39e-15 ***
## Tra 0.08866 0.05816 1.525 0.1281
## Qu 0.02478 0.06335 0.391 0.6959
## Pr 0.16992 0.04278 3.972 8.40e-05 ***
## Co 0.04220 0.04779 0.883 0.3778
## He 0.05326 0.05877 0.906 0.3654
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.88 on 413 degrees of freedom
## Multiple R-squared: 0.3518, Adjusted R-squared: 0.3424
## F-statistic: 37.36 on 6 and 413 DF, p-value: < 2.2e-16
# general linear model
res.glm <- glm(purchase ~ Se + Tra + Qu + Pr + Co + He + product,
data = pur_int)
summary(res.glm)
##
## Call:
## glm(formula = purchase ~ Se + Tra + Qu + Pr + Co + He + product,
## data = pur_int)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.5659 -0.5659 0.0154 0.5484 2.7197
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.412104 0.232037 1.776 0.0765 .
## Se 0.359677 0.049716 7.235 2.34e-12 ***
## Tra 0.115108 0.058299 1.974 0.0490 *
## Qu -0.005556 0.063031 -0.088 0.9298
## Pr 0.205432 0.048458 4.239 2.78e-05 ***
## Co 0.028297 0.048503 0.583 0.5599
## He 0.054973 0.058505 0.940 0.3480
## productChinsu.Gold 0.331880 0.177019 1.875 0.0615 .
## productChinsu.Red 0.221826 0.168857 1.314 0.1897
## productHanh.Phuc -0.032001 0.162024 -0.198 0.8435
## productNam.Ngu 0.364101 0.160753 2.265 0.0240 *
## productNha.Trang -0.225911 0.159939 -1.412 0.1586
## productPhu.Quoc 0.141919 0.174210 0.815 0.4158
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 0.7494267)
##
## Null deviance: 493.39 on 419 degrees of freedom
## Residual deviance: 305.02 on 407 degrees of freedom
## AIC: 1085.6
##
## Number of Fisher Scoring iterations: 2
manifest variable
hoặc observed variable
: biến được đo lường trực tiếp khi thu thập dữ liệu. Trong mô hình SEM, biến manifest variable
được ký hiệu bằng hình hình vuông hoặc hình chữ nhật.latent variable
: là biến không thể đo lường trực tiếp khi thu thập dữ liệu. Thay vào đó, latent variable
được đo lường thông qua manifest variable
. Trong mô hình SEM, biến latent variable
được ký hiệu bằng hình ellipse.exogenous variable
: biến có vai trò giải thích cho biến khác trong mô hình SEM.endogenous variable
: biến được giải thích bởi các biến khác trong mô hình SEM.latent variable
được ngầm định là biến có thể giải thích được dao động trong manifest variable
. Để biểu diễn mối quan hệ này trong mô hình lý thuyết một cách trực quan, ký hiệu mũi tên \(\rightarrow\) được sử dụng, chiều của mũi tên xuất phát từ latent variable
đến manifest variable
.latent variable
được ngầm định là giải thích cho manifest variable
nhưng điều này không có nghĩa là latent variable
lúc nào cũng là exogenous variable
. Trong trường hợp một biến latent variable
được sử dụng để giải thích một biến latent variable
khác, chúng ta sẽ có một latent varible
là exogenous variable
và latent variable
còn lại là endogenous variable
.library(readxl)
library(tidyverse)
library(FactoMineR)
library(factoextra)
library(textshape)
# Import data
ss_dat1 <- read_excel("D:/Dropbox/03. Courses_Handouts/13. Consumer_science/data/sausage_behavior.xlsx")
# column to rowname
ss_dat2 <- textshape::column_to_rownames(ss_dat1,"subject")
ss_dat2
## MCA
res.mca <- MCA(ss_dat2, ncp = 5, graph = FALSE)
fviz_mca_biplot(res.mca,
repel = TRUE, # Avoid text overlapping (slow if many point)
ggtheme = theme_minimal())
## Registered S3 methods overwritten by 'car':
## method from
## influence.merMod lme4
## cooks.distance.influence.merMod lme4
## dfbeta.influence.merMod lme4
## dfbetas.influence.merMod lme4
res.hcpc <- HCPC(res.mca, nb.clust=2, graph = FALSE)
fviz_dend(res.hcpc,
rect = TRUE, rect_fill = TRUE)
## Warning in data.frame(xmin = unlist(xleft), ymin = unlist(ybottom), xmax =
## unlist(xright), : row names were found from a short variable and have been
## discarded
# nhập dữ liệu
cron_ex <- data.frame(
id = c("s1", "s2", "s3", "s4"),
item1 = c(1,4,6,5),
item2 = c(2,2,5,3),
item3 = c(3,5,7,3)
)
cron_ex
# tính cronbach's alpha
library(psy)
psy::cronbach(cron_ex[,2:4])
## $sample.size
## [1] 4
##
## $number.of.items
## [1] 3
##
## $alpha
## [1] 0.8630137
# Import data
purch_int <- read_excel("D:/Dropbox/03. Courses_Handouts/13. Consumer_science/data/ranking.xlsx")
# require packages
library(agricolae)
##
## Attaching package: 'agricolae'
## The following object is masked from 'package:factoextra':
##
## hcut
library(tidyverse)
library(ggpubr)
# names(res.F)
# res.F$statistics
# res.F$groups
ggboxplot(purch_int,
x = "factor", y = "rank",
add = "jitter",
fill = "factor"
)
# res.F <- agricolae::friedman(purch_int$subject,
# purch_int$factor,
# purch_int$rank,
# group = TRUE,
# console = TRUE)
# res.F
friedman.test(rank ~ factor | subject, data = purch_int)
##
## Friedman rank sum test
##
## data: rank and factor and subject
## Friedman chi-squared = 10.72, df = 4, p-value = 0.0299
# Normally Wilcoxon test is performed with
# only 2 groups. But still, here is the way to
# perform Wilcoxon test with multiple groups
res.Wil <- pairwise.wilcox.test(purch_int$rank, purch_int$factor,
p.adjust.method="none")
res.Wil
##
## Pairwise comparisons using Wilcoxon rank sum test with continuity correction
##
## data: purch_int$rank and purch_int$factor
##
## f1 f2 f3 f4
## f2 0.0434 - - -
## f3 0.0126 0.8271 - -
## f4 0.0193 1.0000 0.5864 -
## f5 0.0088 0.0827 0.1887 0.1251
##
## P value adjustment method: none