Hello,
I’m trying to estimate some parameters from the data, but I came across a bug that I don’t know how to deal with.
This piece of code alone may look stupid (especially, using this multiplier), but it’s an isolated part of a more complicated model, that has the same issue. For some reason, estimation of the transformed variable R
fails because of the lower bound I set to it. R
values shouldn’t get as low as 0, but in case they happen to be negative, I want to discard them by setting this lower bound.
R_data = c(0.22, 0.23, 0.26, 0.27, 0.3, 0.34, 0.13, 0.14, 0.21, 0.23,
0.29, 0.31, 0.18, 0.19, 0.27, 0.27, 0.33, 0.36, 0.31, 0.35, 0.38,
0.39, 0.41, 0.48)
N = length(R_data)
modelstring = "
data {
int N;
vector[N] R_data;
}
parameters {
vector[N] R_multiplier;
}
transformed parameters {
vector<lower=0>[N] R;
R = R_multiplier .* R_data;
}
model {
R_multiplier ~ normal(1, 0.25);
}
"
m = stan(model_code = modelstring2, data = list(N=N, R_data=R_data), seed = 1234)
And this is the error I’m getting.
...
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: validate transformed params: R[2] is -0.41672, but must be greater than or equal to 0 (in 'model8e4e69b72ec7_3d89a0a08343181c3029026d11b0b9ba' at line 10)
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
which is unexpected, since if I remove the lower bound (change vector<lower=0>[N] R;
to vector[N] R;
in the transformed parameters
section), I get the values for R that almost never gets lower than 0 (well, maybe some initial values can get down to -2, but not in 100 attempts in a row).
Could you please explain me why is it happening?
Thank you in advance,
Evgeny