Error with uniform_rng

I have the following function defined in my stan

functions {
  real weibull_trunc_rng(real alpha, real sigma, real lb){// function to generate truncated weibull; 
    real lp = weibull_cdf(lb, alpha, sigma);
    real u = uniform_rng(lp, 1);
    real y = sigma * (-log1m(u))^inv(alpha);
    return y;
    }
}

but I am getting the following error message:
[1] “Error in sampler$call_sampler(args_list[[i]]) : "
[2] " Exception: Exception: uniform_rng: Upper bound parameter is 1, but must be greater than 1 (in ‘model5efd3f9032ef_evt_pred_weibull’ at line 10)”
[3] " (in ‘model5efd3f9032ef_evt_pred_weibull’ at line 75)"

what is causing this?

I’m guessing this means “but must be greater than [lower bound].” If the lower bound is 1 then there’s no room for randomness.
Try this:

functions {
  real weibull_trunc_rng(real alpha, real sigma, real lb){// function to generate truncated weibull; 
    real lp = weibull_cdf(lb, alpha, sigma);
    real u = (lp < 1) ? uniform_rng(lp, 1) : 1 ;
    real y = sigma * (-log1m(u))^inv(alpha);
    return y;
    }
}
1 Like

Thanks a lot! This solves the problem.

1 Like