# Error in prep\_call\_sampler(object)

**URL:** <https://discourse.mc-stan.org/t/error-in-prep-call-sampler-object/18343>\
**Category:** General\
**Created:** [October 1, 2020, 10:41pm UTC](https://discourse.mc-stan.org/t/error-in-prep-call-sampler-object/18343 "2020-10-01T22:41:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [October 1, 2020, 10:41pm UTC](https://discourse.mc-stan.org/t/error-in-prep-call-sampler-object/18343/1 "2020-10-01T22:41:54Z")

</div>

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 + beta1_age[i] + beta2_male[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 + beta1_age[i] + beta2_male[i]);  
log\_lik[i] = bernoulli\_logit\_lpmf(chd[i] | alpha + beta1_age[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
````

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [October 2, 2020, 12:17am UTC](https://discourse.mc-stan.org/t/error-in-prep-call-sampler-object/18343/2 "2020-10-02T00:17:12Z")

</div>

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")

```

---

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [October 2, 2020, 1:49am UTC](https://discourse.mc-stan.org/t/error-in-prep-call-sampler-object/18343/3 "2020-10-02T01:49:43Z")

</div>

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
