晓玮孟
晓玮孟

Reputation: 1

Non-conforming parameters in function inprod

all, I'm trying to use JAGS model in R. The R package is "R2jags". I'm confused with the error like beblow.

Compiling model graph Resolving undeclared variables Allocating nodes Deleting model Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, : RUNTIME ERROR: Non-conforming parameters in function inprod

The data processing part,

library(R2jags)

data <- read.table("H:/mlp2020/data109.csv",sep = ",",check.names = F,stringsAsFactors = F,header = T)
rownames(data) <- data[,1]
data <- data[,-1]
z <- as.vector(data$group)
z <- z+1
Y_input <- data[,c(1:1356)]
X_input <- data[,c(1358:1368)]

N <- 1702    #nrow(Y_input)
P <- 1356    #ncol(Y_input)
R <- 11      #ncol(X_input)

Y <- Y_input
X <- X_input 

jags.data <- list("X","Y","z","N","P","R")
jags.params <- c("phi","delta") 
jags.inits <- function(){ 
  list("phi"=rbinom(1,1,0.1),"delta"=rbinom(1,1,0.1)) 
}

my model code is like,

model <- function(){
  for (j in 1:P){
    for (i in 1:N){
    k[i,j] <- 1+phi[j]*z[i]    #k=1 phi[j]=0,k=2 phi[j]=1 z[i]=1,k=3 phi[j]=1 z[i]=2
    }
    phi[j] ~ dbern(w)
  }
  

  for (j in 1:P){
    for (i in 1:N){
      Y[i,j] ~ dnorm(mu[i,j], tau[j])
      
      mu[i,j] = e_1[j] + e_2[j]*equals(k[i,j],2) + inprod(X[i,],beta)
    }
    for (r in 1:R){
      beta[r,j]<-delta[r,j]*beta_0[j]
      #spike and slab pior for beta
      delta[r,j] ~ dbern(t)
    }
    #spike and slab pior for beta
    beta_0[j] ~ dnorm(0,tau_beta[j])
    tau_beta[j] ~ dgamma(2, 15) # input
    
    e_1[j]~dnorm(0,tau_1[j])   #tau_mu[j]=1
    tau_1[j] ~ dgamma(2, 15) # input
    
    e_2[j]~dnorm(0,tau_2[j])   #tau_mu[j]=1
    tau_2[j] ~ dgamma(2, 15) # input
    
    sigma[j] <- 1.0/sqrt(tau[j])
    # input 
    tau[j] ~ dgamma(10, 1)
  } 
  # t ~ dbeta(a_t,b_t) # input
  # w ~ dbeta(a_w,b_w) # input
  w ~ dbeta(1,0.1)
  t ~ dbeta(0.4,1.6)
  
}

jagsfit <- jags(data=jags.data, inits=jags.inits, jags.params,
                n.iter=10, 
                model.file=model)

Any help would be greatly appreciated!

Upvotes: 0

Views: 455

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84619

inprod is the dot product. Its two arguments must be vectors of the same lengths, but the second argument in your code is a matrix.

I have not checked your model, but perhaps you want inprod(X[i,],beta[,j]).

Upvotes: 0

Related Questions