I'm trying to fit a basic measurement error model (from Wansbeek and Meijer pg. 191), using a Bayesian latent variable model. The model appear to converge, but on the wrong answer. I've tried all kinds of variations, and can't get it to work. Why?
Here's the setup: We wish to regress y ~ chi. Unfortunately, instead of chi we have x, where x = chi + v, where v is a zero-mean error term. Chi itself is determined in part by W, so we will use W and x to impute chi.
Here's the R code I'm using to generate data:
n <- 1000
alpha <- 2
beta <- 5
W <- runif(n)
v <- runif(n)*5
u <- runif(n)
e <- runif(n)
chi <- W * alpha + u
x <- chi + v
y <- chi * beta + e
Here's the R code I'm using to set up the JAGS model:
jags.data = list("x","y","W","n")
jags.params = c("alpha", "beta", "s_y", "s_x", "s_chi" )#, "chi")
jagsfit <- jags(jags.data, inits=NULL, jags.params,
n.iter=50000, model.file="jags_model_1.txt")
Here's the JAGS model itself:
#jags_model_1.txt
model{
for( i in 1:n ){
y[i] ~ dnorm( chi[i] * beta, s_y )
x[i] ~ dnorm( chi[i], s_x )
chi[i]~ dnorm( W[i] * alpha, s_chi )
}
alpha ~ dnorm( 0, 20 )
beta ~ dnorm( 0, 20 )
s_y ~ dunif(0,20)
s_x ~ dunif(0,20)
s_chi~ dunif(0,20)
}
And here's the kind of output it gives me:
> print(jagsfit)
Inference for Bugs model at "jags_model_1.txt", fit using jags,
3 chains, each with 50000 iterations (first 25000 discarded), n.thin = 25
n.sims = 3000 iterations saved
mu.vect sd.vect 2.5% 25% 50% 75% 97.5% Rhat n.eff
alpha 5.539 0.084 5.378 5.480 5.535 5.595 5.706 1.020 110
beta 2.511 0.035 2.437 2.487 2.511 2.535 2.576 1.030 89
s_chi 1.385 0.077 1.241 1.331 1.386 1.437 1.539 1.010 220
s_x 0.326 0.015 0.297 0.316 0.326 0.336 0.357 1.011 200
s_y 15.711 3.215 8.175 13.651 16.379 18.381 19.859 1.005 540
deviance 4066.079 242.908 3769.635 3887.593 4003.225 4188.925 4703.454 1.004 580
For each parameter, n.eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor (at convergence, Rhat=1).
DIC info (using the rule, pD = var(deviance)/2)
pD = 29419.3 and DIC = 33485.4
DIC is an estimate of expected predictive error (lower deviance is better).
The problem is that the parameter estimates are nowhere near the original values. I've run this simulation several times with different settings (priors, and jags inits) and it's never come close to the true parameters.
What's wrong here?