-
Notifications
You must be signed in to change notification settings - Fork 0
/
2c onestep mediation.inp
240 lines (212 loc) · 8.71 KB
/
2c onestep mediation.inp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
TITLE: Onestep mediation model
DATA:
FILE = sim.dat;
VARIABLE:
NAMES = y u1 u2 u3 u4 u5 m c;
USEVARIABLES = y u1-u5 m;
CATEGORICAL = u1-u5 y;
NOMINAL = m;
CLASSES = cx(4) cm(2);
ANALYSIS:
TYPE = MIXTURE;
ESTIMATOR = MLR;
STARTS = 500 50;
PROC = 1(STARTS);
MODEL:
%OVERALL%
[cx#1] (gamma10);
[cx#2] (gamma20);
[cx#3] (gamma30);
[cm#1] (gamma01);
[y$1];
cm#1 on cx#1 (gamma11);
cm#1 on cx#2 (gamma12);
cm#1 on cx#3 (gamma13);
%cx#1.cm#1%
[u1$1*-1.6 u2$1*-1.6 u3$1*-1.6 u4$1*-1.6 u5$1*-1.6] (c11-c15);
[m#1@-25];
[y$1] (th_11);
%cx#1.cm#2%
[u1$1*-1.6 u2$1*-1.6 u3$1*-1.6 u4$1*-1.6 u5$1*-1.6] (c11-c15);
[m#1@25];
[y$1] (th_12);
%cx#2.cm#1%
[u1$1*1.6 u2$1*1 u3$1*0 u4$1*-1 u5$1*-1.6] (c21-c25);
[m#1@-25];
[y$1] (th_21);
%cx#2.cm#2%
[u1$1*1.6 u2$1*1 u3$1*0 u4$1*-1 u5$1*-1.6] (c21-c25);
[m#1@25];
[y$1] (th_22);
%cx#3.cm#1%
[u1$1*-1.6 u2$1*-1 u3$1*0 u4$1*1 u5$1*1.6] (c31-c35);
[m#1@-25];
[y$1] (th_31);
%cx#3.cm#2%
[u1$1*-1.6 u2$1*-1 u3$1*0 u4$1*1 u5$1*1.6] (c31-c35);
[m#1@25];
[y$1] (th_32);
%cx#4.cm#1%
[u1$1*1.6 u2$1*1.6 u3$1*1.6 u4$1*1.6 u5$1*1.6](c41-c45);
[m#1@-25];
[y$1] (th_41);
%cx#4.cm#2%
[u1$1*1.6 u2$1*1.6 u3$1*1.6 u4$1*1.6 u5$1*1.6] (c41-c45);
[m#1@25];
[y$1] (th_42);
model constraint:
new(a1 b11 g11 b12 g12 b13 g13 g14);
a1 = -(th_42);
b11 = th_42-th_12;
g11 = th_12-th_11;
b12 = th_42-th_22;
g12 = th_22-th_21;
b13 = th_42-th_32;
g13 = th_32-th_31;
g14 = th_42-th_41;
!class 1
NEW(p_x1m0y0 p_x1m0y1 p_x1m1y0 p_x1m1y1);
p_x1m0y1 = exp(a1+b11)/(exp(a1+b11)+1);
p_x1m0y0 = 1/(exp(a1+b11)+1);
p_x1m1y1 = exp(a1+b11+g11)/(exp(a1+b11+g11)+1);
p_x1m1y0 = 1/(exp(a1+b11+g11)+1);
!class 2
NEW(p_x2m0y0 p_x2m0y1 p_x2m1y0 p_x2m1y1);
p_x2m0y1 = exp(a1+b12)/(exp(a1+b12)+1);
p_x2m0y0 = 1/(exp(a1+b12)+1);
p_x2m1y1 = exp(a1+b12+g12)/(exp(a1+b12+g12)+1);
p_x2m1y0 = 1/(exp(a1+b12+g12)+1);
!class 3
NEW(p_x3m0y0 p_x3m0y1 p_x3m1y0 p_x3m1y1);
p_x3m0y1 = exp(a1+b13)/(exp(a1+b13)+1);
p_x3m0y0 = 1/(exp(a1+b13)+1);
p_x3m1y1 = exp(a1+b13+g13)/(exp(a1+b13+g13)+1);
p_x3m1y0 = 1/(exp(a1+b13+g13)+1);
!class 4
NEW(p_x4m0y0 p_x4m0y1 p_x4m1y0 p_x4m1y1);
p_x4m0y1 = exp(a1)/(exp(a1)+1);
p_x4m0y0 = 1/(exp(a1)+1);
p_x4m1y1 = exp(a1+g14)/(exp(a1+g14)+1);
p_x4m1y0 = 1/(exp(a1+g14)+1);
NEW(p_x1 p_x2 p_x3 p_x4);
p_x1 = exp(gamma10)/(exp(gamma10) + exp(gamma20) + exp(gamma30) + 1);
p_x2 = exp(gamma20)/(exp(gamma10) + exp(gamma20) + exp(gamma30) + 1);
p_x3 = exp(gamma30)/(exp(gamma10) + exp(gamma20) + exp(gamma30) + 1);
p_x4 = 1/(exp(gamma10) + exp(gamma20) + exp(gamma30) + 1);
NEW(p_x1m0 p_x1m1 p_x2m0 p_x2m1 p_x3m0 p_x3m1 p_x4m0 p_x4m1);
p_x1m0 = 1/(exp(gamma01+gamma11) + 1);
p_x1m1 = exp(gamma01+gamma11)/(exp(gamma01+gamma11) + 1);
p_x2m0 = 1/(exp(gamma01+gamma12) + 1);
p_x2m1 = exp(gamma01+gamma12)/(exp(gamma01+gamma12) + 1);
p_x3m0 = 1/(exp(gamma01+gamma13) + 1);
p_x3m1 = exp(gamma01+gamma13)/(exp(gamma01+gamma13) + 1);
p_x4m0 = 1/(exp(gamma01) + 1);
p_x4m1 = exp(gamma01)/(exp(gamma01) + 1);
NEW(term00 term01 term02 term03
term10 term11 term12 term13
term20 term21 term22 term23
term30 term31 term32 term33);
!these are summed across mediator
!probability that outcome=1 if exposure="class 4" and mediator obtains value that it would if exposure="class 4"
term00 = p_x4m0y1*p_x4m0 + p_x4m1y1*p_x4m1;
!probability that outcome=1 if exposure="class 4" and mediator obtains value that it would if exposure="class 3"
term01 = p_x4m0y1*p_x3m0 + p_x4m1y1*p_x3m1;
!probability that outcome=1 if exposure="class 4" and mediator obtains value that it would if exposure="class 2"
term02 = p_x4m0y1*p_x2m0 + p_x4m1y1*p_x2m1;
!probability that outcome=1 if exposure="class 4" and mediator obtains value that it would if exposure="class 1"
term03 = p_x4m0y1*p_x1m0 + p_x4m1y1*p_x1m1;
!probability that outcome=1 if exposure="class 3" and mediator obtains value that it would if exposure="class 4"
term10 = p_x3m0y1*p_x4m0 + p_x3m1y1*p_x4m1;
!probability that outcome=1 if exposure="class 3" and mediator obtains value that it would if exposure="class 3"
term11 = p_x3m0y1*p_x3m0 + p_x3m1y1*p_x3m1;
!probability that outcome=1 if exposure="class 3" and mediator obtains value that it would if exposure="class 2"
term12 = p_x3m0y1*p_x2m0 + p_x3m1y1*p_x2m1;
!probability that outcome=1 if exposure="class 3" and mediator obtains value that it would if exposure="class 1"
term13 = p_x3m0y1*p_x1m0 + p_x3m1y1*p_x1m1;
!probability that outcome=1 if exposure="class 2" and mediator obtains value that it would if exposure="class 4"
term20 = p_x2m0y1*p_x4m0 + p_x2m1y1*p_x4m1;
!probability that outcome=1 if exposure="class 2" and mediator obtains value that it would if exposure="class 3"
term21 = p_x2m0y1*p_x3m0 + p_x2m1y1*p_x3m1;
!probability that outcome=1 if exposure="class 2" and mediator obtains value that it would if exposure="class 2"
term22 = p_x2m0y1*p_x2m0 + p_x2m1y1*p_x2m1;
!probability that outcome=1 if exposure="class 2" and mediator obtains value that it would if exposure="class 1"
term23 = p_x2m0y1*p_x1m0 + p_x2m1y1*p_x1m1;
!probability that outcome=1 if exposure="class 1" and mediator obtains value that it would if exposure="class 4"
term30 = p_x1m0y1*p_x4m0 + p_x1m1y1*p_x4m1;
!probability that outcome=1 if exposure="class 1" and mediator obtains value that it would if exposure="class 3"
term31 = p_x1m0y1*p_x3m0 + p_x1m1y1*p_x3m1;
!probability that outcome=1 if exposure="class 1" and mediator obtains value that it would if exposure="class 2"
term32 = p_x1m0y1*p_x2m0 + p_x1m1y1*p_x2m1;
!probability that outcome=1 if exposure="class 1" and mediator obtains value that it would if exposure="class 1"
term33 = p_x1m0y1*p_x1m0 + p_x1m1y1*p_x1m1;
!deriving mediation effects for every possible reference class due to class switching
NEW(tot_1v4 tot_1v3 tot_1v2
tot_2v4 tot_2v3 tot_2v1
tot_3v4 tot_3v2 tot_3v1
tot_4v3 tot_4v2 tot_4v1);
tot_1v4 = ln(term33/term00);
tot_1v3 = ln(term33/term11);
tot_1v2 = ln(term33/term22);
tot_2v4 = ln(term22/term00);
tot_2v3 = ln(term22/term11);
tot_2v1 = ln(term22/term33);
tot_3v4 = ln(term11/term00);
tot_3v2 = ln(term11/term22);
tot_3v1 = ln(term11/term33);
tot_4v3 = ln(term00/term11);
tot_4v2 = ln(term00/term22);
tot_4v1 = ln(term00/term33);
NEW(tie_1v4 tie_1v3 tie_1v2
tie_2v4 tie_2v3 tie_2v1
tie_3v4 tie_3v2 tie_3v1
tie_4v3 tie_4v2 tie_4v1);
tie_1v4 = ln(term33/term30);
tie_1v3 = ln(term33/term31);
tie_1v2 = ln(term33/term32);
tie_2v4 = ln(term22/term20);
tie_2v3 = ln(term22/term21);
tie_2v1 = ln(term22/term23);
tie_3v4 = ln(term11/term10);
tie_3v2 = ln(term11/term12);
tie_3v1 = ln(term11/term13);
tie_4v3 = ln(term00/term01);
tie_4v2 = ln(term00/term02);
tie_4v1 = ln(term00/term03);
NEW(pde_1v4 pde_1v3 pde_1v2
pde_2v4 pde_2v3 pde_2v1
pde_3v4 pde_3v2 pde_3v1
pde_4v3 pde_4v2 pde_4v1);
pde_1v4 = ln(term30/term00);
pde_1v3 = ln(term31/term11);
pde_1v2 = ln(term32/term22);
pde_2v4 = ln(term20/term00);
pde_2v3 = ln(term21/term11);
pde_2v1 = ln(term23/term33);
pde_3v4 = ln(term10/term00);
pde_3v2 = ln(term12/term22);
pde_3v1 = ln(term13/term33);
pde_4v3 = ln(term01/term11);
pde_4v2 = ln(term02/term22);
pde_4v1 = ln(term03/term33);
!deriving AUC to work out class order
NEW(auc1 auc2 auc3 auc4);
auc1 = exp(-c11)/(1+exp(-c11))
+ 2*exp(-c12)/(1+exp(-c12))
+ 3*exp(-c13)/(1+exp(-c13))
+ 4*exp(-c14)/(1+exp(-c14))
+ 5*exp(-c15)/(1+exp(-c15));
auc2 = exp(-c21)/(1+exp(-c21))
+ 2*exp(-c22)/(1+exp(-c22))
+ 3*exp(-c23)/(1+exp(-c23))
+ 4*exp(-c24)/(1+exp(-c24))
+ 5*exp(-c25)/(1+exp(-c25));
auc3 = exp(-c31)/(1+exp(-c31))
+ 2*exp(-c32)/(1+exp(-c32))
+ 3*exp(-c33)/(1+exp(-c33))
+ 4*exp(-c34)/(1+exp(-c34))
+ 5*exp(-c35)/(1+exp(-c35));
auc4 = exp(-c41)/(1+exp(-c41))
+ 2*exp(-c42)/(1+exp(-c42))
+ 3*exp(-c43)/(1+exp(-c43))
+ 4*exp(-c44)/(1+exp(-c44))
+ 5*exp(-c45)/(1+exp(-c45));