Cannot find special function lambert_w0

Hi,

I’m unable to find the special function lambert_w0 in my pystan/rstan program.

See doc and stan math pr.

I’m assuming here that stan-math functions should just eventually appear for use in rstan/pystan; though this might not be well-founded.

functions
{
    int signum(real y)
    {
        return y > 0 ? 1 : -1;
    }
}
data
{
    int N;
    real y[N];
}
parameters
{
    real<lower=0> d;
}
transformed parameters
{
    real z;
    z = sign(y) * lambert_w0(d * y^2) / d; // doesn't work as lambert_w0 not found
}
model
{
    d ~ gamma(1, 2);
    z ~ normal(0, 1);
    // todo jacobian adjustment since i'm putting a prior on a transformed parameter
}

I get a compile error and also

> rstan::lookup('rep')
      StanFunction       Arguments ReturnType
579 rep_row_vector (real x, int n) row_vector
580     rep_vector (real x, int m)     vector
> rstan::lookup('lambert')
[1] "no matching Stan functions"

The current CRAN rstan is a few versions behind, and so doesn’t have the function available.

Try the preview of the next rstan version, restart R (making sure that rstan doesn’t get loaded) and run:

remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
2 Likes