# A hard modeling problem using Bayesian inference

**URL:** <https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686>\
**Category:** Modeling\
**Created:** [May 29, 2017, 6:36am UTC](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686 "2017-05-29T06:36:56Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [May 30, 2017, 4:37pm UTC](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686/21 "2017-05-30T16:37:45Z")

</div>

You need to actually _read_ the error messages. The error message says `yT` is not found and that’s what’s going on. Start from the assumption that the error message is right and figure out why you’re getting it. We don’t have a lot of time to debug user programs step by step.

---

<div class="post-metadata">

**Author:** ![ghjk](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@ghjk](https://discourse.mc-stan.org/u/ghjk)\
**Post date:** [May 31, 2017, 12:10am UTC](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686/22 "2017-05-31T00:10:07Z")

</div>

I understand the meaning of that error. What I don’t understand is why it requires me to specific `yT` in the R code? I thought we already defined it in Stan, and now we have to define it again?? How could we declare `yT as a variable` in this case though, as I could not see how to do this?

Also, when I switched from `yT = yT` to `yH = yH` in the `datalist(yH=yH,ncol = ncol, nrow=nrow, A=A )` function and ran the code, it was able to execute successfully. However, when I added the two following lines of code (thanks to your link!!), I got the meaningless result: Stan model ‘56827d6b7a762380b4e29186578344f8’ does not contain samples. NULL.

> class(fit)  
> print(names(summary(fit)))

This means the sampling function that I used: `fit <- sampling(ret_sm, warmup=100, iter=600, seed=1, data=list(yH = yH, ncol = ncol, nrow=nrow, A=A`), did not run at all?! Could you please help me fix this error? Why the `number of iterations was set to 600` but the `sampling() function` did not run??

---

<div class="post-metadata">

**Author:** ![ghjk](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@ghjk](https://discourse.mc-stan.org/u/ghjk)\
**Post date:** [May 31, 2017, 3:21am UTC](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686/23 "2017-05-31T03:21:56Z")

</div>

I read it, but what could I do if I tried fixing it, and it never works but just gives me the same error? I thought you would be able to help me with the execution code, Dr. Carpenter;( Sorry for asking you trivial (to you, but not to me) questions…

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ahartikainen/32/321_2.png) [@ahartikainen](https://discourse.mc-stan.org/u/ahartikainen)\
**Post date:** [May 31, 2017, 3:54am UTC](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686/24 "2017-05-31T03:54:07Z")

</div>

Hi,

I assume that you have misunderstood how Stan/RStan works. It is not your normal R module (I come from the python side so the module might not be the correct name here) where you call its functions as any other modules (ggplot2 etc) in R. You should consider Stan as an external program that you send the data through RStan interface and get results back in a container. From this container you can extract your samples and then process them with normal R functions.

So the namespace and the variables defined in Stan are independent of your variables in the R namespace.

I recommend that you familiarize the concepts and the common way of defining models with the Stan manual. Start with something simple and work your way to the more complex models.

[Previous page](https://discourse.mc-stan.org/t/a-hard-modeling-problem-using-bayesian-inference/686.md?page=1)
