Here is a generative model I am working on. Think of a game show where your winnings are determined by the product of two RV’s: winningsMultiplier(X) and maxWinnings(Y). We observe winnings w_i = x_i * y. Our prior on y/10^5 ~ Beta(2,8) corresponding to winnings up to $100k, but more likely around $20-$30k. X_i ~ Beta(2,2). Y does not change from observation to observation, but x_i and w_i do.

Here is a pic of the generative DAG:

Anyway, my attempt to code it is below. I get an error after the last line (`ERROR: type UnionAll has no field w`

):

I need two pieces of help for which I would be very appreciative: 1) verify the logic of the implemented math is correct and 2) help me eliminate the error so I can get a posterior for y. Thanks!

```
## simulate some data to see if we can recover params
Random.seed!(1234)
## make y_winnings equal to 35000 for simulation
nObs = 20
dataDF = DataFrame(y_raw = rand(Beta(2,8),nObs),
x = rand(Beta(2,2),nObs))
dataDF.y = 35000 * dataDF.y_raw
dataDF.w = dataDF.x .* dataDF.y
dataDF
## find posterior for y, the max winnings (we know it is 35k)
struct spinProblem{T <: AbstractVector}
w::T # winnings of previous players
end
# https://en.wikipedia.org/wiki/Product_distribution
function (problem::spinProblem)(θ)
@unpack x, y_raw = θ # extract the parameters
@unpack w, = spinProblem # extract the data
# log likelihood accumulated in llSpinProb
# prior
llSpinProb = logpdf(LocationScale(0, 100000, Beta(2,8)),y)
yDraw = 10^5 * y_raw
for i in 1:length(w)
x = w / y
llSpinProb += logpdf(Beta(2,2),x) #data
end
return(llSpinProb)
end
p2 = spinProblem(dataDF.w)
p2((x = 0.5, y_raw = 0.25,)) # gives ERROR
```