# Considering switch to Julia -- modelling examples linked to R / comparison to Stan / production environment

**URL:** <https://discourse.julialang.org/t/considering-switch-to-julia-modelling-examples-linked-to-r-comparison-to-stan-production-environment/62428>\
**Category:** New to Julia\
**Created:** [June 5, 2021, 11:26am UTC](https://discourse.julialang.org/t/considering-switch-to-julia-modelling-examples-linked-to-r-comparison-to-stan-production-environment/62428 "2021-06-05T11:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CharlesDriver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charlesdriver/32/21125_2.png) [@CharlesDriver](https://discourse.julialang.org/u/CharlesDriver)\
**Post date:** [June 5, 2021, 11:26am UTC](https://discourse.julialang.org/t/considering-switch-to-julia-modelling-examples-linked-to-r-comparison-to-stan-production-environment/62428/1 "2021-06-05T11:26:15Z")

</div>

I maintain R software for hierarchical sde / state space modelling, oriented to social science contexts, and am also in the process of constructing something for large scale item response models. At present I have models coded in Stan (for fast gradients) and interface via R. Stan does some nice things but is a pretty inflexible from a dev point of view and too connected to it’s HMC approach, requiring a bunch of hacks for parallelism / optimization etc. Updating of the R connection also seems largely stopped. Julia looks like a fantastic way of unifying things for me, but at least for some time I would be interested in trying it just as a replacement for the computational side of things, and still use the current R front ends I have. I’m also interested in the prospect of using models coded in Julia as a replacement for c++ in some online software, where small jobs would be called from other software with fairly high frequency. Some queries:  
Does this (or some of this) seem sensible? Is the R link mature / stable enough for this kind of thing? How does Julia compare to Stan in terms of computational performance (i.e. compute time / accuracy of an autodiff’d log gradient) for fairly complex models? Any recent comparisons available? Any examples available that roughly match what I want to do? Is anyone bored / enthusiastic enough to hold my hand with random question answering if I dive in to this, or does someone capable want a few hours consulting / tutoring work? Thanks for any guidance!

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [June 5, 2021, 11:42am UTC](https://discourse.julialang.org/t/considering-switch-to-julia-modelling-examples-linked-to-r-comparison-to-stan-production-environment/62428/2 "2021-06-05T11:42:18Z")

</div>

If you haven’t seen it, I’d recomend taking a look at [GPU-Accelerated ODE Solving in R with Julia, the Language of Libraries](https://www.stochasticlifestyle.com/gpu-accelerated-ode-solving-in-r-with-julia-the-language-of-libraries/), which gives an example of calling Julia from R (also bringing up the objective to make it as ergonomic as Rcpp).

[This paper](https://arxiv.org/pdf/2002.02702.pdf) has some benchmarks comparing [Turing](https://github.com/TuringLang/Turing.jl) to Stan for HMC sampling.

Julia will be more flexible / allow you to tune things more easily when performance is a concern, e.g. defining custom adjoints.  
There are a lot of AD options, but [ForwardDiff](https://github.com/JuliaDiff/ForwardDiff.jl) and [Zygote](https://github.com/FluxML/Zygote.jl) are the most mature for forward and reverse mode, respectively.  
Diffractor is a promising library on the horizon that will offer mixed mode as well as efficient high order AD (which Zygote fails at, for example).
