Error in prep_call_sampler(object)

H all,

I’m getting a rather strange error that I have not received in earlier analyses of exactly the same code and data. The error message reads

Error in prep_call_sampler(object) : the compiled object from C++ code for this model is invalid, possible reasons: - compiled with save_dso=FALSE; - compiled on a different platform; - does not exist (created from reading csv files).

Here is the code

modelString ="
data {
int <lower=0> n;
vector[n] age;
vector[n] male;
int <lower=0,upper=1> chd[n];
}
parameters {
real alpha;
real beta1;
real beta2;
}

transformed parameters {
real <lower=0> oddsbeta1;
real <lower=0> oddsbeta2;

oddsbeta1 = exp(beta1);
oddsbeta2 = exp(beta2);

}

model {
for (i in 1:n) {
chd[i] ~ bernoulli_logit(alpha + beta1age[i] + beta2male[i]);
}

// Priors
alpha ~ normal(0, 1);
beta1 ~ normal(0, 1);
beta2 ~ normal(0, 1);
}

generated quantities {
real chd_rep[n];
vector[n] log_lik;
for (i in 1:n) {
chd_rep[i] = bernoulli_logit_rng(alpha + beta1age[i] + beta2male[i]);
log_lik[i] = bernoulli_logit_lpmf(chd[i] | alpha + beta1age[i] +
beta2
male[i]);
}

}
"

# Start estimation
```{r, echo=TRUE}
nChains = 3
nIter= 30000
thinSteps = 10
burnInSteps = floor(nIter/2)


myfitCHD = stan(data=data.list,model_code=modelString,chains=nChains,
              iter=nIter,warmup=burnInSteps,thin=thinSteps)


Thanks in advance,

David

Hi David,

Do you get the same error if you run the code above in a fresh R session with no other models loaded in?

Also, can you post the output from the following:

devtools::session_info("rstan")
1 Like

Strangely enough, clearing out all of the other models did the trick. Also, it seems that knitting the whole markdown code is better than running the analysis one chunk at a time. Mysterious. Thanks!

David