Simon S
Simon S

Reputation: 21

Bayesian - decision model with R and R2WinBugs

We want to run a given baysian Model for decision making with R and WinBugs. We are using RStudio and R2WinBugs. The model is given by:

# Search and Stop 
model{
  # Data

  for (i in 1:ns){
    for (q in 1:nq){
      y[i,q] ~ dbern(dec[t[i,q,z1[i,q]]])
      ypred[i,q] ~ dbern(dec[t[i,q,z1[i,q]]])
    }
  }   
  # TTB Decision
  for (i in 1:ns){
    for (q in 1:nq){
      for (j in 1:nc){
        tmp1[i,q,j] <- (m[p[q,1],j]-m[p[q,2],j])*pow(2,s[i,j]-1)
      }
      tmp2[i,q] <- sum(tmp1[i,q,1:nc])
      tmp3[i,q] <- -1*step(-tmp2[i,q])+step(tmp2[i,q])
      t[i,q,1] <- tmp3[i,q]+2
    }
  }
  # WADD Decision
  for (i in 1:ns){
    for (q in 1:nq){
      for (j in 1:nc){
        tmp4[i,q,j] <- (m[p[q,1],j]-m[p[q,2],j])*x[j]
      }
      # Find if Cue Favors First, Second, or Neither Stimulus
      tmp5[i,q] <- sum(tmp4[i,q,1:nc])
      tmp6[i,q] <- -1*step(-tmp5[i,q])+step(tmp5[i,q])
      t[i,q,2] <- tmp6[i,q]+2
    }
  }
  # Follow Decision With Probability Gamma, or Guess
  dec[1] <- 1-gamma
  dec[2] <- 0.5
  dec[3] <- gamma
  # Cue Search Order From Ranking stmp
  for (i in 1:ns){
    for (j in 1:nc){
      s[i,j] <- rank(stmp[i,1:nc],j)
      stmp[i,j] ~ dnorm(0,1)I(0,)
    }
  }
  # TTB and WADD Rate Per Subject
  for (i in 1:ns){
    phi[i] ~ dbeta(1,1)
    for (q in 1:nq){
      z[i,q] ~ dbern(phi[i])
      z1[i,q] <- z[i,q]+1
    }
  }
  gamma ~ dunif(0.5,1)
}`

The underlying data is given by a matlab file, which we read in by the readMat() method.

alldata <-readMat("file.mat").

This is actually working, because we can see the data given by this file in RStudio. This file contains the arrays x, v, p, y, m. These arrays are stored in the list

data<-list(alldata$x,alldata$v, alldata$p, alldata$y, alldata$m).

At the moment we use as inits the value NULL, which means that WinBugs generates the data. But we are not sure if we need WinBugs to generate the data, or if we need to specify it ourselves:

samples <- bugs(data, inits=NULL, parameters, model.file = "Path/SearchStop.txt", bugs.directory = bugsdir, debug = TRUE )

This brings the following error:

undefined variable
compile(3)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(3)
update(334)
command #Bugs:update cannot be executed (is greyed out)
set(gamma)
command #Bugs:set cannot be executed (is greyed out)
set(deviance)
command #Bugs:set cannot be executed (is greyed out)
dic.set()
command #Bugs:dic.set cannot be executed (is greyed out)

In R2WinBugs there is no exact information about which variable is undefined,but when we were trying it in Matlab the error message said, that z1 is undefined.

Upvotes: 2

Views: 114

Answers (0)

Related Questions