I am trying to use the multivariate normal canonical form to draw random
numbers. According to my understanding, the following two functions should
give the same result over a large number of draws, but I am getting
different results. What am I doing wrong.
function ablRegCoeffPostDraw(xtx::Array{Float64, 2}, xty::Array{Float64, 1},
errorVariance::Float64, priorMean::Array{Float64, 1},
priorPrec::Array{Float64, 2})
postPrec=priorPrec+xtx/errorVariance
postMean=priorPrec*priorMean+xty/errorVariance
postMean=postPrec\postMean
rand(MvNormal(postMean, inv(postPrec)))
end
function ablRegCoeffPostDraw1(xtx::Array{Float64, 2}, xty::Array{Float64,
1},
errorVariance::Float64, priorMean::Array{Float64, 1},
priorPrec::Array{Float64, 2})
postPrec=priorPrec+xtx/errorVariance
postMean=priorPrec*priorMean+xty/errorVariance
postMean=postPrec\postMean
potential=postPrec*postMean
rand(MvNormalCanon(potential, postPrec))
end