-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.stan
More file actions
33 lines (31 loc) · 728 Bytes
/
git.stan
File metadata and controls
33 lines (31 loc) · 728 Bytes
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
data {
int<lower=0> n_trials;
int<lower=0> n_dogs;
int<lower=0,upper=1> y[n_dogs,n_trials];
}
parameters {
vector[2] beta;
}
transformed parameters {
matrix[n_dogs,n_trials] n_avoid;
matrix[n_dogs,n_trials] n_shock;
matrix[n_dogs,n_trials] p;
for (j in 1:n_dogs) {
n_avoid[j,1] = 0;
n_shock[j,1] = 0;
for (t in 2:n_trials) {
n_avoid[j,t] = n_avoid[j,t-1] + 1 - y[j,t-1];
n_shock[j,t] = n_shock[j,t-1] + y[j,t-1];
}
for (t in 1:n_trials)
p[j,t] = inv_logit(beta[1] * n_avoid[j,t] + beta[2] * n_shock[j,t]);
}
}
model {
beta[1] ~ uniform(-100, 0);
beta[2] ~ uniform(0, 100);
for (i in 1:n_dogs) {
for (j in 1:n_trials)
y[i,j] ~ bernoulli(p[i,j]);
}
}