1

我正在尝试在 Wabersich 和 Vandekerckhove (2013) 第 26 页中实现图形模型。 jags 模型脚本编写如下:

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])

 }

}

然后我使用了以下初始列表:

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)

但是,运行jags.model导致错误:

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.

我的数据结构是

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

由于初始化,这个错误似乎在 jags 中很常见。我试图更改初始值或删除它们,但它再次失败。当我删除dwiener错误将得到解决。

如果有人可以帮助我,我将不胜感激。

4

2 回答 2

2

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

于 2014-06-18T15:17:08.290 回答
0

错误原因:在我的数据中,响应时间以毫秒为单位,当 RT 除以 1000(秒)时,它可以工作。但是,我没有看到任何限制 ms 在 dwiener 模块中使用的文档。但我可以猜测,NaN当 RT 以 ms 为单位(或在 C 中超过双精度)时,会产生类似于 R 的东西。

于 2014-06-18T15:46:49.033 回答