-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dynamic IRT binary outcome
55 lines (42 loc) · 1.52 KB
/
Dynamic IRT binary outcome
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
data {
int<lower=1> N; // Number of observation. (for parties)
int<lower=1> I; // Number of items (same for parties and cantons)
int<lower=1> J; // Number of Actors
int<lower=1> T; // Number of time point
int<lower=0, upper=1> y[N]; // list of outcome (binary for parties)
int<lower=1> i[N]; // list of items
int<lower=1> j[N]; // list of actors
int<lower=1> t[N]; // list of time points
}
parameters {
vector[I] alpha; // Difficulty parameter
vector[I] beta; // Discrimination parameter
vector[J] theta; // ideal position of actor j at time t;
vector[J] time[T-1]; // random time variable.
vector<lower=0, upper =1>[J] time_var; // Time variance
}
transformed parameters {
vector[J] theta2[T];
vector[N] p_binary;
for(n in 1:T) {
if(n==1) {
theta2[n] = theta; // At time = 0
} if(n>1) {
theta2[n] = theta2[n-1] + time[n-1] .* time_var; // Otherwise normally distributed around the observation at previous time
}
}
for (n in 1:N) {
p_binary[n] = inv_logit(theta2[t[n], j[n]] * beta[i[n]] + alpha[i[n]]); // Define the parameter in this block. Helps with the computation issues.
}
}
model {
beta ~ normal(0, 5); // Prior for the discrimination of items
alpha ~ normal(0, 5); // Prior for the difficulty of items
target += exponential_lpdf(time_var| 10); // Prior for the time
theta ~ std_normal();
// at time 1, no difference between theta and theta2
for (n in 1:T-1) {
time[n] ~ std_normal(); // Time parameter
}
y ~ bernoulli(p_binary);
}