I’m using Turing to fit a model, where every data point is a pair (S,L), as we describe in the following paper: Revisiting the links-species scaling relationship in food webs | bioRxiv
In practice, we do not use L to fit the model, but L-(S-1), and I have not been able to use this directly from within Turing - what I had to do was create a variable (equal to L.-(S.-1)) and then call the model on this.
The model is as follows:
@model flexible_links(s,f) = begin
N = length(s)
# Transformed data
F = (s.*s) .- (s .- 1.0)
# Parameters
ϕ ~ Normal(3.0, 0.5)
μ ~ Beta(3.0, 7.0)
for i in 1:N
f[i] ~ BetaBinomial(F[i], μ*exp(ϕ), (1-μ)*exp(ϕ))
end
return μ, ϕ
end
What I would like to write instead would look something like this:
@model flexible_links(s,l) = begin
N = length(s)
# Transformed data
f = [l[i]-(s[i]-1) for i in 1:N]
F = (s.*s) .- (s .- 1.0)
# Parameters
ϕ ~ Normal(3.0, 0.5)
μ ~ Beta(3.0, 7.0)
for i in 1:N
f[i] ~ BetaBinomial(F[i], μ*exp(ϕ), (1-μ)*exp(ϕ))
end
return μ, ϕ
end
But it does not work, because f is of the wrong type - I’d appreciate any points as to where I should be looking to solve the problem.