Sean S
Sean S

Reputation: 108

JAGS compilation error

My seemingly straightforward model keeps giving me strange compilation errors.

Runtime Error:
Compilation error on line 17.
Unknown variable Nx
Either supply values for this variable with the data or define it on the left hand side of a relation.

Here is my code:

dataList = list(
  x = x ,
  y = y ,
  xP = xProbe
)

Here's the JAGS model:  
1    data{  
2        Ntotal <- length(y)  
3        ym <- mean(y)  
4        ysd <- sd(y)  
5        for ( i in 1:Ntotal ) {  
6          zy[i] <- ( y[i] - ym ) / ysd  
7        }  
8        Nx <- length(xName)  
9        for ( j in 1:Nx ) {  
10         xm[j]  <- mean(x[,j])  
11         xsd[j] <-   sd(x[,j])  
12         for ( i in 1:Ntotal ) {  
13           zx[i,j] <- ( x[i,j] - xm[j] ) / xsd[j]  
14         }  
15       }  
16       Nprobe <- Ntotal  
17       for ( j in 1:Nx ) {  
18         xPm[j]  <- mean(xP[,j])  
19         xPsd[j] <-   sd(xP[,j])  
20         for (i in 1:Nprobe ) {  
21           zxP[i,j] <- ( xP[i,j] - xPm[j] ) / xPsd[j]  
22         }  
23       }  
24   }  
25   model{  
26       for ( i in 1:Ntotal ) {  
27         zy[i] ~ dt( zbeta0 + sum(zbeta[1:Nx]*zx[i,1:Nx]), 1/zsigma^2, nu)  
28       }  
29      # Priors vague on standardized scale:  
30       zbeta0 ~ dnorm( 0 , 1/2^2 )     
31       for ( j in 1:Nx ) {  
32         zbeta[j] ~ dnorm( 0 , 1/2^2 )  
33       }  
34       zsigma ~ dunif( 1.0E-5 , 1.0E+1 )  
35       nu ~ dexp(1/30.0)  
36      # Transform to original scale:  
37       beta[1:Nx] <- ( zbeta[1:Nx] / xsd[1:Nx] )*ysd  
38       beta0 <- zbeta0* ysd + ym - sum(zbeta[1:Nx]*xm[1:Nx]/xsd[1:Nx])*ysd  
39       sigma <- zsigma*ysd  
40      # Predicted y values as xProbe:  
41       for ( i in 1:Nprobe ) {  
42         zyP[i] ~ dt(zbeta0+sum(zbeta[1:Nx]*zxP[i,1:Nx]),1/zsigma^2, nu)  
43         yP[i] <- zyP[i] * ysd + ym  
44       }  
45   }  

Upvotes: 1

Views: 1895

Answers (1)

mfidino
mfidino

Reputation: 3055

It looks as if you have not defined what xName is on line 8, which Nx is dependent on. Define that in the dataList and you should be good to go (in regards to fixing this single error).

Upvotes: 2

Related Questions