简体   繁体   中英

Observed node inconsistent with unobserved parents at initialization in JAGS

I am trying to implement the graphical model in Wabersich and Vandekerckhove (2013) page 26. The jags model script is written as follow:

model{

  # mean and standard variance  of nu is varying on condition
  # 1
  for(j in 1:n_cond){
   nu_mean[j] ~ dunif(-5.00, 5.00) 
   nu_sd[j] ~ dunif(0.0001, 3.00)
   nu_prec[j] <- pow(nu_sd[j], -2)
  }
  # 2
  alpha_mean ~ dunif(0.0100, 3.00)
  alpha_sd ~ dunif(0.0001, 2.00)
  alpha_prec <- pow(alpha_sd, -2)
  # 3
  theta_mean ~ dunif(0.0100, 0.70)
  theta_sd ~ dunif(0.0001, 0.25)
  theta_prec <- pow(theta_sd, -2)
  # 4
  eta_mean <- 3.5
  eta_sd <- 3.5
  eta_prec <- pow(eta_sd, -2)
  # 5
  chi_mean <- 0.35
  chi_sd <- 0.125
  chi_prec <- pow(chi_sd, -2)

  # p is the index of each subject
  for(p in 1:n_sub){

    # 6 alpha distribution
    alpha_sub[p] ~ dnorm(alpha_mean, alpha_prec)

    #7 theta distribution
    theta_sub[p] ~ dnorm(theta_mean, theta_prec)

    # 8 chi dsitribution
   chi_sub[p] ~ dnorm(chi_mean, chi_prec)
   chi_sub_prec[p] <- pow(chi_sub[p], -2)

    # 9 eta distribution
    eta_sub[p] ~ dnorm(eta_mean, eta_prec)
    eta_sub_prec[p] <- pow(eta_sub[p], -2)

    # 10 
    for(k in 1:n_cond){
      nu_sub[p, k] ~ dnorm(nu_mean[k], nu_prec[k])
    } 
  }

  beta <- 0.5 ## beta in wiener is constant
  for(i in 1: n_trial){

  #11
  delta[i] ~ dnorm(nu_sub[sub[i], cond[i]],
                    eta_sub_prec[sub[i]])
  #12
  tau[i] ~ dnorm( theta_sub[sub[i]],
                   chi_sub_prec[sub[i]] )

  alpha[i] <- alpha_sub[sub[i]]

  # 13 response time
  RT[i] ~ dwiener(alpha[i], 
                         tau[i],
                        beta,
                        delta[i])

 }

}

Then I used the following initial list:

chain1_ini <- list(
                   nu_mean = c(3, 3, 3, 3),  
                   nu_sd = c(.5, .5, .5, .5), 
                   alpha_mean = 1.5,
                   alpha_sd = .5, 
                   theta_mean = .01, 
                   theta_sd = .1)

However, running jags.model result in error:

jags.model(file = jags_script, data = jags_data, inits = chain1_ini, n.chains = 1)

Error in jags.model(file = jags_script, data = jags_data, inits = chain1_ini,  : 
Error in node RT[1]
Observed node inconsistent with unobserved parents at initialization.
Try setting appropriate initial values.

My data structure is

str(jags_data)
List of 6
$ cond   : num [1:1799] 4 1 1 2 2 4 1 4 4 4 ...
$ n_cond : int 4
$ n_sub  : int 10
$ sub    : num [1:1799] 1 1 1 1 1 1 1 1 1 1 ...
$ RT     : num [1:1799] -1686 2067 1931 2553 1986 ...
$ n_trial: int 1799

It seems this error is very common in jags becasue of the initialization. I tried to change the initial values or remove them, but it failed again. When I remove the dwiener the error will be solved.

I would appreciate if anyone could help me.

在您的示例中,RT [1]为负(-1686),但dwiener分布模拟的是Wiener扩散的非负第一次通过时间。

Reason of th error: In my data, the response time is in millisecond and when the RT is divided by 1000 (seconds) it works. However, I haven't seen any documentation that limits the use of ms in dwiener module. But I can guess that somthing like NaN in R is produced when RT is in ms (or exceeding double precision in C).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM