Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRMS tutorial: add rstan example #346

Merged
merged 14 commits into from
Dec 6, 2024
Merged

BRMS tutorial: add rstan example #346

merged 14 commits into from
Dec 6, 2024

Conversation

falkmielke
Copy link
Contributor

@falkmielke falkmielke commented Nov 22, 2024

Description

This PR adds an example of rstan usage with a raw Stan model to the existing brms tutorial.
I also rearranged that tutorial a bit (separate section for data).

I was able to test the Rmd code, all runs as intended. However, I did not knit or publish any of this to html, the structure and publication procedure of this repo seem too sophisticated for me (though great that it is based on hugo ssg!). I hope it will not crash GHA.

Thank you in advance for review and suggestions!

Task list

  • My tutorial or article is placed in a subfolder of tutorials/content
  • The filename of my tutorial or article is index.md. In case of an Rmarkdown tutorial I have knitted my index.Rmd to index.md (both files are pushed to the repo).
  • I have included tags in the YAML header (see the tags listed in the tutorials website side bar for tags that have been used before)
  • I have added categories to the YAML header and my category tags are from the list of category tags
  • I was not able to compile the tutorial into html files, and would appreciate if you original authors and tutorial maintainers could take over.

Copy link
Contributor

@wlangera wlangera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Falk

Very nice addition.

I checked the Dutch version. I will assume the same comments apply for the English version.
General remarks:

  • Could you keep the term burnin instead of warmup. I like burnin more.
  • Any particular reason you provide the poisson_model.stan file in brms_eng folder and not in the brms_nl folder?
  • I think I would like to put your section ("Deep Dive: rstan") in a separate section between "Vergelijken met frequentist statistics" and "Referenties". I think the use of rstan is quite advanced for the general users in INBO. Therefore, I think it is better that it is not in the middle of our tutorial, but behind it. People get a view of the whole process of bayesian statistisc (in brms), and if they want (or if they heard about stan somewhere and want to look into it), they can progress further to your section. What do you think?

Het relatieve gebruiksgemak gaat echter ten koste van de flexibiliteit en in zekere mate de leesbaarheid.

Stan en `rstan` daarentegen leunen meer op de wiskundige formulering van modellen.
Elk aspect van het model moet expliciet worden ingesteld, wat een voordeel kan zijn (bijvoorbeeld als u te maken hebt met niet-standaard use cases) of een nadeel (bijvoorbeeld als u modellen op niet-optionele manieren beveiligt).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wat bedoel je met "een model beveiligen"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a translation fault of a faulty English sentence, which on top of that I overlooked in proofreading. My apologies! It is corrected.


Sampling doet vrijwel hetzelfde als hierboven, want in de kern is `brms` gewoon `stan`.

```{r stan_sampling}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik zou hier ook zelf een burn-in gebruiken zoals we in de brms-voorbeelden hebben gedaan. Dan is het nog meer gelijkaardig als hierboven.

Copy link
Contributor Author

@falkmielke falkmielke Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out, @wlangera !
I briefly asked @hansvancalster and googled "burn-in tuning warmup Bayesian stats". There is a to-the-point discussion here. My notion of changing came from the fact that we don't physically "burn" or "burn in" anything; thus I was surprised that apparently the term was considered appropriate for some MCMC algorithms. "Tuning", my actual favorite 🤘, is reserved for a certain sub-part of the warm-up phase (Merci, Hans!).

Anyways, the experts seem to prefer "warm-up", and if you agree and confirm, I will in turn adjust this throughout the tutorial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that sounds good. Thanks

@wlangera
Copy link
Contributor

From looking at the content/tutorials/r_brms/index.md file, I think that the html's should be rendered locally and commited to the repo in this folder.

falkmielke and others added 5 commits November 26, 2024 07:31
Co-authored-by: Ward Langeraert <60934857+wlangera@users.noreply.github.com>
Co-authored-by: Ward Langeraert <60934857+wlangera@users.noreply.github.com>
Co-authored-by: Ward Langeraert <60934857+wlangera@users.noreply.github.com>
Co-authored-by: Ward Langeraert <60934857+wlangera@users.noreply.github.com>
Co-authored-by: Ward Langeraert <60934857+wlangera@users.noreply.github.com>
@falkmielke
Copy link
Contributor Author

From looking at the content/tutorials/r_brms/index.md file, I think that the html's should be rendered locally and commited to the repo in this folder.

Thanks, I will try that, and we see where checks lead us.

@falkmielke
Copy link
Contributor Author

  • Any particular reason you provide the poisson_model.stan file in brms_eng folder and not in the brms_nl folder?

Good point; I was thinking about git / data redundancy.
Thinking one step further:

  • should they rather be in the [...]/html folder, close to what people actually read?
  • ... or shouldn't they best be in a top level /data folder, or in /inst, to be generally accessible?
    Thank you for advice @wlangera @hansvancalster ! I will move the file and adjust links.

@hansvancalster
Copy link
Contributor

  • Any particular reason you provide the poisson_model.stan file in brms_eng folder and not in the brms_nl folder?

Good point; I was thinking about git / data redundancy. Thinking one step further:

  • should they rather be in the [...]/html folder, close to what people actually read?
  • ... or shouldn't they best be in a top level /data folder, or in /inst, to be generally accessible?
    Thank you for advice @wlangera @hansvancalster ! I will move the file and adjust links.

I would put it in the base folder of your tutorial: content/tutorials/r_brms/ or equally fine in a subfolder of that: content/tutorials/r_brms/<subfolder>. The name for the <subfolder> perhaps model, model_files, stan, stan_files or ...?

@falkmielke
Copy link
Contributor Author

I incorporated the change suggestions and re-knitted the html reports. This also yielded two image-related issues, here and here.

  • the cmdstanr package is explicitly mentioned (suggestion by @hansvancalster )
  • general code files are now in a general folder
  • knit with low res images

Thank you for re-checking and publishing!

Copy link
Contributor

@wlangera wlangera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Falk, I have send you the images via mail.

Thanks for the changes

@falkmielke falkmielke merged commit 8c46fb7 into master Dec 6, 2024
1 check passed
@falkmielke falkmielke deleted the rstan branch December 6, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants