title: R2WinBUGS error (no prior specified for this initial value)
body: <p>The original WinBUGS code is as follows:</p>
  
  <pre><code>model { for (i in 1:n) {for (j in 1:J) {y[i,j] &lt;- equals(D[i],j)
  D[i] ~ dcat(p[i,])
  p[i,j]  &lt;- phi[i,j] / sum(phi[i,]) 
  LL[i,j] &lt;- y[i,j]*log(p[i,j])}
  for (j in 2:J) {                     
  S.ed[i,j] &lt;-  c1[j]*ed.c[i]+equals(degree,2)*c2[j]*ed.c[i]*ed.c[i]+inprod(delta.c[j,],Spline[i,])
  log(phi[i,j]) &lt;- beta0[j] + beta1[j]*white[i] +  beta2[j]*exp.c[i] + S.ed[i,j]}
  LLt[i] &lt;- sum(LL[i,])
  phi[i,1] &lt;- 1
  H[i] &lt;- 1/exp(LLt[i])
  exp.c[i] &lt;- exp[i]-mean(exp[])
  ed.c[i] &lt;- ed[i]-mean(ed[])}
  # Priors
  beta0[1] &lt;- 0; beta1[1] &lt;- 0; beta2[1] &lt;- 0; c1[1] &lt;- 0; c2[1] &lt;- 0
  for (j in 2:J) {beta1[j] ~ dnorm(0,0.0001)
  beta2[j] ~ dnorm(0,0.0001)
  c1[j] ~ dnorm(0,0.0001)
  c2[j] ~ dnorm(0,0.0001)
  beta0[j] ~ dnorm(0,0.0001)}
  Dv &lt;- -2*sum(LLt[])
  for (k in 1:K) {knot.c[k] &lt;- knot[k]-mean(ed[])
  # degree =1 for linear spline, =2 for quadratic spline 
  for (i in 1:337) { S[i,k] &lt;- (ed.c[i]-knot.c[k])*step(ed[i]-knot[k])
  Spline[i,k] &lt;- pow(S[i,k],degree)}}
  # Random spline coefficients
  for (j in 2:J) {for (k in 1:K) {delta[j,k] ~ dnorm(0,tau[j]); delta.c[j,k] &lt;- delta[j,k]-mean(delta[j,])}
  # full conditionals for spline precision
  tau[j] ~ dgamma(As[j],Bs[j]);     As[j] &lt;- 0.1 + K/2;    Bs[j] &lt;- 0.1 + inprod(delta.c[j,],delta.c[j,])/2}}
  
  *INITIS*
  
  list(beta1=c(NA,0,0,0,0),beta2=c(NA,0,0,0,0),c1=c(NA,0,0,0,0),
  c2=c(NA,0,0,0,0),tau=c(NA,1,1,1,1),
  beta0=c(NA,0,0,0,0),delta=structure(.Data=c(NA,NA,NA,NA,NA,NA,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),.Dim=c(5,6)))
  
  list(beta1=c(NA,-0.5,0.5,0,0),beta2=c(NA,-0.5,0.5,0,0),
  c1=c(NA,-0.5,0.5,0,0),c2=c(NA,-0.5,0.5,0,0),tau=c(NA,1,1,1,1),
  beta0=c(NA,-0.5,0.5,0,0),delta=structure(.Data=c(NA,NA,NA,NA,NA,NA,
  -0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,
  0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,0,0),.Dim=c(5,6)))
  
  
  *DATA*
  </code></pre>
  
  <p>my own R2WinBUGS code is like this.</p>
  
  <pre><code>rm(list=ls())
  setwd("C:/Users/~~/BMCD")
  
  Data &lt;- read.table("model604data.txt")
  D&lt;-Data[,1]; exp&lt;-Data[,2]; ed&lt;-Data[,3]; white&lt;-Data[,4]; J=5; K=6; n=337; knot=c(9.6,12,13.6,14,16,16.4); degree=2;
  data &lt;- list(D=D, exp=exp, ed=ed, white=white, J=J, K=K, n=n, knot=knot, degree=degree)
  
  parameters &lt;- c("beta0","beta1","beta2")
  
  inits =list(list(beta1=c(NA,0,0,0,0),beta2=c(NA,0,0,0,0),c1=c(NA,0,0,0,0),c2=c(NA,0,0,0,0),tau=c(NA,1,1,1,1),beta0=c(NA,0,0,0,0),delta=structure(.Data=c(NA,NA,NA,NA,NA,NA,
                                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),.Dim=c(5,6))),
     list(beta1=c(NA,-0.5,0.5,0,0),beta2=c(NA,-0.5,0.5,0,0),c1=c(NA,-0.5,0.5,0,0),c2=c(NA,-0.5,0.5,0,0),tau=c(NA,1,1,1,1),beta0=c(NA,-0.5,0.5,0,0),delta=structure(.Data=c(NA,NA,NA,NA,NA,NA,
                                                      -0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,0,0),.Dim=c(5,6))) )
  
  
  model604 &lt;- bugs(data, inits, parameters,model.file="C:/Users/~~/model604.odc",
               debug=TRUE,n.chains=2, n.iter=2000, n.burnin=500, bugs.directory="C:/Program Files/WinBUGS14/" )'
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/sngJg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sngJg.png" alt="enter image description here"></a></p>
  
  <p>How can I fix this error?<br>
  I tried to change NA in inits to 0, but it didn't work and give me another error message.<br>
  The data follows rectangular format but it's alright<br>
  the syntax translation for model and data will be okay, I guess.<br>
  Should I add the prior condition?</p>