Home > database >  No-Conforming parameters in inprod function in Jags
No-Conforming parameters in inprod function in Jags

Time:11-28

I am getting error. What does it mean by non-conforming parameters in Inprod()

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  RUNTIME ERROR:
Non-conforming parameters in function inprod
#Jags code 

jagsscript <- cat("
model {  

   # Estimate the initial state vector 
   for(i in 1:14) {
      X[i,1] ~ dnorm(0,1) # weakly informative normal prior 
      xknot[i] <- X[i,1]
   }

   # B matrix of interactions
   for (r in 3:14){
     B[r,1] <- 0
   }
     for (r in c(2:14)){
     B[r,2] <- 0
     }
    for (r in c(1:2, 4:14)){
     B[r,3] <- 0
    }
    for (r in c(1:3, 5:14)){
     B[r,4] <- 0
    }
    for (r in c(1:4, 6:14)){
     B[r,5] <- 0
    }
    for (r in c(1:5, 7:14)){
     B[r,6] <- 0
    }
    for (r in c(1:6, 8:14)){
     B[r,7] <- 0
    }
    for (r in c(1:7, 9:14)){
     B[r,8] <- 0
    }
    for (r in c(1:8, 10:14)){
     B[r,9] <- 0
    }
    for (r in c(1:9, 11:14)){
     B[r,10] <- 0
    }
    for (r in c(1:10, 12:14)){
     B[r,11] <- 0
    }
    for (r in c(1:11, 13:14)){
     B[r,12] <- 0
    }
    for (r in c(1:12, 14)){
     B[r,13] <- 0
    }
    for (r in c(1:13)){
     B[r,14] <- 0
    }
   
   

   B[1, 1] <- phi[1]
   B[1, 2] <- phi[2]
   B[2, 1] <- 1

   for (n in 3:12){
     B[n,n] <- rho[n-2]
   }

   B[13, 13] <- 1
   B[14, 14] <- 1
   
   for (n in 1:10){
   rho[n] ~ dunif(-1, 1)
   }
   phi[1] ~ dnorm(0, 1.3)
   phi[2] ~ dnorm(0, 1.3)


   
      for (r in 1:10){
     Z[r,2] <- 0
      }
      for (r in 2:11){
     Z[r,3] <- 0
      }
       for (r in c(1, 3:11)){
     Z[r,4] <- 0
       }
      for (r in c(1,2, 4:11)){
     Z[r,5] <- 0
      }
       for (r in c(1:3, 5:11)){
     Z[r,6] <- 0
       }
       for (r in c(1:4, 6:11)){
     Z[r,7] <- 0
       }
       for (r in c(1:5, 7:11)){
     Z[r,8] <- 0
       }
       for (r in c(1:6, 8:11)){
     Z[r,9] <- 0
       }
       for (r in c(1:7, 9:11)){
     Z[r,10] <- 0
       }
       for (r in c(1:8, 10:11)){
     Z[r,11] <- 0
       }
   
  
   
    Z[11,1] <- beta[1]
    Z[11,2] <- beta[2]
    Z[1, 1] <- ld[1]
    Z[2, 1] <- ld[2]
    Z[3, 1] <- ld[3]
    Z[4, 1] <- ld[4]
    Z[5, 1] <- ld[5]
    Z[6, 1] <- ld[6]
    Z[7, 1] <- ld[7]
    Z[8, 1] <- ld[8]
    Z[9, 1] <- ld[9]
    Z[10, 1] <- ld[10]

    Z[11,12] <- 1
    Z[1,3] <- 1
    Z[2,4] <- 1
    Z[3,5] <- 1
    Z[4,6] <- 1
    Z[5,7] <- 1
    Z[6,8] <- 1
    Z[7,9] <- 1
    Z[8,10] <- 1
    Z[9,11] <- 1
    Z[10,12] <- 1
    Z[11,13] <- 1
    
   beta[1] ~ dbeta(2.21, 12.53)
   beta[2] ~ dbeta(2.21, 12.53)
   
    for (i in 1:10){
    ld[i] ~ dnorm(0, 1.3)
    }


   # Autoregressive process
   for(t in 2:nYears) {
      for(i in 1:14) {
         predX[i,t] <- inprod(B[i,], X[,t-1])
         X[i,t] ~ dnorm(predX[i,t], tauQ[states[i]])
      }
   }

    tauQ[1] ~ dscaled.gamma(1, 10)
    Q1 <- 1 / tauQ[1]
   
    Q2 <- 1 / tauQ[2]
        Q2 <- 0

   for( i in 3:14){
    tauQ[i] ~ dscaled.gamma(1, 10)
   }
   Q3 <- 1 / tauQ[3]
   Q4 <- 1 / tauQ[4]
   Q5 <- 1 / tauQ[5]
   Q6 <- 1 / tauQ[6]
   Q7 <- 1 / tauQ[7]
   Q8 <- 1 / tauQ[8]
   Q9 <- 1 / tauQ[9]
   Q10 <- 1 / tauQ[10]
   Q11 <- 1 / tauQ[11]
   Q12<- 1 / tauQ[12]
   Q13 <- 1 / tauQ[13]
   Q14 <- 1 / tauQ[14]
   
   
   # Observation model
   for(t in 1:nYears) {
     for(i in 1:11) {
       predY[i,t] <- inprod(Z[i,], X[,t])
       Y[i,t] ~ dnorm(predY[i,t], tauR[hf[i]])
     }
   }
      for( i in 1:11){
    tauR[i] ~ dscaled.gamma(1, 10)
    }
   R1 <- 1 / tauR[1]
   R2 <- 1 / tauR[2]
   R3 <- 1 / tauR[3]
   R4 <- 1 / tauR[4]
   R5 <- 1 / tauR[5]
   R6 <- 1 / tauR[6]
   R7 <- 1 / tauR[7]
   R8 <- 1 / tauR[8]
   R9 <- 1 / tauR[9]
   R10 <- 1 / tauR[10]
   R11 <- 1 / tauR[11]
   

}  

",file="marss-jags.txt")

#putting data

tdat <- t(hf_cycle)
jags.data <- list(Y = tdat, 
                  nYears = ncol(tdat),
                  states = 1:14, hf = 1:11)
          
jags.params <- c("ld", "rho", "beta","phi", "xknot", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", 
                 "Q1", "Q2", "Q3", "Q4","Q5","Q6","Q7","Q8","Q9","Q10", "Q11", "Q12","Q13","Q14") 
model.loc <- "marss-jags.txt"

#running jags
mod_1 <- jags(jags.data, 
              parameters.to.save = jags.params, 
              model.file = model.loc, 
              n.chains = 2, 
              n.burnin = 2000,  
              n.thin = 1, 
              n.iter = 5000)  

We are trying to estimate the demand index from high frequency indicator using bayesian technique. Specifically, the joint posterior distribution for the unknown parameters and the unobserved factor can be sampled using a Markov Chain Monte Carlo procedure on the full set of conditional distributions

CodePudding user response:

The JAGS user manual briefly describes the restrictions for inprod() on page 43 (in table 9.2) as:

inprod(x1, x2)
Description:  Inner product
Restrictions:  Dimensions of x1, x2 conform

In your case, you have:

inprod(B[i,], X[,t-1])
inprod(Z[i,], X[,t])

So the number of columns of B and number of columns of Z must both be equal to the number of rows of X. JAGS is complaining that one (or both) of these is not the case.

CodePudding user response:

You define a value of Z[i,j] for j in 1:13, therefore the matrix Z has 13 columns. But the matrix X has 14 rows, and you perform an inner product between a row Z[i, ] of Z, of length 13, and a column X[, t] of X, of length 14.

  • Related