-
Notifications
You must be signed in to change notification settings - Fork 0
/
sem.R
57 lines (48 loc) · 1.13 KB
/
sem.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Identify the SEM model
library(lavaan)
# load data
data=read.csv("test.csv",header=TRUE)
# remove na
data <- data[!(rowSums(is.na(data))),]
# set the initial model
# Input vars -> emotional responses -> output
model <- '
# Touch
Touch ~ Gender + attn + Int + Vols
# Excel
Excel ~ Gender + attn + Int + Vols
# Diff
Diff ~ Gender + attn + Int + Vols
# Final output
pVolsOX ~ Gender + attn + Int + Vols + Touch + Excel + Diff
'
# run SEM
original <- sem(model, data = data, ordered = 'pVolsOX')
summary(original)
# remove non-significant paths
mod_model <- '
# Touch
Touch ~ Int
# Excel
Excel ~ Int
# Diff
Diff ~ attn + Vols
# Final output
pVolsOX ~ attn + Vols + Excel
'
modified <- sem(mod_model, data = data, ordered = 'pVolsOX')
summary(modified,fit.measures=TRUE, modindices=T)
# modification
mod_model1 <- '
# Touch
Touch ~ Int
# Excel
Excel ~ Int
# Diff
Diff ~ attn + Vols
# Final output
pVolsOX ~ attn + Vols + Excel
Touch ~~ Excel
'
modified1 <- sem(mod_model1, data = data, ordered = 'pVolsOX')
summary(modified1,fit.measures=TRUE, modindices=T)