extract underlying STAN model code

618 views
Skip to first unread message

Martin

unread,
Feb 10, 2016, 2:33:57 AM2/10/16
to Stan users mailing list
Hi,

I could not find this in the documentation, is it possible to extract the underlying STAN model, for example like this

mod <- stan_glm(y~x, dat)

extract(mod)

to get the STAN code from my model (as a string maybe) ? 

thanks

Jonah Gabry

unread,
Feb 10, 2016, 9:18:48 AM2/10/16
to stan-...@googlegroups.com
You can get the Stan code using 

stancode <- rstan::get_stancode(mod$stanfit)
cat
(stancode)

or by doing 

launch_shinystan(mod)

and clicking on More and then Model Code. 

However, the Stan code for stan_glm (and the other modeling functions) is long and complicated because it is flexible enough to be used for all the different model formulas, priors, other options, specified by the user. So it won't look like a simple Stan model for a glm, but I guess it could be helpful to you if you're interested in some of the tricks for numerical stability, speed, etc, that we've used. If you have any questions about it let us know!

Hope that helps, 

Jonah

Martin

unread,
Feb 10, 2016, 10:05:04 AM2/10/16
to Stan users mailing list
thanks Jonah. I really love this package, great work

Am Mittwoch, 10. Februar 2016 15:18:48 UTC+1 schrieb Jonah Gabry:
Hi Martin, 

Jonah Sol Gabry

unread,
Feb 10, 2016, 10:14:56 AM2/10/16
to stan-...@googlegroups.com
Thanks, glad you like it! We'll be releasing an update with some bug fixes and a few additions very soon, so keep an eye out for that. 

Jonah
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/5tiWRmx1V8o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages