The example code listed at the bottom produces the following error:
Semantic error in '/var/folders/np/d_865sb11c93jr4g3vdjws8r0000gs/T/RtmpQ4sg49/model-332b1d1c9bf8.stan', line 27, column 16 to column 17:
-------------------------------------------------
25: vector[1934] p;
26: vector[61] a;
27: vector[61] a;
^
28: a = abar + za * sigma_a;
29: for ( i in 1:1934 ) {
-------------------------------------------------
Identifier 'a' is already in use.
The problem I suspect is that both log_lik and save> independently introduce a declaration to the generated_quantities block.
Changing save> to transpars> or removing log_lik = TRUE compiles successfully.
Code follows:
library(rethinking)
data(bangladesh)
d <- bangladesh
dat <- list(
C = d$use.contraception,
D = as.integer(d$district)
)
m2 <- ulam(
alist(
C ~ dbern(p),
logit(p) <- a[D],
save > vector[61]:a <<- abar + za * sigma_a,
vector[61]:za ~ dnorm(0, 1),
abar ~ dnorm(0, 1),
sigma_a ~ dexp(1)
),
data = dat, chains = 4, cores = 4, log_lik = TRUE
)
The example code listed at the bottom produces the following error:
The problem I suspect is that both
log_lik
andsave>
independently introduce a declaration to thegenerated_quantities
block. Changingsave>
totranspars>
or removinglog_lik = TRUE
compiles successfully.Code follows: