Is it possible to use the draw of one random variable as the bound for another one? In my example, I have a simple linear relationship with x-values in the interval [0,1] and I want to bound the resulting y-value to be positive.
I have tried to use the first variable as the bound for the second one, yet that does not work (see the MWE below).
I already saw this discussion, which is sadly only about the parameters of the distribution and not the values to truncate on.
Is this even possible, if yes how? Thanks a lot for any kind of help!
MWE:
a = 0:.05:1
b = 2 .- 1.5 * a + randn(21)
@model function truncate_mwe(x, y)
intercept ~ truncated(Normal(0, 1), 0, Inf)
slope ~ truncated(Normal(0, 1), -intercept, Inf)
for i in eachindex(y)
y[i] ~ Normal(intercept + slope * x[i], 1)
end
end
chain_mwe = sample(truncate_mwe(a,b), NUTS(), 1000)
# for me this chain always has some samples,
# for which intercept + slope < 0
For anyone who might stumble upon this in the future, I found help in a GitHub issue (which also links many other relevant sources).
The TLDR is that it works now, you just have to set the upper and lower kwargs (and update your packages).