Here, the R data set …..
## # A tibble: 200 x 15
## Respondent_ID Gender IncomeDummy Safe1 ComCon1 Affordable1 Frequency1 People1
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 1 0 2 2 2 3 4
## 2 2 1 0 2 1 2 1 3
## 3 3 1 0 3 3 1 1 3
## 4 4 0 0 3 3 3 3 2
## 5 5 1 0 2 2 4 3 4
## 6 6 1 0 4 1 1 3 3
## 7 7 1 0 3 3 2 3 3
## 8 8 0 0 4 3 3 3 3
## 9 9 0 0 1 1 2 3 2
## 10 10 1 1 2 1 3 2 3
## # ... with 190 more rows, and 7 more variables: PubOpinion1 <dbl>,
## # SMedia1 <dbl>, Access1 <dbl>, Money1 <dbl>, Capable1 <dbl>,
## # PTUse_Intention <dbl>, Trips_per_Month <dbl>
There are several packages used in this example:
library(stats)
library(lavaan)
library(readr)
library(semPlot)Loading data set **** into R’s workspace and assigning it to df_all (for convenience):
df_all <- read_csv("SEM_Data.csv",
col_types = cols(Respondent_ID = col_character(),
.default = col_number()),
na = "empty",
skip_empty_rows = TRUE)df_all_model_binary <- df_all
df_all_model_binary$PTUse_Intention_dum = ifelse(df_all_model_binary$PTUse_Intention < 3, 0, 1)
df_all_model_binary## # A tibble: 200 x 16
## Respondent_ID Gender IncomeDummy Safe1 ComCon1 Affordable1 Frequency1 People1
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 1 0 2 2 2 3 4
## 2 2 1 0 2 1 2 1 3
## 3 3 1 0 3 3 1 1 3
## 4 4 0 0 3 3 3 3 2
## 5 5 1 0 2 2 4 3 4
## 6 6 1 0 4 1 1 3 3
## 7 7 1 0 3 3 2 3 3
## 8 8 0 0 4 3 3 3 3
## 9 9 0 0 1 1 2 3 2
## 10 10 1 1 2 1 3 2 3
## # ... with 190 more rows, and 8 more variables: PubOpinion1 <dbl>,
## # SMedia1 <dbl>, Access1 <dbl>, Money1 <dbl>, Capable1 <dbl>,
## # PTUse_Intention <dbl>, Trips_per_Month <dbl>, PTUse_Intention_dum <dbl>
binary and observed variables are continuous)Considering the following latent variables & assuming that no covariance exists among variables:
AttitudeSubjective NormPerceived Behavioral ControlmodelSEM_syntax <- '# Measurement models,
Attitude =~ 1*Safe1 + ComCon1 + Affordable1 + Frequency1
SubNorm =~ 1*People1 + PubOpinion1 + SMedia1
PBC =~ 1*Access1 + Money1 + Capable1
#Structural part of the model (linear regressions)
PTUse_Intention_dum ~ Attitude + SubNorm + PBC
'fitSEM <- lavaan::sem(model = modelSEM_syntax,
data = df_all_model_binary,
orthogonal = T, #If TRUE, all covariances among latent variables are set to zero.
)summary(fitSEM, fit.measures = TRUE, standardized = TRUE)## lavaan 0.6-8 ended normally after 39 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 24
##
## Number of observations 200
##
## Model Test User Model:
##
## Test statistic 247.040
## Degrees of freedom 42
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 951.252
## Degrees of freedom 55
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.771
## Tucker-Lewis Index (TLI) 0.700
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1921.836
## Loglikelihood unrestricted model (H1) -1798.316
##
## Akaike (AIC) 3891.671
## Bayesian (BIC) 3970.831
## Sample-size adjusted Bayesian (BIC) 3894.796
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.156
## 90 Percent confidence interval - lower 0.138
## 90 Percent confidence interval - upper 0.175
## P-value RMSEA <= 0.05 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.261
##
## 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
## Attitude =~
## Safe1 1.000 0.600 0.749
## ComCon1 1.096 0.107 10.208 0.000 0.658 0.807
## Affordable1 0.881 0.103 8.536 0.000 0.528 0.655
## Frequency1 0.934 0.106 8.823 0.000 0.560 0.677
## SubNorm =~
## People1 1.000 0.476 0.695
## PubOpinion1 1.351 0.134 10.119 0.000 0.643 0.951
## SMedia1 1.016 0.100 10.139 0.000 0.483 0.768
## PBC =~
## Access1 1.000 0.485 0.651
## Money1 1.117 0.184 6.078 0.000 0.542 0.802
## Capable1 0.632 0.100 6.312 0.000 0.307 0.589
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PTUse_Intention_dum ~
## Attitude 0.456 0.058 7.827 0.000 0.273 0.592
## SubNorm -0.140 0.060 -2.324 0.020 -0.066 -0.144
## PBC -0.087 0.065 -1.347 0.178 -0.042 -0.092
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Attitude ~~
## SubNorm 0.000 0.000 0.000
## PBC 0.000 0.000 0.000
## SubNorm ~~
## PBC 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Safe1 0.281 0.038 7.457 0.000 0.281 0.438
## .ComCon1 0.232 0.037 6.332 0.000 0.232 0.349
## .Affordable1 0.372 0.044 8.542 0.000 0.372 0.571
## .Frequency1 0.370 0.044 8.347 0.000 0.370 0.541
## .People1 0.241 0.029 8.470 0.000 0.241 0.516
## .PubOpinion1 0.043 0.028 1.560 0.119 0.043 0.095
## .SMedia1 0.162 0.022 7.204 0.000 0.162 0.409
## .Access1 0.319 0.047 6.806 0.000 0.319 0.576
## .Money1 0.162 0.046 3.554 0.000 0.162 0.356
## .Capable1 0.177 0.022 7.894 0.000 0.177 0.653
## .PTUs_Intntn_dm 0.132 0.015 8.853 0.000 0.132 0.620
## Attitude 0.360 0.063 5.728 0.000 1.000 1.000
## SubNorm 0.226 0.043 5.282 0.000 1.000 1.000
## PBC 0.235 0.057 4.136 0.000 1.000 1.000
semPaths(object = fitSEM,
layout = 'tree2',
intercepts = F,
what = "std",
whatLabels = 'std',
combineGroups = F,
rotation = 4,
thresholds = F,
residuals = F,
nCharNodes = 4,
curve = T,
intStyle = 'multi',
shapeLat = 'ellipse',
optimizeLatRes = T,
style = "lisrel",
ask = F,
sizeLat = 10,
sizeMan = 6,
sizeInt = 10
)