Hello,
I just started learning Stan so forgive me if this is asinine but I wrote the following program to model a stick-breaking process:
data {
int<lower=0> N;
int<lower=0> M;
real<lower=0, upper=1> y[N,M];
}
parameters {
real<lower=0> a;
real<lower=0, upper=1> b[N,M];
}
transformed parameters {
real<lower=0, upper=1> B[N,M];
B = b;
for (i in 1:N)
for (j in 1:M)
for (k in 1:j-1)
B[i,j] *= 1 - b[i,k];
}
model {
for (i in 1:N)
b[i] ~ beta(1, a);
for (i in 1:N)
for (j in 1:M)
y[i,j] - B[i,j] ~ normal(0, 0.001);
}
Originally I simply wanted to write y = B;
in the model section but I realized that wasn’t allowed so I instead constrained their difference with a very tight normal. It works pretty well but I can’t help but feel this is some kind of hack.
I’m also getting the following warning from the compiler, further contributing to my sense of unease:
Warning (non-fatal):
Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
If it does, you need to include a target += statement with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
(y[i, j] - B[i, j]) ~ normal(...)
Here is a link to the Mathematica notebook file with all of my results and reports from the sampler:
https://drive.google.com/open?id=1kasphL57WAFAwIikaH-C4SCaiQNMC81E
Thanks for any input.
-Marcos