# Learning Rstan for beginners

**URL:** <https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368>\
**Category:** Modeling\
**Created:** [June 4, 2024, 9:12pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368 "2024-06-04T21:12:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwndirangu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jwndirangu/32/18707_2.png) [@jwndirangu](https://discourse.mc-stan.org/u/jwndirangu)\
**Post date:** [June 4, 2024, 9:12pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/1 "2024-06-04T21:12:27Z")

</div>

I am looking for a mentor/trainer for Rstan. I am interested in multi population stochastic epidemic models. Are there Rstan training sessions, classes or something I can rely on?

Is the manual enough for these complex models?

---

<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:** [June 7, 2024, 10:38am UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/2 "2024-06-07T10:38:39Z")

</div>

If you want to hire someone, you might try posting int he Jobs category.

If there’s a specific model you want to start with, I would suggest posting a query about it here with an informative title about the model so the right people read it.

I’m not sure what you mean by “multi-population” or “stochastic” epidemic models. Most Bayesian models are stochastic to some extent. And we often stratify the population by demographic factors in order to do post stratification for estimating population prevalence, if that’s what you mean. Are the different populations different age groups, groups in different localities, or what? Any population of people is technically a subpopulation of the global population, though we often reason about superpopulations in Stan (e.g., reasoning about the next marginal person rather than just trying to reason about the actual population right now).

There are several hundred published papers on Covid modeling using Stan—you could always start by looking at some of those. There are also a lot of Stan case studies out there, including many for epidemics (I worked with the UK Biosecurity Centre through Covid and we built a bunch of spatiotemporal models subdivided by local authority and post stratified by demographics). We’ve published things about different populations of viruses (e.g., monitoring omicron taking over), and different subpopulations of the British population using demographic and spatial information.

P.S. Unless you need something specifically from RStan, you might want to try cmdstanr—it’s simpler in many ways, more up to date with Stan itself, and easier to install. (The reason Stan gets out of date is because of CRAN’s antiquated size policies (max 1MB), platform requirements (does anyone remember Sparc?), and no dependency management for releases—together these are just ridiculous.

---

<div class="post-metadata">

**Author:** ![jwndirangu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jwndirangu/32/18707_2.png) [@jwndirangu](https://discourse.mc-stan.org/u/jwndirangu)\
**Post date:** [June 13, 2024, 9:11am UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/3 "2024-06-13T09:11:16Z")

</div>

Dear Bob,  
I have started working in Rstan this April, I have tried working with simple SIR models so that I can implement it in my SEIR two interacting population model. The problem is experience especially in Rstan. I need somebody to share my code with for guidance if I am doing the correct thing. Since the model is for publication, I didn’t want to share it int he public forum.  
I would appreciate any reference Stan code especially what you did on Omicron in subpopulations.

I do appreciate your explanation. where can I get your artcles?  
Josephine

---

<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:** [July 19, 2024, 9:55pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/4 "2024-07-19T21:55:24Z")

</div>

> [@jwndirangu](#):
>
> Since the model is for publication, I didn’t want to share it in the public forum.

Without details, it’s hard to help. I do find that biologists tend to be more secretive than other scientists. I just do all of my work in open GitHub repos whenever my co-authors are willing.

> **[Replacement dynamics and the pathogenesis of the Alpha, Delta and Omicron...](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9990386/)**
>
> New SARS-CoV-2 variants causing COVID-19 are a major risk to public health worldwide due to the potential for phenotypic change and increases in pathogenicity, transmissibility and/or vaccine escape. Recognising signatures of new variants in terms of...

But this probably isn’t what you’re looking for. This work is very simple and not S(E)IR based.

---

<div class="post-metadata">

**Author:** ![jwndirangu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jwndirangu/32/18707_2.png) [@jwndirangu](https://discourse.mc-stan.org/u/jwndirangu)\
**Post date:** [July 19, 2024, 10:03pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/5 "2024-07-19T22:03:57Z")

</div>

I am a mathematician not Biologist, maybe some unfounded fears. I will send my model for yout help.

Thanks

---

<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:** [July 22, 2024, 8:51pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/6 "2024-07-22T20:51:18Z")

</div>

If you want to study SIR models in Stan, you can check out this tutorial:

[https://mc-stan.org/users/documentation/case-studies/boarding\_school\_case\_study.html](https://mc-stan.org/users/documentation/case-studies/boarding_school_case_study.html)

The SARS variant work was just trying to estimate prevalence over time of the different variants.

---

<div class="post-metadata">

**Author:** ![jwndirangu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jwndirangu/32/18707_2.png) [@jwndirangu](https://discourse.mc-stan.org/u/jwndirangu)\
**Post date:** [July 22, 2024, 9:19pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/7 "2024-07-22T21:19:42Z")

</div>

Yes this is my best reference,

See what I did trying to correct the method they used, using dynamical survival analysis.

I want to capture the bimodal infection pattern, you could help me get this kind of a distribution.

Thanks so much for the Leo paper.

> **(attachments)**
>
> [DSA\_flu\_script.R](https://discourse.mc-stan.org/uploads/short-url/qo5Q1hasgmsg2blIzkgluBqTKnW.R) (3.59 KB)  
> [DSA\_flu.stan](https://discourse.mc-stan.org/uploads/short-url/wyJmcPAvTFFYHfOem8VjFmjDPk.stan) (2.21 KB)  
> [DSA\_flu\_init.R](https://discourse.mc-stan.org/uploads/short-url/p3ZlpM1WDQel4ZZc6GUWY7batbt.R) (958 Bytes)  
> [DSA\_flu\_plot.R](https://discourse.mc-stan.org/uploads/short-url/5uM6gRf2hkXhKtSNPgsh5NeSeJZ.R) (1.4 KB)  
> [flu\_data.csv](https://discourse.mc-stan.org/uploads/short-url/wdQmqkFPcA7lAmY7OQd2aSAXkiw.csv) (316 Bytes)

---

<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:** [July 22, 2024, 9:31pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/8 "2024-07-22T21:31:54Z")

</div>

I’m not an expert in these models. @charlesm93 is your best bet—if you’re at ICML, you can catch him in person :-).

---

<div class="post-metadata">

**Author:** ![jwndirangu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jwndirangu/32/18707_2.png) [@jwndirangu](https://discourse.mc-stan.org/u/jwndirangu)\
**Post date:** [July 22, 2024, 9:38pm UTC](https://discourse.mc-stan.org/t/learning-rstan-for-beginners/35368/9 "2024-07-22T21:38:59Z")

</div>

Hello,

I get you. Let me look for him.

Thanks again.
