I’m just starting to get to grips with Turing, and enjoying it very much so far. But I’ve run up against a problem with a bivariate normal prior.
using Turing, StatsPlots
@model function pearson_correlation(x)
rows = size(x, 1)
# priors
μ = Vector(undef, 2)
μ[1] ~ Normal(0, 100)
μ[2] ~ Normal(0, 100)
σ₁ ~ Uniform(0, 100)
σ₂ ~ Uniform(0, 100)
r ~ Uniform(-1, 1)
# covariance matrix
Σ = [σ₁ r*σ₁*σ₂;
r*σ₁*σ₂ σ₁]
# likelihood. Loop over observations (rows)
for i = 1:rows
x[i,:] ~ MvNormal(μ, Σ)
end
end
x = [0.8 102; 1 98; 0.5 100; 0.9 105; 0.7 103; 0.4 110; 1.2 99; 1.4 87; 0.6 113; 1.1 89; 1.3 93]
chain = sample(pearson_correlation(x), HMC(0.05, 10), 1000)
density(chain[:r])
I’m getting an error relating to x[i,:] ~ MvNormal(μ, Σ)
… From the docs I’m not sure you can define a covariance matrix like this? Any pointers on how to fix this would be much appreciated.