Skip to content

Commit cb26627

Browse files
committed
fix(hgf): sigma_base assignement bug
1 parent 09408cf commit cb26627

7 files changed

Lines changed: 45 additions & 43 deletions

File tree

commons/stan_files/ehgf_ibrb.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ transformed data {
7373
}
7474
}
7575
sigma_base[1] = 0;
76-
sigma_base[2:L] = sigma0;
76+
for (l in 2:L) {
77+
sigma_base[l] = sigma0[l-1];
78+
}
7779

7880
// differentiate free kappa and fixed kappa
7981
for (l in 1:(L-2)) {

commons/stan_files/ehgf_ibrb_multipleB.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ transformed data {
7979
}
8080
}
8181
sigma_base[1] = 0;
82-
sigma_base[2:L] = sigma0;
82+
for (l in 2:L) {
83+
sigma_base[l] = sigma0[l-1];
84+
}
8385

8486
// differentiate free kappa and fixed kappa
8587
for (l in 1:(L-2)) {

commons/stan_files/ehgf_ibrb_vds.stan

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ transformed data {
7070
}
7171
}
7272
sigma_base[1] = 0;
73-
sigma_base[2:L] = sigma0;
73+
for (l in 2:L) {
74+
sigma_base[l] = sigma0[l-1];
75+
}
7476

7577
// differentiate free kappa and fixed kappa
7678
for (l in 1:(L-2)) {
@@ -223,14 +225,6 @@ model {
223225
}
224226
sa_hat[L] = sa[L] + exp(omega[i,L-1]);
225227

226-
// Response model (volatility-dependent stochasticity)
227-
if (!input_first) {
228-
// make choice based on previous valid input or inital prior belief
229-
real zeta = exp(-mu_hat[3]);
230-
real eta = zeta * mu_hat[2];
231-
y[i,t] ~ bernoulli_logit(eta);
232-
}
233-
234228
sa_prev = sa;
235229

236230
// Level 2
@@ -268,7 +262,12 @@ model {
268262
}
269263

270264
// Response model (volatility-dependent stochasticity)
271-
if (input_first) {
265+
if (!input_first) {
266+
// make choice based on previous valid input or inital prior belief
267+
real zeta = exp(-mu_hat[3]);
268+
real eta = zeta * mu_hat[2];
269+
y[i,t] ~ bernoulli_logit(eta);
270+
} else {
272271
// make choice based on current input
273272
real zeta = exp(-mu[3-1]);
274273
real eta = zeta * mu[2-1];
@@ -318,14 +317,6 @@ generated quantities {
318317
sa_hat[l] = sa[l] + exp(ka * mu[(l+1)-1] + om);
319318
}
320319
sa_hat[L] = sa[L] + exp(omega[i,L-1]);
321-
322-
// Response model (volatility-dependent stochasticity)
323-
if (!input_first) {
324-
// make choice based on previous valid input or inital prior belief
325-
real zeta = exp(-mu_hat[3]);
326-
real eta = zeta * mu_hat[2];
327-
log_lik += bernoulli_logit_lpmf(y[i,t] | eta);
328-
}
329320

330321
sa_prev = sa;
331322

@@ -364,7 +355,12 @@ generated quantities {
364355
}
365356

366357
// Response model (volatility-dependent stochasticity)
367-
if (input_first) {
358+
if (!input_first) {
359+
// make choice based on previous valid input or inital prior belief
360+
real zeta = exp(-mu_hat[3]);
361+
real eta = zeta * mu_hat[2];
362+
log_lik += bernoulli_logit_lpmf(y[i,t] | eta);
363+
} else {
368364
// make choice based on current input
369365
real zeta = exp(-mu[3-1]);
370366
real eta = zeta * mu[2-1];

commons/stan_files/ehgf_ibrb_vds_multipleB.stan

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ transformed data {
7676
}
7777
}
7878
sigma_base[1] = 0;
79-
sigma_base[2:L] = sigma0;
79+
for (l in 2:L) {
80+
sigma_base[l] = sigma0[l-1];
81+
}
8082

8183
// differentiate free kappa and fixed kappa
8284
for (l in 1:(L-2)) {
@@ -231,14 +233,6 @@ model {
231233
}
232234
sa_hat[L] = sa[L] + exp(omega[i,L-1]);
233235

234-
// Response model (volatility-dependent stochasticity)
235-
if (!input_first) {
236-
// make choice based on previous valid input or inital prior belief
237-
real zeta = exp(-mu_hat[3]);
238-
real eta = zeta * mu_hat[2];
239-
y[i,bIdx,t] ~ bernoulli_logit(eta);
240-
}
241-
242236
sa_prev = sa;
243237

244238
// Level 2
@@ -276,7 +270,12 @@ model {
276270
}
277271

278272
// Response model (volatility-dependent stochasticity)
279-
if (input_first) {
273+
if (!input_first) {
274+
// make choice based on previous valid input or inital prior belief
275+
real zeta = exp(-mu_hat[3]);
276+
real eta = zeta * mu_hat[2];
277+
y[i,bIdx,t] ~ bernoulli_logit(eta);
278+
} else {
280279
// make choice based on current input
281280
real zeta = exp(-mu[3-1]);
282281
real eta = zeta * mu[2-1];
@@ -329,14 +328,6 @@ generated quantities {
329328
}
330329
sa_hat[L] = sa[L] + exp(omega[i,L-1]);
331330

332-
// Response model (volatility-dependent stochasticity)
333-
if (!input_first) {
334-
// make choice based on previous valid input or inital prior belief
335-
real zeta = exp(-mu_hat[3]);
336-
real eta = zeta * mu_hat[2];
337-
log_lik += bernoulli_logit_lpmf(y[i,bIdx,t] | eta);
338-
}
339-
340331
sa_prev = sa;
341332

342333
// Level 2
@@ -374,7 +365,12 @@ generated quantities {
374365
}
375366

376367
// Response model (volatility-dependent stochasticity)
377-
if (input_first) {
368+
if (!input_first) {
369+
// make choice based on previous valid input or inital prior belief
370+
real zeta = exp(-mu_hat[3]);
371+
real eta = zeta * mu_hat[2];
372+
log_lik += bernoulli_logit_lpmf(y[i,bIdx,t] | eta);
373+
} else {
378374
// make choice based on current input
379375
real zeta = exp(-mu[3-1]);
380376
real eta = zeta * mu[2-1];

commons/stan_files/hgf_ibrb.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ transformed data {
7070
}
7171
}
7272
sigma_base[1] = 0;
73-
sigma_base[2:L] = sigma0;
73+
for (l in 2:L) {
74+
sigma_base[l] = sigma0[l-1];
75+
}
7476

7577
// differentiate free kappa and fixed kappa
7678
for (l in 1:(L-2)) {

commons/stan_files/hgf_ibrb_multipleB.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ transformed data {
7676
}
7777
}
7878
sigma_base[1] = 0;
79-
sigma_base[2:L] = sigma0;
79+
for (l in 2:L) {
80+
sigma_base[l] = sigma0[l-1];
81+
}
8082

8183
// differentiate free kappa and fixed kappa
8284
for (l in 1:(L-2)) {

commons/stan_files/hgf_ibrb_single.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ transformed data {
5151
mu_base[1] = 0;
5252
mu_base[2:L] = mu0;
5353
sigma_base[1] = 0;
54-
sigma_base[2:L] = sigma0;
54+
for (l in 2:L) {
55+
sigma_base[l] = sigma0[l-1];
56+
}
5557

5658
// differentiate free kappa and fixed kappa
5759
for (l in 1:(L-2)) {

0 commit comments

Comments
 (0)