-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmediation_analysis.R
executable file
·64 lines (57 loc) · 1.36 KB
/
mediation_analysis.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
58
59
60
61
62
63
64
library(lavaan)
setwd('U:/joe_python/GitHub/Learning_Connectome')
data <- read.csv('./data/hub_mediation.csv')
data[colnames(data)[2:length(colnames(data))]] <- scale(data[colnames(data)[2:length(colnames(data))]])
data['Age'] = data['Age']**2
# Reading and clustering coefficient
model <- ' # direct effect
Reading ~ c*Age
# mediator
hub_clustering ~ a*Age
Reading ~ b*hub_clustering
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit <- sem(model, data = data)
summary(fit, fit.measures=TRUE)
# Reading and global efficiency
model <- ' # direct effect
Reading ~ c*Age
# mediator
hub_efficiency ~ a*Age
Reading ~ b*hub_efficiency
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit <- sem(model, data = data)
summary(fit, fit.measures=TRUE)
# Maths and clustering coefficient
model <- ' # direct effect
Maths ~ c*Age
# mediator
hub_clustering ~ a*Age
Maths ~ b*hub_clustering
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit <- sem(model, data = data)
summary(fit, fit.measures=TRUE)
# Maths and global efficiency
model <- ' # direct effect
Maths ~ c*Age
# mediator
hub_efficiency ~ a*Age
Maths ~ b*hub_efficiency
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit <- sem(model, data = data)
summary(fit, fit.measures=TRUE)