-
Notifications
You must be signed in to change notification settings - Fork 0
/
AE_AC_GPCM.R
135 lines (110 loc) · 3.63 KB
/
AE_AC_GPCM.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
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
#y_dz = Item responses of DZ twins (matrix)
#y_mz = Item responses of MZ twins (matrix)
#n_mz = Number of MZ twin pairs
#n_dz = Number of DZ twin pairs
#n_items = Number of items administered
#Required structure of the y_dz/y_mz data matrix:
#y_dz[i,k] = kth datapoint from the ith DZ twin pair
#y_mz[i,k] = kth datapoint from the ith MZ twin pair
#This results in a matrix of n_mz (or, in case of y_dz, n_dz)
#rows and 2*n_items columns. e.g. y_mz[1,22] is the response
#of MZ twin 1 from family 1 to item 22 if n_items = 22
#JAGS uses precision parameters for the variance parameters.
#Therefore, after running the script, these precision parameters
#have to be inverted. For example:
#var_a <- 1/outputAnalysis$tau_a[,,1] with the rjags package
model{
#MZ twins
for (i in 1:n_mz){
c_mz[i] ~ dnorm(0, tau_c_mz[i])
a_mz[i] ~ dnorm(0, tau_a)
tau_c_mz[i] <- 1/(exp(gamma0 + gamma1*a_mz[i]))
tau_e_mz[i] <- 1/(exp(beta0 + beta1*a_mz[i]))
#Phenotypic values:
mz[i,1] ~ dnorm(a_mz[i] + c_mz[i], tau_e_mz[i])
mz[i,2] ~ dnorm(a_mz[i] + c_mz[i], tau_e_mz[i])
for (j in 1:n_items){
for (k in 1:3){
eta[i,j,k] <- alpha[j] *
(mz[i,1]-beta[j,k])
psum[i,j,k] <- sum(eta[i,j,1: k])
exp_psum[i,j,k] <- exp(psum [i,j,k])
prob[i,j,k] <- exp_psum[i,j,k]/sum(exp_psum [i,j,1:3])
}
}
for (j in (n_items+1):(2*n_items)){
for (k in 1:3){
eta[i,j,k] <- alpha[j-n_items] *
(mz[i,2]-beta[j-n_items,k])
psum [i,j,k] <- sum(eta[i,j,1: k])
exp_psum [i,j,k] <- exp( psum [i , j , k])
prob [i,j,k] <- exp_psum[i,j,k]/sum(exp_psum [i,j,1:3])
}
}
for (j in 1:(2*n_items)){
y_mz[i,j] ~ dcat (prob[i,j,1:3])
}
} #end MZ twins
#DZ twins
for (i in 1:n_dz){
c_dz[i] ~ dnorm(0, 1)
a1_dz[i] ~ dnorm(0, doubletau_a)
a2_dz[i,1] ~ dnorm(a1_dz[i], doubletau_a)
a2_dz[i,2] ~ dnorm(a1_dz[i], doubletau_a)
tau_c_dz[i,1] <- exp(gamma0 + gamma1*a2_dz[i,1])
tau_c_dz[i,2] <- exp(gamma0 + gamma1*a2_dz[i,2])
c_dz_twin1[i] <- c_dz[i] * sqrt(tau_c_dz[i,1])
c_dz_twin2[i] <- c_dz[i] * sqrt(tau_c_dz[i,2])
tau_e_dz[i,1] <- 1/(exp(beta0 + beta1*a2_dz[i,1]))
tau_e_dz[i,2] <- 1/(exp(beta0 + beta1*a2_dz[i,2]))
dz[i,1] ~ dnorm(a2_dz[i,1] + c_dz_twin1[i], tau_e_dz[i,1])
dz[i,2] ~ dnorm(a2_dz[i,2] + c_dz_twin2[i], tau_e_dz[i,2])
for (j in 1:n_items){
for (k in 1:3){
etadz[i,j,k] <- alpha [j] * (dz[i,1]-beta [j,k])
psumdz [i,j,k] <- sum(etadz[i,j,1: k])
exp_psumdz[i,j,k] <- exp(psumdz [i,j,k])
probdz [i,j,k] <- exp_psumdz [i,j,k]/
sum(exp_psumdz[i,j,1:3])
}
}
for (j in (n_items+1):(2*n_items)){
for (k in 1:3){
etadz[i,j,k] <- alpha[j-n_items] *
(dz[i,2]-beta [j-n_items,k])
psumdz [i,j,k] <- sum(etadz[i,j,1:k])
exp_psumdz [i,j,k] <- exp(psumdz [i,j,k])
probdz [i,j,k] <- exp_psumdz [i,j,k]/
sum(exp_psumdz [i,j,1:3])
}
}
for (j in 1:(2*n_items)){
y_dz[i,j] ~ dcat (probdz[i,j,1:3])
}
} #end DZ twins
#DZ twins genetic correlation 0.5:
doubletau_a <- 2*tau_a
#Set alpha of item 3 to 1 to identify the scale
alpha[3] <- 1
#for the rest of the alpha parameters:
#lognormal prior with expectation of 0
#and variance of 10
alpha[1] ~ dlnorm(0, .1)
alpha[2] ~ dlnorm(0, .1)
for (j in 4:n_items){
alpha[j] ~ dlnorm(0, .1)
}
#Beta IRT parameters:
for (j in 1:n_items){
beta [j , 1] <- 0.0
for (k in 2:3){
beta [j , k] ~ dnorm (0, .1)
}
}
#Priors distributions:
tau_a ~ dgamma(1,1)
beta0 ~ dnorm(-1,.5)
beta1 ~ dnorm(0,.1)
gamma0 ~ dnorm(-1,.5)
gamma1 ~ dnorm(0,.1)
}