-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject script.R
50 lines (32 loc) · 1.3 KB
/
project script.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
## New data (11/19/20) - our focus is A30 - A41 (used to be r30-r41)
## selection = MI groups
library(Hmisc)
library(careless)
data <- spss.get("TD-12 Research ABD combined N735 SIOP.sav")
write.csv(data, "SIOP.csv")
data$long <- longstring(data[2:13], avg = FALSE) ## then sort and screen
newdata <- data[ which(data$long < 9), ]
write.csv(newdata, "cleanedSIOP.csv")
## Tutorial on MI in R here: https://www.frontiersin.org/articles/10.3389/fpsyg.2019.01507/full
data$group[data$long < 3 ] <- "Low Stakes" ## temporary placeholder for real groups
data$group[data$long >= 3 ] <- "High Stakes"
data$group <- as.factor(data$group)
library(lavaan) ## CFAs
data2 <- data[,c(2:13,15)] ## getting rid of non-group/non-items
model <- ' mach =~ R30 + R31 + R32 + R33
narc =~ R34 + R35 + R36 + R37
psyc =~ R38 + R39 + R40 + R41 '
fit <- cfa(model,
data = data2,
group = "group")
summary(fit)
## MI below: https://www.rdocumentation.org/packages/semTools/versions/0.5-1/topics/measEq.syntax
## Another resource: https://jslefche.github.io/sem_book/multigroup-analysis.html
library(semPlot)
layout(t(1:2))
semPaths(fit,what="std",layout="tree")
library(semTools)
MI <- measEq.syntax(model,
data = data2,
group = "group")
summary(MI)