0

私のモデルでは、各被験者と各試行に対して 10 のオプション (1 ~ 10) を選択できます ( expectancy)。以下のグラフのルールに基づいて各オプションの値を計算したので、各オプションの値は、試行ごとにshockとの差に基づいて更新されます(乗算)。次に、softmax ルールを使用して、この脅威の同じ関数で各オプションを特定の確率に変換しました: JAGS エラー: "宣言されていない変数の解決" および "exp への無効なベクトル引数" .valphav

ここでの問題は、ジャグに同じ選択の値を更新させることができないことだと思います。

データ: expectancy= 各試行の 1 ~ 10 の番号。shock= 各試行で 1 または 0 のいずれかの数。(以下にサンプルデータを提供しました)

2番目のプロットは、これが2つの選択肢/1つの主題の状況でスタンでどのように行われるかです.

RW_model <- function(){
  # data
  for(i in 1:nsubjects) # for each person
  { 
    # initial value for v
    v [i,1,expectancy[i,1]] <- 0
    
    for (j in 2:ntrials) # for each trial
    {
      # expectancy chosen
      expectancy[i,j] ~ dcat(mu[i,j,1:10])
      predk[i,j] ~ dcat(mu[i,j,1:10])
      
      # softmax rule to calculate values of each expectancy for each subject
      # tau is the value sensitivity parameter
      mu[i,j,1:10] <- exp_v[i,j,1:10] / sum(exp_v[i,j,1:10])
      exp_v[i,j,expectancy[i,j-1]] <- exp(v[i,j,expectancy[i,j-1]]/tau[i])
      
      # prediction error: difference between feedback and learned values of the chosen expectancy  
      pe [i,j-1] <- shock [i,j-1] - v [i,j-1,expectancy[i,j-1]]
      # value updating process for expectancy
      v [i,j,expectancy[i,j-1]] <- v [i,j-1,expectancy[i,j-1]] + alpha [i] * pe [i,j-1]
    }
  }
  
  # priors
  for (i in 1:nsubjects){
    tau [i] ~ dunif (0,3)
    alpha [i] ~ dunif (0,1)
  }
  
}


# example data/ initial value/ parameters
nsubjects <- 42
ntrials <- 14
shock <- matrix(c(0,0,1,1,0,0,1,1,0,0,1,0,1,0),nrow=42,ncol = 14,byrow = T)
expectancy <- matrix(c(1,2,3,4,5,6,7,7,8,8,7,10,10,00),nrow=42,ncol = 14,byrow = T)



data <- list('shock','nsubjects','ntrials','expectancy')


myinits <-  list(list(tau = runif (42,0,3),
                     alpha = runif (42,0,1)))
parameters <- c("tau",'alpha','v','predk') 

# jags sampling
samples <- jags(data, inits=myinits, parameters,
                    model.file = RW_model,
                    n.chains=1, n.iter=1000, n.burnin=500, n.thin=1, DIC=T) 

ここに画像の説明を入力

ここに画像の説明を入力

4

1 に答える 1