flatironinstitute / stan-playground

Run Stan models in the browser
Apache License 2.0
36 stars 1 forks source link

Possiblility of generating the stan code from R #202

Open WardBrian opened 3 months ago

WardBrian commented 3 months ago

The primary use case of this would be to support brms. This supports a make_stancode and make_standata functions which are paired together.

Related to #139, with the same questions about whether or not it belongs in the same scripts.

There is not really an equivalent need/desire for this in Python

WardBrian commented 2 months ago

This was requested at StanCon by @wds15

@paul-buerkner mentioned that some additional changes in BRMS would be necessary if we wanted to be able to take advantage of all the cool downstream stuff BRMS enables for its models, so this issue can also serve as a place to discuss if anything would be needed on our end

WardBrian commented 3 weeks ago

For basic uses, it looks like this is already possible, e.g.:

install.packages('brms')
library(brms)
make_stancode(rating ~ treat + period + carry + (1|subject),
         data = inhaler, family = "cumulative")

data <- make_standata(rating ~ treat + period + carry + (1|subject),
         data = inhaler, family = "cumulative")

in the data generation window will set the data and print the Stan code, which you can copy over yourself. A bit clunky, and missing all of brms' niceties around PPC, etc