I am struggling with this error for modeling latent variables using Turing
MethodError: no method matching Normal(::Array{Float64,1}, ::Float64)
My data generation code is
using Distributions
using Statistics, LinearAlgebra
#using VegaDatasets
using Turing, TuringModels
function SEM_b(N_ID, NY)
#loading matrix 2*6
ld2 = [1 .71 .69 0 0 0;
0 0 0 1 .35 1.5]
cov2 = Matrix(1.0I,2,2)
eta2 = MvNormal([0; 0],cov2)
eta2b = rand(eta2, N_ID) #2*N matrix
eps2 = MvNormal(fill(0, NY),diagm(ones(NY)))
eps2b = rand(eps2, N_ID) #NY*N_ID matrix
Y2 = transpose(eta2b)*ld2 + transpose(eps2b)
transpose(eta2b), transpose(eps2b), Y2
end
and my Turing code is
@model MM_SEM(Y, N_eta) = begin
ll,rr = size(Y)
μ = Array{Float64,2}(undef,ll,rr)
λ ~ filldist(Normal(0,5),4)
η_σ ~ filldist(truncated(Normal(0,5),0,Inf),N_eta)
σ ~ filldist(truncated(Normal(0,5),0,Inf),rr)
η_ρ ~ LKJ(N_eta,1.)
L = η_σ .* η_ρ .* η_σ'
L = (L' + L)/2
eta ~ filldist(MvNormal(fill(0,N_eta), L),ll)
μ[:,1] = eta[1,:]
μ[:,2] = λ[1]*eta[1,:]
μ[:,3] = λ[2]*eta[1,:]
μ[:,4] = eta[2,:]
μ[:,5] = λ[3]*eta[2,:]
μ[:,6] = λ[4]*eta[2,:]
for j in 1:rr
Y[:,j] ~ Normal(μ[:,j],σ[j])
end
#for i ∈ 1:ll
#μ[i,1] = eta[1,i]
#μ[i,2] = λ[1]*eta[1,i]
#μ[i,3] = λ[2]*eta[1,i]
#μ[i,4] = eta[2,i]
#μ[i,5] = λ[3]*eta[2,i]
#μ[i,6] = λ[4]*eta[2,i]
#for j in 1:rr
# Y[i,j] ~ Normal(μ[i,j],σ[j])
#end
#end
end
and
chain = sample(MM_SEM(a[3],2), NUTS(0.95), 1000);