-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelANOVA.txt
executable file
·118 lines (114 loc) · 2.68 KB
/
modelANOVA.txt
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
model{
# N observations (subjects * withinX1 * withinX2 * betweenX3)
for(i in 1:N){
Y[i] ~ dnorm(muY[i], tauY)
muY[i] <- a0 + a1[X1[i]] + a2[X2[i]] + a3[X3[i]] + a12[X1[i],X2[i]] + a123[X1[i],X2[i],X3[i]] + aS[X1[i],X3[i],id[i]]
}
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
for (j3 in 1:nX3) {
for (s in 1:nS[j3]) {
m[j1,j2,j3,s] <- a0 + a1[j1] + a2[j2] + a3[j3] + a12[j1,j2] + a123[j1,j2,j3] + aS[j1,j3,s] # cell means
}
}
}
}
# Mean for each subject
for (j3 in 1:nX3) {
for (s in 1:nS[j3]) {
mS[j3,s] <- mean(m[1:nX1, 1:nX2, j3, s])
}
}
# Means for each treatment condition (across subjects)
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
for (j3 in 1:nX3) {
m123[j1,j2,j3] <- mean(m[j1,j2,j3,1:nS[j3]])
}
}
}
# Mean for between factor (across subjects and within factors)
for (j3 in 1:nX3) {
m3[j3] <- mean(m123[1:nX1,1:nX2,j3])
}
# Mean for within factor 1
for (j1 in 1:nX1) {
m1[j1] <- mean(m123[j1,1:nX2,1:nX3])
}
# Mean for within factor 2
for (j2 in 1:nX2) {
m2[j2] <- mean(m123[1:nX1,j2,1:nX3])
}
# Mean for 2 factor interaction
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
m12[j1,j2] <- mean(m123[j1,j2,1:nX3])
}
}
mTot = mean(m123[1:nX1,1:nX2,1:nX3])
# Intercept
intercept <- mTot
# Deflection for between factor
for (j3 in 1:nX3) {
group[j3] <- m3[j3] - mTot
}
# Deflection for within factors
for (j2 in 1:nX2) {
paradigm[j2] <- m2[j2] - mTot
}
for (j1 in 1:nX1) {
phase[j1] <- m1[j1] - mTot
}
# Deflections for interactions
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
phase_paradigm[j1,j2] <- m12[j1,j2] - (intercept + phase[j1] + paradigm[j2])
for (j3 in 1:nX3) {
phase_paradigm_group[j1,j2,j3] <- m123[j1,j2,j3] - (intercept + phase[j1] + paradigm[j2] + phase_paradigm[j1, j2] + group[j3])
}
}
}
# Deflection for each subject
for (j3 in 1:nX3) {
for (s in 1:nS[j3]) {
betaS[j3,s] <- mS[j3,s] - (intercept + group[j3])
}
}
# Priors
tauY ~ dgamma(0.001, 0.001)
for (j1 in 1:nX1) {
for (j3 in 1:nX3) {
tauS[j1,j3] ~ dt(0, 1/2.5^2,7)T(0,)
}
}
a0 ~ dnorm(0, 10^-6)
for (j1 in 1:nX1) {
a1[j1] ~ dnorm(0, 10^-6)
}
for (j2 in 1:nX2) {
a2[j2] ~ dnorm(0, 10^-6)
}
for (j3 in 1:nX3) {
a3[j3] ~ dnorm(0, 10^-6)
}
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
a12[j1,j2] ~ dnorm(0, 10^-6)
}
}
for (j1 in 1:nX1) {
for (j2 in 1:nX2) {
for(j3 in 1:nX3) {
a123[j1,j2,j3] ~ dnorm(0, 10^-6)
}
}
}
# Random effects
for (j1 in 1:nX1) {
for (j3 in 1:nX3) {
for(s in 1:nS[j3]){
aS[j1,j3,s] ~ dnorm(0, tauS[j1,j3])
}
}
}
}