I’m trying to fit a translated / 3-parameter Weibull (see here: https://en.wikipedia.org/wiki/Weibull_distribution#Related_distributions), but I’ve never coded a PDF in Stan. I can get it to run, but getting it to mix is another issue.
The challenge with this distribution is that the observed values always have to be greater than the location (i.e. x >= theta on the Wikipedia page). This is problematic because it implies a vector-valued constraint. I’ve come up with what I think is a fairly clumsy solution, so any advice on how to improve this would be most gratefully received!
> foo_model <- "
> data{
> int<lower=0> N;
> int<lower=0> Nsites;
> real<lower=0> y[N];
> int site[N];
> }
> parameters{
> real<lower=0> scale[Nsites];
> real<lower=0> shape;
> real int_mean;
> real int_by_site[Nsites];
> real<lower=0> int_by_site_sd;
> }
> transformed parameters{
> vector[N] mu;
> for (i in 1:N)
> mu[i] = int_mean + int_by_site_sd*int_by_site[site[i]];
> }
> model{
> shape ~ normal(0,1);
> scale ~ normal(0,1);
> int_mean ~ normal(0,1);
> int_by_site ~ normal(0,1);
> int_by_site_sd ~ normal(0,1);
> for (i in 1:N){
> if (y[i] < mu[i])
> target += negative_infinity();
> else
> target += log(shape/scale[site[i]]) + (shape-1)*log((y[i]-mu[i])/scale[site[i]]) - pow((y[i]-mu[i])/scale[site[i]],shape);
> }
> }
> "