Skip to content

Commit d9ca888

Browse files
committed
fix probit-multi
1 parent ba3900f commit d9ca888

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
functions {
2-
int sum(int[,] a) {
3-
int s;
4-
s <- 0;
5-
for (i in 1:size(a))
6-
for (j in 1:size(a[i]))
7-
s <- s + a[i,j];
2+
int sum_2darray(int[,] a) {
3+
int s = 0;
4+
for (i in 1:size(a)) {
5+
s = s +sum(a[i]);
6+
}
87
return s;
98
}
109
}
@@ -17,29 +16,27 @@ data {
1716
}
1817
transformed data {
1918
int<lower=0> N_pos;
20-
int<lower=1,upper=N> n_pos[sum(y)];
19+
int<lower=1,upper=N> n_pos[sum_2darray(y)];
2120
int<lower=1,upper=D> d_pos[size(n_pos)];
2221
int<lower=0> N_neg;
2322
int<lower=1,upper=N> n_neg[(N * D) - size(n_pos)];
2423
int<lower=1,upper=D> d_neg[size(n_neg)];
2524

26-
N_pos <- size(n_pos);
27-
N_neg <- size(n_neg);
25+
N_pos = size(n_pos);
26+
N_neg = size(n_neg);
2827
{
29-
int i;
30-
int j;
31-
i <- 1;
32-
j <- 1;
28+
int i = 1;
29+
int j = 1;
3330
for (n in 1:N) {
3431
for (d in 1:D) {
3532
if (y[n,d] == 1) {
36-
n_pos[i] <- n;
37-
d_pos[i] <- d;
38-
i <- i + 1;
33+
n_pos[i] = n;
34+
d_pos[i] = d;
35+
i = i + 1;
3936
} else {
40-
n_neg[j] <- n;
41-
d_neg[j] <- d;
42-
j <- j + 1;
37+
n_neg[j] = n;
38+
d_neg[j] = d;
39+
j = j + 1;
4340
}
4441
}
4542
}
@@ -54,21 +51,21 @@ parameters {
5451
transformed parameters {
5552
vector[D] z[N];
5653
for (n in 1:N_pos)
57-
z[n_pos[n], d_pos[n]] <- z_pos[n];
54+
z[n_pos[n], d_pos[n]] = z_pos[n];
5855
for (n in 1:N_neg)
59-
z[n_neg[n], d_neg[n]] <- z_neg[n];
56+
z[n_neg[n], d_neg[n]] = z_neg[n];
6057
}
6158
model {
6259
L_Omega ~ lkj_corr_cholesky(4);
6360
to_vector(beta) ~ normal(0, 5);
64-
{
61+
{
6562
vector[D] beta_x[N];
66-
for (n in 1:N)
67-
beta_x[n] <- beta * x[n];
63+
for (n in 1:N) {
64+
beta_x[n] = beta * x[n];
65+
}
6866
z ~ multi_normal_cholesky(beta_x, L_Omega);
6967
}
7068
}
7169
generated quantities {
72-
corr_matrix[D] Omega;
73-
Omega <- multiply_lower_tri_self_transpose(L_Omega);
70+
corr_matrix[D] Omega = multiply_lower_tri_self_transpose(L_Omega);
7471
}

0 commit comments

Comments
 (0)