0

So I have a rjags model given below. My problem is that when I want to run jags.model(), it sometimes compiles sometimes it does not. So I could literally run the jags.model() function and no error occurs when I immediately rerun the same jags.model() with the same parameters and nothing changes I suddenly get the error message:

Error in update.jags(object, n.iter, ...) : 
Error in node ((beta[2]/x1[5])^0.9)
Invalid parent values

I really have no idea how that can happen is there something wrong with my workspace? Below are my input and my model.

    bayesnlm = "
model {

for (i in 1:length(y)) {

y[i] ~ dnorm(mu[i], tau)

mu[i] <- beta[3] + beta[4] * (x2[i]) +
beta[1] *(0.9/beta[2])*(beta[2]/x1[i])^1.9*exp((-(beta[2]/x1[i])^0.9))


residual[i] <- y[i] - mu[i]


}


# Define Prior distribution 

beta[1:4] ~ dmnorm.vcov(mu.p[1:4], Sigma[1:4,1:4])


tau ~ dgamma(1.0E-3, 1.0E-3)
} 
"

My input data looks like this:

$`x1`
[1]  14  75 258  26  70

$x2
[1]  14  75 258 815 859

$y
[1]  0.2091645  1.7007476 -0.2880298 -0.2880298  0.7063589

$Sigma
              [,1]          [,2]          [,3]          [,4]
[1,]  2.479069e+04  3.717394e+03 -1.940021e+01  5.853116e-03
[2,]  3.717394e+03  1.245803e+03  3.743637e+00 -1.778376e-03
[3,] -1.940021e+01  3.743637e+00  3.006899e-01 -1.496941e-04
[4,]  5.853116e-03 -1.778376e-03 -1.496941e-04  9.027231e-08

$mu.p
[1]  5.445813e+02  1.343918e+02 -5.689060e-01 -1.070608e-04

Here you can copy and paste it:

    list(x1 = c(14, 75, 258, 26, 70), x2 = c(14, 75, 258, 815, 859
), y = c(0.20916452356296, 1.70074760142997, -0.288029835726044, 
-0.288029835726044, 0.706358882851964), Sigma = structure(c(24790.6941908131, 
3717.39378904953, -19.400211288343, 0.00585311596063579, 3717.39378904953, 
1245.80270600402, 3.74363729374668, -0.00177837577140645, -19.400211288343, 
3.74363729374668, 0.300689871287482, -0.000149694071017865, 0.00585311596063579, 
-0.00177837577140645, -0.000149694071017865, 9.02723134020887e-08
), .Dim = c(4L, 4L)), mu.p = c(544.581343592283, 134.391793200685, 
-0.568905977830338, -0.000107060840574308))
duckmayr
  • 16,303
  • 3
  • 35
  • 53
Janosch
  • 356
  • 2
  • 13
  • 1
    You may want to check out [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In particular, can you edit your question to provide the list of input data as the output from `dput()`? – duckmayr Feb 23 '19 at 17:13
  • 1
    I would guess the problem is that your prior allows for negative values of `beta[2]`, but when `beta[2] < 0`, then `((beta[2]/x1[5])^0.9)` is not a real number. – duckmayr Feb 23 '19 at 17:22
  • Oh yeah true I completely overlooked that. Is there a way to constrain the priors within a multivariate normal? – Janosch Feb 23 '19 at 17:48
  • Not to my knowledge. Typically in JAGS you truncate a prior to only allow positive values using `T(0,)` (See Section 7.1 of [the user manual](http://people.stat.sc.edu/hansont/stat740/jags_user_manual.pdf)), but this doesn't work for multivariate distributions. I have seen [this workaround](https://sourceforge.net/p/mcmc-jags/discussion/610037/thread/9472caff/) for a bivariate normal, which you may be able to adapt to suit your needs. – duckmayr Feb 23 '19 at 18:01

0 Answers0