Closed simeonqs closed 3 years ago
Are you able to print the stan code generated by ulam? Reject is a reserved word in the stan language
This code below works:
library(rethinking)
# prep data
data( UCBadmit )
UCBadmit$male <- as.integer(UCBadmit$applicant.gender=="male")
UCBadmit$dept <- rep( 1:6 , each=2 )
UCBadmit$applicant.gender <- NULL
UCBadmit$rejected <- UCBadmit$reject
UCBadmit$reject <- NULL
# varying intercepts model
m_glmm1 <- ulam(
alist(
admit ~ binomial(applications,p),
logit(p) <- a[dept] + b*male,
a[dept] ~ normal( abar , sigma ),
abar ~ normal( 0 , 4 ),
sigma ~ half_normal(0,1),
b ~ normal(0,1)
), data=UCBadmit, chains = 4, cores = 4, iter = 1000, control = list(max_treedepth = 15, adapt_delta = 0.8), cmdstan = TRUE)
The trick is to rename $reject
to $rejected
in
UCBadmit$rejected <- UCBadmit$reject UCBadmit$reject <- NULL
For reference, the generated code that errors is:
data{
int reject[12];
int applications[12];
int admit[12];
int male[12];
int dept[12];
}
parameters{
vector[6] a;
real abar;
real<lower=0> sigma;
real b;
}
model{
vector[12] p;
b ~ normal( 0 , 1 );
sigma ~ normal( 0 , 1 );
abar ~ normal( 0 , 4 );
a ~ normal( abar , sigma );
for ( i in 1:12 ) {
p[i] = a[dept[i]] + b * male[i];
p[i] = inv_logit(p[i]);
}
admit ~ binomial( applications , p );
}
Will close, as there is not much that can be done on our end. Reject is a reserved keyword.
Thanks a lot. This is an example for Richards McElreath rethinking package, but it's good to know what causes the issue.
Thanks. Can you link me to the example?
https://github.com/rmcelreath/rethinking
Under Multilevel model formulas. I added a few settings to test if changing treedepth, cores etc. caused any issues.
I got this error while compiling a standard test model in the rethinking package:
code: