Hoping to get some help understanding the source of this zero probability error. My model is relatively straightforward after understanding the purpose of my user-defined function.
findx() takes two variable values (1) context which is an integer 1-16 which selects one of my empirically extracted distributions (implemented as piecewise linear functions (plfs) and (2) theta which is a cumulative density threshold between 0 and 1 and outputs a cardinal x-value associated with the location of the cumulative density threshold on the plf density curve.
I’ve tried to debug with print statements in various places but haven’t been able to find the source of my issue. I have also included a standump file below with the data I am feeding into the model.
Thank you in advance to anyone who is able to help.
gtmproduction_data.Rdata (7.3 MB)
functions {
real findx (int context, real theta, real[,,] plfs, int rows) {
real plf[rows, 3] = plfs[context,,];
real default_x;
for (row in 1:rows) {
real x = plf[row, 1];
real m = plf[row, 2];
real b = plf[row, 3];
real y = ((m * x) + b);
if (theta <= y) {
return ((theta - b) / m);
}
}
default_x = (theta - plf[rows, 3]) / plf[rows, 2];
return(default_x);
}
}
data {
int<lower=1> numrows;
int<lower=0> N;
int<lower=0> contexts[N, 5];
real<lower=-1, upper=70> plfs[16, numrows, 3];
}
parameters {
real<lower=0, upper=1> theta_few;
real<lower=0, upper=1> theta_many;
vector<lower=0>[16] sigma;
}
model {
theta_few ~ uniform(0, 1);
theta_many ~ uniform(0, 1);
for (c in 1:16) {
sigma[c] ~ gamma(5,3);
}
for (i in 1:N) {
if (contexts[i, 3] == 1) {
contexts[i, 5] ~ bernoulli(normal_cdf(contexts[i,4], findx(contexts[i, 2], theta_many, plfs, numrows), sigma[contexts[i, 2]]));
} else if (contexts[i, 3] == 2) {
contexts[i, 5] ~ bernoulli(1 - (normal_cdf(contexts[i,4], findx(contexts[i, 2], theta_few, plfs, numrows), sigma[contexts[i, 2]])));
}
}
}