I’m writing an R package that relies on Rstan and plan to put it on CRAN once an accompanying article has been published. I want use some functionality from Stan 2.36 (sum-to-zero-vectors), but CRAN is still at Rstan version 2.32.7.
I’m using a development version of Rstan at the moment, but I’m wondering when a newer version of Rstan (>= 2.36) might be available on CRAN?
Unfortunately, I believe there is still a long list of downstream packages on CRAN that need code changes before RStan could update to a more recent version. There is a list here, though it has not been updated in some time
For your specific use case, you may be able to use the following function, which implements the same mathematical transform that Stan does internally. It will not have the benefit of specialized autodiff, but the geometric improvements should be the same:
/**
* Constrain sum-to-zero vector
*
* @param y unconstrained zero-sum parameters
* @return vector z, the vector whose elements sum to zero
*/
vector zero_sum_constrain(vector y) {
int N = num_elements(y);
vector[N + 1] z = zeros_vector(N + 1);
real sum_w = 0;
for (ii in 1:N) {
int i = N - ii + 1;
real n = i;
real w = y[i] * inv_sqrt(n * (n + 1));
sum_w += w;
z[i] += sum_w;
z[i + 1] -= w * n;
}
return z;
}
If you want to stick with rstan then I think @WardBrian’s suggestion is the way to go. However, if you want to actually use the latest Stan version you could switch to using our cmdstanr interface. Even though it’s not on cran you can still submit packages that use it to cran. @wlandau has a really helpful package to make this easier: