16 The BART model of risk taking

  • 인지모델링 / 파트 3 - 베이지안 인지모델링 [1]
  • 김무성

Contents

  • 16.1 The BART model
  • 16.2 A hierarchical extension of the BART model

참고

  • In the original version of the BART, the probability of the balloon bursting increased with every pump, but we consider a simplified version in which that probability is constant, and the expected gain of every decision to pump is zero.
  • In the standard behavioral analysis of the BART, the risk propensity for a subject is measured as the average number of pumps for those balloons that did not burst.
  • It is also possible to measure risk propensity using cognitive models of people’s decisions on the BART

16.1 The BART model

  • We focus on a simple model using just two parameters, used by van Ravenzwaaij et al. (2011).
    • γ+
      • controls risk taking
    • β
      • controls behavioral consistency.
  • p
    • It is assumed the subject knows the constant probability p that the balloon will burst any time it is pumped.
  • ω
    • The number of pumps the subject considers optimal, ω,
      • depends on this probability,
      • and on the propensity for risk taking, such that
        • ω = −γ+/ log (1 − p).
  • Larger values of γ+ lead to larger numbers of pumps being considered optimal, and so to greater risk seeking.
  • θ_jk
    • kth opportunity within
    • jth trial
    • The probability that a subject chooses to pump on the kth opportunity within the jth trial
      • depends on the number of pumps considered optimal,
      • and on the behavioral consistency of the subject.
    • These two factors are combined using the logistic function
      • θ_jk = 1/ (1 + exp {β (k − ω)}).
  • β
    • High values of β correspond to less variable responding.
    • When β = 0, θjk = 0.5, and both pumping and cashing in choices are always equally likely.
    • As β becomes large, the choice becomes completely determined by whether or not k exceeds the number of pumps the subject considers optimal.
  • d_jk
    • Finally, the observed decision made on the kth choice within the jth trial 􏰁􏰂simply follows the modeled choice, so that d_jk ∼ Bernoulli(θ_jk) .

The code BART 1.m or BART 1.R applies the model to data from a single subject, known as George, provided in the file GeorgeSober.txt. (우리 실습에서는 Jags 코드를 씀)


In [1]:
# 이 부분은 파이썬 커널로 변경해서 실행할 것
!head GeorgeSober.txt











JAGS code

BART 1.txt


In [15]:
# BART Model of Risky Decision-Making
BART_1_s = "
model{
  # Optimal Number of Pumps
  omega <- -gplus/log(1-p)
  # Choice Data
  for (j in 1:ntrials){
    for (k in 1:options[j]){
      theta[j,k] <- 1-(1/(1+max(-15,min(15,exp(beta*(k-omega))))))
      d[j,k] ~ dbern(theta[j,k])
    }
  }
  # Priors
  gplus ~ dunif(0,10)
  beta ~ dunif(0,10)
}
"

BART_1_jags.R


In [2]:
library(R2jags)


Loading required package: rjags
Loading required package: coda
Linked to JAGS 3.4.0
Loaded modules: basemod,bugs

Attaching package: ‘R2jags’

The following object is masked from ‘package:coda’:

    traceplot


In [4]:
p       <- .15	# (Belief of) bursting probability
ntrials <- 90 # Number of trials for the BART

In [5]:
Data   <- matrix (data = as.numeric (as.matrix (read.table ("GeorgeSober.txt"))[-1,]), ntrials, 8)
head(Data)


Out[5]:
1.0000 2.0000 0.176515.0000 1.0000 2.0000 0.0000 0.0000
1.0000 2.0000 0.176515.0000 2.0000 1.0000 0.0000 0.0000
1.0000 2.0000 0.176515.0000 3.0000 3.0000 0.6900 0.6900
1.0000 2.0000 0.176515.0000 4.0000 3.0000 0.6900 1.3800
1.0000 2.0000 0.176515.0000 5.0000 1.0000 0.0000 1.3800
1.0000 2.0000 0.176515.0000 6.0000 1.0000 0.5000 1.8800

In [8]:
d      <- matrix (, ntrials, 30) # Data in binary format
head(d)


Out[8]:
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA
NANANANANANANANANANANANANANANANANANANANANANANANANANANANANANA

In [9]:
cash    <-(Data[,7]!=0)*1	# Cash or burst?
npumps  <- Data[,6]				# Nr. of pumps
options <- cash + npumps  # Nr. of decision possibilities

In [10]:
for (j in 1:ntrials)
{
	if (npumps[j]>0) {d[j, 1:npumps[j]] <- rep (0, npumps[j])}
	if (cash[j]==1) {d[j, (npumps[j]+1)] <- 1}
}

In [11]:
data <- list("ntrials", "p", "options", "d") # to be passed on to JAGS

In [12]:
myinits <-	list(
  list(gplus = 1.2, beta = 0.5))

In [13]:
# parameters to be monitored:
parameters <- c("gplus", "beta")

In [16]:
# The following command calls JAGS with specific options.
# For a detailed description see the R2jags documentation.
samples <- jags(data, inits=myinits, parameters, 
                textConnection(BART_1_s), #model.file = "BART_1.txt",
                n.chains=1, n.iter=5000, n.burnin=2000, n.thin=1)


module glm loaded
Compiling model graph
   Resolving undeclared variables
   Allocating nodes
   Graph Size: 458

Initializing model


In [17]:
# Now the values for the monitored parameters are in the "samples" object, 
# ready for inspection.

gplus <- samples$BUGSoutput$sims.list$gplus
beta  <- samples$BUGSoutput$sims.list$beta

In [18]:
#################### PLOT RESULTS

par (cex.main = 2.5, cex.lab = 2, cex.axis = 1.5, mar = c(5, 5, 4, 0), las = 1)
layout (matrix (1:3, 1, 3))

hist(npumps, main = " ", xlab="Number of Pumps", ylab="Frequency", breaks=c(0:7), 
     col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,6.5,by=1), labels = c("1", "2", "3", "4", "5", "6", "7"))
     
plot(density(gplus), xlab = expression (gamma^'+'),
	main = " ", bty = 'n', lwd=2, ylab="Posterior Density")
plot(density(beta), xlab = expression (beta),
	main = " ", bty = 'n', lwd=2, lab = c(5,3,5), ylab="Posterior Density")


Stan code

BART_1_Stan.R


In [19]:
library(rstan)

model <- "
// BART Model of Risky Decision-Making
data { 
  int<lower=1> ntrials;
  real<lower=0,upper=1> p;
  int<lower=1> options[ntrials];
  int d[ntrials,30];
}
parameters {
  // Priors
  real<lower=0,upper=10> gplus;
  real<lower=0,upper=10> beta;
} 
transformed parameters {
  real<lower=0> omega;

  // Optimal Number of Pumps
  omega <- -gplus / log1m(p);  // log1m(p) equals log(1 - p), but faster
}
model {
  // Choice Data
  for (j in 1:ntrials) {
    for (k in 1:options[j]) {
      real theta;
      theta <- 1 - inv_logit(-beta * (k - omega));
      d[j,k] ~ bernoulli(theta);
    }
  }
}"

p       <- .15	# (Belief of) bursting probability
ntrials <- 90   # Number of trials for the BART

Data   <- matrix(data=as.numeric(as.matrix(read.table("GeorgeSober.txt"))[-1, ]),
                 ntrials, 8)
d      <- matrix(-99, ntrials, 30) # Data in binary format

cash    <-(Data[, 7] != 0) * 1  # Cash or burst?
npumps  <- Data[, 6]				    # Nr. of pumps
options <- cash + npumps        # Nr. of decision possibilities

for (j in 1:ntrials) {
	if (npumps[j] > 0) {d[j, 1:npumps[j]] <- rep(0, npumps[j])}
	if (cash[j] == 1) {d[j, (npumps[j] + 1)] <- 1}
}

# To be passed on to Stan:
data <- list(ntrials=ntrials, p=p, options=options, d=d) 

myinits <- list(
  list(gplus=1.2, beta=.5))

parameters <- c("gplus", "beta")  # Parameters to be monitored

# The following command calls Stan with specific options.
# For a detailed description type "?rstan".
samples <- stan(model_code=model,   
                data=data, 
                init=myinits,  # If not specified, gives random inits
                pars=parameters,
                iter=5000, 
                chains=1, 
                thin=1,
                warmup=2000,  # Stands for burn-in; Default = iter/2
                # seed=123  # Setting seed; Default is random seed
)
# Now the values for the monitored parameters are in the "samples" object, 
# ready for inspection.

gplus <- extract(samples)$gplus
beta  <- extract(samples)$beta

#################### PLOT RESULTS

par (cex.main = 2.5, cex.lab = 2, cex.axis = 1.5, mar = c(5, 5, 4, 0), las = 1)
layout (matrix (1:3, 1, 3))

hist(npumps, main = " ", xlab="Number of Pumps", ylab="Frequency", breaks=c(0:7), 
     col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,6.5,by=1), labels = c("1", "2", "3", "4", "5", "6", "7"))
     
plot(density(gplus), xlab = expression (gamma^'+'),
	main = " ", bty = 'n', lwd=2, ylab="Posterior Density")
plot(density(beta), xlab = expression (beta),
	main = " ", bty = 'n', lwd=2, lab = c(5,3,5), ylab="Posterior Density")


Loading required package: Rcpp
Loading required package: inline

Attaching package: ‘inline’

The following object is masked from ‘package:Rcpp’:

    registerPlugin

rstan (Version 2.6.0, packaged: 2015-02-06 21:02:34 UTC, GitRev: 198082f07a60)

Attaching package: ‘rstan’

The following object is masked from ‘package:R2jags’:

    traceplot

The following object is masked from ‘package:coda’:

    traceplot

TRANSLATING MODEL 'model' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'model' NOW.
In file included from file2be70d2a06.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
    static void set_zero_all_adjoints() {
                ^
In file included from file2be70d2a06.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
      size_t product(std::vector<size_t> dims) {
             ^
2 warnings generated.

SAMPLING FOR MODEL 'model' NOW (CHAIN 1).

Iteration:    1 / 5000 [  0%]  (Warmup)
Iteration:  500 / 5000 [ 10%]  (Warmup)
Iteration: 1000 / 5000 [ 20%]  (Warmup)
Iteration: 1500 / 5000 [ 30%]  (Warmup)
Iteration: 2000 / 5000 [ 40%]  (Warmup)
Iteration: 2001 / 5000 [ 40%]  (Sampling)
Iteration: 2500 / 5000 [ 50%]  (Sampling)
Iteration: 3000 / 5000 [ 60%]  (Sampling)
Iteration: 3500 / 5000 [ 70%]  (Sampling)
Iteration: 4000 / 5000 [ 80%]  (Sampling)
Iteration: 4500 / 5000 [ 90%]  (Sampling)
Iteration: 5000 / 5000 [100%]  (Sampling)
#  Elapsed Time: 0.601588 seconds (Warm-up)
#                0.82259 seconds (Sampling)
#                1.42418 seconds (Total)

16.2 A hierarchical extension of the BART model

Alcohol abuse can stimulate risk taking behavior.

  • For example, alcohol abuse has been found to increase risk taking during driving and to increase participation in unsafe sex
  • Examining performance on the BART, Lejuez et al. (2002) found that people with potentially problematic drinking habits also took more risks blowing up the balloons.
  • To examine the effects of alcohol on risk taking behavior more systematically, van Ravenzwaaij et al. (2011) carried out a within-subject manipulation, in which each subject completed the BART while sober, tipsy, and drunk.
    • For a man weighing 70 kg, the blood alcohol concentration level for “drunk” required the consumption of 180 ml of vodka. We analyze here a subset of the data using a hierarchical extension of the individual two-parameter model.

hierarchical extension

  • The hierarchical extension is straightforward and requires
    • only group-level distributions for
      • the risk taking parameter γ+ and
      • behavioral consistency parameter β.
    • We assume
      • these parameters are drawn from Gaussian distributions,
        • but are constrained to be positive.
    • The graphical model now contains
      • an extra plate
        • that corresponds to the different levels or conditions of intoxication,
      • and is shown in Figure 16.4.

JAGS code


In [1]:
#### 입력 파일을 살펴보자. 이 부분은 파이썬 커널로 바꿔서 실행할 것.
!head GeorgeSober.txt GeorgeTipsy.txt GeorgeDrunk.txt


==> GeorgeSober.txt <==











==> GeorgeTipsy.txt <==











==> GeorgeDrunk.txt <==










BART_2_jags.txt


In [20]:
# Hierarchical BART Model of Risky Decision-Making
BART_2_s = "
model{
  # Choice Data
  for (i in 1:nconds){
    gplus[i] ~ dnorm(mug,lambdag)T(0,)
    beta[i] ~ dnorm(mub,lambdab)T(0,)
    omega[i] <- -gplus[i]/log(1-p)
    for (j in 1:ntrials){
      for (k in 1:options[i,j]){
        theta[i,j,k] <- 1-(1/(1+max(-15,min(15,exp(beta[i]*(k-omega[i]))))))
        d[i,j,k] ~ dbern(theta[i,j,k])
      }
    }
  }
  # Priors
  mug ~ dunif(0,10)
  sigmag ~ dunif(0,10)
  mub ~ dunif(0,10)
  sigmab ~ dunif(0,10)
  lambdag <- 1/pow(sigmag,2)
  lambdab <- 1/pow(sigmab,2)
}
"

In [21]:
library(R2jags)

p       <- .15	# (Belief of) bursting probability
ntrials <- 90 # Number of trials for the BART

In [22]:
################### READ IN THE DATA

Data <- list(
	matrix (data = as.numeric (as.matrix (read.table ("GeorgeSober.txt"))[-1,]), ntrials, 8),
	matrix (data = as.numeric (as.matrix (read.table ("GeorgeTipsy.txt"))[-1,]), ntrials, 8),
	matrix (data = as.numeric (as.matrix (read.table ("GeorgeDrunk.txt"))[-1,]), ntrials, 8)
)

In [24]:
str(Data)


List of 3
 $ : num [1:90, 1:8] 1 1 1 1 1 1 1 1 1 1 ...
 $ : num [1:90, 1:8] 1 1 1 1 1 1 1 1 1 1 ...
 $ : num [1:90, 1:8] 1 1 1 1 1 1 1 1 1 1 ...

In [23]:
head(Data)


Out[23]:
  1. 1.0000 2.0000 0.176515.0000 1.0000 2.0000 0.0000 0.0000
    1.0000 2.0000 0.176515.0000 2.0000 1.0000 0.0000 0.0000
    1.0000 2.0000 0.176515.0000 3.0000 3.0000 0.6900 0.6900
    1.0000 2.0000 0.176515.0000 4.0000 3.0000 0.6900 1.3800
    1.0000 2.0000 0.176515.0000 5.0000 1.0000 0.0000 1.3800
    1.0000 2.0000 0.176515.0000 6.0000 1.0000 0.5000 1.8800
    1.0000 2.0000 0.176515.0000 7.0000 1.0000 0.5000 2.3800
    1.0000 2.0000 0.176515.0000 8.0000 1.0000 0.5000 2.8800
    1.0000 2.0000 0.176515.0000 9.0000 3.0000 0.6900 3.5700
    1.0000 2.0000 0.176515.000010.0000 3.0000 0.6900 4.2600
    1.0000 2.0000 0.176515.000011.0000 3.0000 0.6900 4.9500
    1.0000 2.0000 0.176515.000012.0000 3.0000 0.6900 5.6400
    1.0000 2.0000 0.176515.000013.0000 3.0000 0.6900 6.3300
    1.0000 2.0000 0.176515.000014.0000 3.0000 0.6900 7.0200
    1.0000 2.0000 0.176515.000015.0000 3.0000 0.6900 7.7100
    1.0000 2.0000 0.176515.000016.0000 5.0000 0.9500 8.6600
    1.0000 2.0000 0.176515.000017.0000 2.0000 0.0000 8.6600
    1.0000 2.0000 0.176515.000018.0000 4.0000 0.8100 9.4700
    1.0000 2.0000 0.176515.000019.0000 4.0000 0.810010.2800
    1.0000 2.0000 0.176515.000020.0000 4.0000 0.810011.0900
    1.0000 2.0000 0.176515.000021.0000 4.0000 0.810011.9000
    1.0000 2.0000 0.176515.000022.0000 2.0000 0.000011.9000
    1.0000 2.0000 0.176515.000023.0000 1.0000 0.000011.9000
    1.0000 2.0000 0.176515.000024.0000 2.0000 0.590012.4900
    1.0000 2.0000 0.176515.000025.0000 3.0000 0.000012.4900
    1.0000 2.0000 0.176515.000026.0000 1.0000 0.000012.4900
    1.0000 2.0000 0.176515.000027.0000 1.0000 0.500012.9900
    1.0000 2.0000 0.176515.000028.0000 1.0000 0.500013.4900
    1.0000 2.0000 0.176515.000029.0000 1.0000 0.500013.9900
    1.0000 2.0000 0.176515.000030.0000 1.0000 0.500014.4900
    2.0000 1.0000 0.111110.0000 1.0000 5.0000 0.0000 0.0000
    2.0000 1.0000 0.111110.0000 2.0000 5.0000 0.7700 0.7700
    2.0000 1.0000 0.111110.0000 3.0000 4.0000 0.6900 1.4600
    2.0000 1.0000 0.111110.0000 4.0000 1.0000 0.0000 1.4600
    2.0000 1.0000 0.111110.0000 5.0000 3.0000 0.0000 1.4600
    2.0000 1.0000 0.111110.0000 6.0000 1.0000 0.5000 1.9600
    2.0000 1.0000 0.111110.0000 7.0000 3.0000 0.6200 2.5800
    2.0000 1.0000 0.111110.0000 8.0000 3.0000 0.6200 3.2000
    2.0000 1.0000 0.111110.0000 9.0000 4.0000 0.6900 3.8900
    2.0000 1.0000 0.111110.000010.0000 4.0000 0.0000 3.8900
    2.0000 1.0000 0.111110.000011.0000 6.0000 0.8600 4.7500
    2.0000 1.0000 0.111110.000012.0000 2.0000 0.0000 4.7500
    2.0000 1.0000 0.111110.000013.0000 2.0000 0.5600 5.3100
    2.0000 1.0000 0.111110.000014.0000 1.0000 0.5000 5.8100
    2.0000 1.0000 0.111110.000015.0000 3.0000 0.0000 5.8100
    2.0000 1.0000 0.111110.000016.0000 3.0000 0.6200 6.4300
    2.0000 1.0000 0.111110.000017.0000 3.0000 0.6200 7.0500
    2.0000 1.0000 0.111110.000018.0000 3.0000 0.6200 7.6700
    2.0000 1.0000 0.111110.000019.0000 3.0000 0.6200 8.2900
    2.0000 1.0000 0.111110.000020.0000 1.0000 0.5000 8.7900
    2.0000 1.0000 0.111110.000021.0000 1.0000 0.5000 9.2900
    2.0000 1.0000 0.111110.000022.0000 1.0000 0.5000 9.7900
    2.0000 1.0000 0.111110.000023.0000 1.0000 0.500010.2900
    2.0000 1.0000 0.111110.000024.0000 7.0000 0.960011.2500
    2.0000 1.0000 0.111110.000025.0000 4.0000 0.690011.9400
    2.0000 1.0000 0.111110.000026.0000 4.0000 0.690012.6300
    2.0000 1.0000 0.111110.000027.0000 3.0000 0.000012.6300
    2.0000 1.0000 0.111110.000028.0000 1.0000 0.500013.1300
    2.0000 1.0000 0.111110.000029.0000 1.0000 0.500013.6300
    2.0000 1.0000 0.111110.000030.0000 1.0000 0.500014.1300
    3.00 3.00 0.2520.00 1.00 2.00 0.63 0.63
    3.00 3.00 0.2520.00 2.00 3.00 0.79 1.42
    3.00 3.00 0.2520.00 3.00 2.00 0.63 2.05
    3.00 3.00 0.2520.00 4.00 3.00 0.79 2.84
    3.00 3.00 0.2520.00 5.00 2.00 0.63 3.47
    3.00 3.00 0.2520.00 6.00 3.00 0.79 4.26
    3.00 3.00 0.2520.00 7.00 2.00 0.63 4.89
    3.00 3.00 0.2520.00 8.00 4.00 0.99 5.88
    3.00 3.00 0.2520.00 9.00 2.00 0.63 6.51
    3.00 3.00 0.2520.0010.00 5.00 1.24 7.75
    3.00 3.00 0.2520.0011.00 1.00 0.00 7.75
    3.00 3.00 0.2520.0012.00 1.00 0.00 7.75
    3.00 3.00 0.2520.0013.00 3.00 0.79 8.54
    3.00 3.00 0.2520.0014.00 2.00 0.63 9.17
    3.00 3.00 0.2520.0015.00 5.00 1.2410.41
    3.00 3.00 0.2520.0016.00 1.00 0.0010.41
    3.00 3.00 0.2520.0017.00 3.00 0.7911.20
    3.00 3.00 0.2520.0018.00 2.00 0.6311.83
    3.00 3.00 0.2520.0019.00 1.00 0.0011.83
    3.00 3.00 0.2520.0020.00 1.00 0.5012.33
    3.00 3.00 0.2520.0021.00 1.00 0.5012.83
    3.00 3.00 0.2520.0022.00 1.00 0.0012.83
    3.00 3.00 0.2520.0023.00 1.00 0.5013.33
    3.00 3.00 0.2520.0024.00 2.00 0.6313.96
    3.00 3.00 0.2520.0025.00 2.00 0.6314.59
    3.00 3.00 0.2520.0026.00 2.00 0.0014.59
    3.00 3.00 0.2520.0027.00 1.00 0.5015.09
    3.00 3.00 0.2520.0028.00 1.00 0.5015.59
    3.00 3.00 0.2520.0029.00 1.00 0.5016.09
    3.00 3.00 0.2520.0030.00 1.00 0.5016.59
  2. 1.0000 2.0000 0.176515.0000 1.0000 4.0000 0.8100 0.8100
    1.0000 2.0000 0.176515.0000 2.0000 4.0000 0.8100 1.6200
    1.0000 2.0000 0.176515.0000 3.0000 2.0000 0.0000 1.6200
    1.0000 2.0000 0.176515.0000 4.0000 3.0000 0.6900 2.3100
    1.0000 2.0000 0.176515.0000 5.0000 5.0000 0.9500 3.2600
    1.0000 2.0000 0.176515.0000 6.0000 5.0000 0.9500 4.2100
    1.0000 2.0000 0.176515.0000 7.0000 5.0000 0.9500 5.1600
    1.0000 2.0000 0.176515.0000 8.0000 4.0000 0.0000 5.1600
    1.0000 2.0000 0.176515.0000 9.0000 1.0000 0.0000 5.1600
    1.0000 2.0000 0.176515.000010.0000 3.0000 0.0000 5.1600
    1.0000 2.0000 0.176515.000011.0000 3.0000 0.6900 5.8500
    1.0000 2.0000 0.176515.000012.0000 4.0000 0.8100 6.6600
    1.0000 2.0000 0.176515.000013.0000 1.0000 0.0000 6.6600
    1.0000 2.0000 0.176515.000014.0000 1.0000 0.5000 7.1600
    1.0000 2.0000 0.176515.000015.0000 4.0000 0.8100 7.9700
    1.0000 2.0000 0.176515.000016.0000 1.0000 0.0000 7.9700
    1.0000 2.0000 0.176515.000017.0000 1.0000 0.5000 8.4700
    1.0000 2.0000 0.176515.000018.0000 1.0000 0.0000 8.4700
    1.0000 2.0000 0.176515.000019.0000 5.0000 0.9500 9.4200
    1.0000 2.0000 0.176515.000020.0000 3.0000 0.690010.1100
    1.0000 2.0000 0.176515.000021.0000 5.0000 0.950011.0600
    1.0000 2.0000 0.176515.000022.0000 5.0000 0.950012.0100
    1.0000 2.0000 0.176515.000023.0000 2.0000 0.000012.0100
    1.0000 2.0000 0.176515.000024.0000 2.0000 0.590012.6000
    1.0000 2.0000 0.176515.000025.0000 6.0000 1.120013.7200
    1.0000 2.0000 0.176515.000026.0000 7.0000 1.320015.0400
    1.0000 2.0000 0.176515.000027.0000 5.0000 0.000015.0400
    1.0000 2.0000 0.176515.000028.0000 1.0000 0.000015.0400
    1.0000 2.0000 0.176515.000029.0000 5.0000 0.950015.9900
    1.0000 2.0000 0.176515.000030.0000 4.0000 0.810016.8000
    2.0000 1.0000 0.111110.0000 1.0000 6.0000 0.0000 0.0000
    2.0000 1.0000 0.111110.0000 2.0000 5.0000 0.7700 0.7700
    2.0000 1.0000 0.111110.0000 3.0000 4.0000 0.6900 1.4600
    2.0000 1.0000 0.111110.0000 4.0000 5.0000 0.7700 2.2300
    2.0000 1.0000 0.111110.0000 5.0000 5.0000 0.7700 3.0000
    2.0000 1.0000 0.111110.0000 6.0000 5.0000 0.7700 3.7700
    2.0000 1.0000 0.111110.0000 7.0000 5.0000 0.7700 4.5400
    2.0000 1.0000 0.111110.0000 8.0000 5.0000 0.7700 5.3100
    2.0000 1.0000 0.111110.0000 9.0000 5.0000 0.7700 6.0800
    2.0000 1.0000 0.111110.000010.0000 2.0000 0.0000 6.0800
    2.0000 1.0000 0.111110.000011.0000 5.0000 0.7700 6.8500
    2.0000 1.0000 0.111110.000012.0000 5.0000 0.7700 7.6200
    2.0000 1.0000 0.111110.000013.0000 5.0000 0.7700 8.3900
    2.0000 1.0000 0.111110.000014.0000 5.0000 0.7700 9.1600
    2.0000 1.0000 0.111110.000015.0000 7.0000 0.960010.1200
    2.0000 1.0000 0.111110.000016.0000 1.0000 0.000010.1200
    2.0000 1.0000 0.111110.000017.0000 2.0000 0.000010.1200
    2.0000 1.0000 0.111110.000018.0000 1.0000 0.000010.1200
    2.0000 1.0000 0.111110.000019.0000 5.0000 0.770010.8900
    2.0000 1.0000 0.111110.000020.0000 5.0000 0.770011.6600
    2.0000 1.0000 0.111110.000021.0000 5.0000 0.770012.4300
    2.0000 1.0000 0.111110.000022.0000 4.0000 0.000012.4300
    2.0000 1.0000 0.111110.000023.0000 3.0000 0.620013.0500
    2.0000 1.0000 0.111110.000024.0000 7.0000 0.960014.0100
    2.0000 1.0000 0.111110.000025.0000 7.0000 0.960014.9700
    2.0000 1.0000 0.111110.000026.0000 7.0000 0.960015.9300
    2.0000 1.0000 0.111110.000027.0000 8.0000 1.070017.0000
    2.0000 1.0000 0.111110.000028.0000 7.0000 0.960017.9600
    2.0000 1.0000 0.111110.000029.0000 8.0000 1.070019.0300
    2.0000 1.0000 0.111110.000030.0000 7.0000 0.000019.0300
    3.00 3.00 0.2520.00 1.00 1.00 0.00 0.00
    3.00 3.00 0.2520.00 2.00 4.00 0.99 0.99
    3.00 3.00 0.2520.00 3.00 4.00 0.99 1.98
    3.00 3.00 0.2520.00 4.00 1.00 0.00 1.98
    3.00 3.00 0.2520.00 5.00 4.00 0.99 2.97
    3.00 3.00 0.2520.00 6.00 2.00 0.00 2.97
    3.00 3.00 0.2520.00 7.00 4.00 0.99 3.96
    3.00 3.00 0.2520.00 8.00 4.00 0.99 4.95
    3.00 3.00 0.2520.00 9.00 5.00 1.24 6.19
    3.00 3.00 0.2520.0010.00 4.00 0.99 7.18
    3.00 3.00 0.2520.0011.00 4.00 0.99 8.17
    3.00 3.00 0.2520.0012.00 1.00 0.00 8.17
    3.00 3.00 0.2520.0013.00 4.00 0.99 9.16
    3.00 3.00 0.2520.0014.00 4.00 0.9910.15
    3.00 3.00 0.2520.0015.00 1.00 0.0010.15
    3.00 3.00 0.2520.0016.00 4.00 0.9911.14
    3.00 3.00 0.2520.0017.00 1.00 0.0011.14
    3.00 3.00 0.2520.0018.00 1.00 0.0011.14
    3.00 3.00 0.2520.0019.00 2.00 0.0011.14
    3.00 3.00 0.2520.0020.00 4.00 0.9912.13
    3.00 3.00 0.2520.0021.00 4.00 0.9913.12
    3.00 3.00 0.2520.0022.00 4.00 0.9914.11
    3.00 3.00 0.2520.0023.00 2.00 0.0014.11
    3.00 3.00 0.2520.0024.00 2.00 0.0014.11
    3.00 3.00 0.2520.0025.00 4.00 0.9915.10
    3.00 3.00 0.2520.0026.00 3.00 0.0015.10
    3.00 3.00 0.2520.0027.00 4.00 0.0015.10
    3.00 3.00 0.2520.0028.00 3.00 0.0015.10
    3.00 3.00 0.2520.0029.00 4.00 0.9916.09
    3.00 3.00 0.2520.0030.00 3.00 0.0016.09
  3. 1.0000 2.0000 0.176515.0000 1.0000 1.0000 0.5000 0.5000
    1.0000 2.0000 0.176515.0000 2.0000 7.0000 1.3200 1.8200
    1.0000 2.0000 0.176515.0000 3.0000 7.0000 1.3200 3.1400
    1.0000 2.0000 0.176515.0000 4.0000 6.0000 0.0000 3.1400
    1.0000 2.0000 0.176515.0000 5.0000 5.0000 0.9500 4.0900
    1.0000 2.0000 0.176515.0000 6.0000 4.0000 0.0000 4.0900
    1.0000 2.0000 0.176515.0000 7.0000 3.0000 0.0000 4.0900
    1.0000 2.0000 0.176515.0000 8.0000 6.0000 1.1200 5.2100
    1.0000 2.0000 0.176515.0000 9.0000 4.0000 0.8100 6.0200
    1.0000 2.0000 0.176515.000010.0000 4.0000 0.8100 6.8300
    1.0000 2.0000 0.176515.000011.0000 2.0000 0.0000 6.8300
    1.0000 2.0000 0.176515.000012.0000 1.0000 0.0000 6.8300
    1.0000 2.0000 0.176515.000013.0000 4.0000 0.0000 6.8300
    1.0000 2.0000 0.176515.000014.0000 4.0000 0.8100 7.6400
    1.0000 2.0000 0.176515.000015.0000 2.0000 0.0000 7.6400
    1.0000 2.0000 0.176515.000016.0000 3.0000 0.6900 8.3300
    1.0000 2.0000 0.176515.000017.0000 3.0000 0.6900 9.0200
    1.0000 2.0000 0.176515.000018.0000 3.0000 0.6900 9.7100
    1.0000 2.0000 0.176515.000019.0000 3.0000 0.690010.4000
    1.0000 2.0000 0.176515.000020.0000 6.0000 1.120011.5200
    1.0000 2.0000 0.176515.000021.0000 5.0000 0.950012.4700
    1.0000 2.0000 0.176515.000022.0000 5.0000 0.950013.4200
    1.0000 2.0000 0.176515.000023.0000 5.0000 0.950014.3700
    1.0000 2.0000 0.176515.000024.0000 2.0000 0.000014.3700
    1.0000 2.0000 0.176515.000025.0000 5.0000 0.000014.3700
    1.0000 2.0000 0.176515.000026.0000 2.0000 0.000014.3700
    1.0000 2.0000 0.176515.000027.0000 4.0000 0.810015.1800
    1.0000 2.0000 0.176515.000028.0000 5.0000 0.950016.1300
    1.0000 2.0000 0.176515.000029.0000 5.0000 0.950017.0800
    1.0000 2.0000 0.176515.000030.0000 2.0000 0.000017.0800
    2.0000 1.0000 0.111110.0000 1.0000 9.0000 1.1900 1.1900
    2.0000 1.0000 0.111110.0000 2.0000 1.0000 0.0000 1.1900
    2.0000 1.0000 0.111110.0000 3.0000 6.0000 0.8600 2.0500
    2.0000 1.0000 0.111110.0000 4.0000 6.0000 0.8600 2.9100
    2.0000 1.0000 0.111110.0000 5.0000 6.0000 0.8600 3.7700
    2.0000 1.0000 0.111110.0000 6.0000 6.0000 0.8600 4.6300
    2.0000 1.0000 0.111110.0000 7.0000 4.0000 0.0000 4.6300
    2.0000 1.0000 0.111110.0000 8.0000 6.0000 0.8600 5.4900
    2.0000 1.0000 0.111110.0000 9.0000 5.0000 0.0000 5.4900
    2.0000 1.0000 0.111110.000010.0000 5.0000 0.0000 5.4900
    2.0000 1.0000 0.111110.000011.0000 2.0000 0.0000 5.4900
    2.0000 1.0000 0.111110.000012.0000 6.0000 0.8600 6.3500
    2.0000 1.0000 0.111110.000013.0000 2.0000 0.5600 6.9100
    2.0000 1.0000 0.111110.000014.0000 1.0000 0.5000 7.4100
    2.0000 1.0000 0.111110.000015.0000 1.0000 0.5000 7.9100
    2.0000 1.0000 0.111110.000016.0000 1.0000 0.5000 8.4100
    2.0000 1.0000 0.111110.000017.0000 1.0000 0.5000 8.9100
    2.0000 1.0000 0.111110.000018.0000 1.0000 0.5000 9.4100
    2.0000 1.0000 0.111110.000019.0000 1.0000 0.5000 9.9100
    2.0000 1.0000 0.111110.000020.0000 1.0000 0.500010.4100
    2.0000 1.0000 0.111110.000021.0000 1.0000 0.500010.9100
    2.0000 1.0000 0.111110.000022.0000 1.0000 0.500011.4100
    2.0000 1.0000 0.111110.000023.0000 1.0000 0.500011.9100
    2.0000 1.0000 0.111110.000024.0000 1.0000 0.500012.4100
    2.0000 1.0000 0.111110.000025.0000 1.0000 0.500012.9100
    2.0000 1.0000 0.111110.000026.0000 1.0000 0.500013.4100
    2.0000 1.0000 0.111110.000027.0000 1.0000 0.500013.9100
    2.0000 1.0000 0.111110.000028.0000 1.0000 0.500014.4100
    2.0000 1.0000 0.111110.000029.0000 1.0000 0.500014.9100
    2.0000 1.0000 0.111110.000030.0000 1.0000 0.500015.4100
    3.00 3.00 0.2520.00 1.00 3.00 0.00 0.00
    3.00 3.00 0.2520.00 2.00 5.00 1.24 1.24
    3.00 3.00 0.2520.00 3.00 1.00 0.00 1.24
    3.00 3.00 0.2520.00 4.00 2.00 0.00 1.24
    3.00 3.00 0.2520.00 5.00 2.00 0.63 1.87
    3.00 3.00 0.2520.00 6.00 2.00 0.63 2.50
    3.00 3.00 0.2520.00 7.00 3.00 0.79 3.29
    3.00 3.00 0.2520.00 8.00 3.00 0.00 3.29
    3.00 3.00 0.2520.00 9.00 3.00 0.79 4.08
    3.00 3.00 0.2520.0010.00 2.00 0.00 4.08
    3.00 3.00 0.2520.0011.00 2.00 0.63 4.71
    3.00 3.00 0.2520.0012.00 2.00 0.00 4.71
    3.00 3.00 0.2520.0013.00 2.00 0.63 5.34
    3.00 3.00 0.2520.0014.00 2.00 0.63 5.97
    3.00 3.00 0.2520.0015.00 3.00 0.79 6.76
    3.00 3.00 0.2520.0016.00 3.00 0.79 7.55
    3.00 3.00 0.2520.0017.00 3.00 0.79 8.34
    3.00 3.00 0.2520.0018.00 1.00 0.00 8.34
    3.00 3.00 0.2520.0019.00 1.00 0.50 8.84
    3.00 3.00 0.2520.0020.00 1.00 0.50 9.34
    3.00 3.00 0.2520.0021.00 1.00 0.50 9.84
    3.00 3.00 0.2520.0022.00 1.00 0.00 9.84
    3.00 3.00 0.2520.0023.00 1.00 0.5010.34
    3.00 3.00 0.2520.0024.00 1.00 0.5010.84
    3.00 3.00 0.2520.0025.00 1.00 0.5011.34
    3.00 3.00 0.2520.0026.00 2.00 0.6311.97
    3.00 3.00 0.2520.0027.00 2.00 0.6312.60
    3.00 3.00 0.2520.0028.00 2.00 0.6313.23
    3.00 3.00 0.2520.0029.00 2.00 0.6313.86
    3.00 3.00 0.2520.0030.00 1.00 0.5014.36

In [26]:
nconds <- length(Data)      
cash  <- npumps <- matrix (, nconds, ntrials) # Cashes and nr. of pumps
d <- array (, c(nconds, ntrials, 30))        # Data in binary format

In [27]:
for (i in 1:nconds)
{
	cash[i,]   <- (Data[[i]][,7]!=0)*1	# Cash or burst?
	npumps[i,] <- Data[[i]][,6]				  # Nr. of pumps

	for (j in 1:ntrials)
	{
		if (npumps[i,j]>0) {d[i, j, 1:npumps[i,j]] <- rep(0, npumps[i,j])}
		if (cash[i,j]==1) {d[i, j, (npumps[i,j]+1)] <- 1}
	}
}

In [28]:
options <- cash + npumps	# Nr. of decision possibilities

In [29]:
data <- list("nconds", "ntrials", "p", "options", "d") # to be passed on to JAGS

In [31]:
myinits <- list(
    list(mug = 1.2, sigmag = 0.1, mub = 0.8, sigmab = 0.8),
    list(mug = 1.5, sigmag = 0.2, mub = 1.0, sigmab = 1.2))

In [32]:
# parameters to be monitored:
parameters <- c("gplus", "beta", "mug", "sigmag", "mub", "sigmab")

In [33]:
# The following command calls JAGS with specific options.
# For a detailed description see the R2jags documentation.
samples <- jags(data, inits=myinits, parameters, 
                textConnection(BART_2_s), #model.file = "BART_2_jags.txt",
                n.chains=2, n.iter=5000, n.burnin=2000, n.thin=1)


Compiling model graph
   Resolving undeclared variables
   Allocating nodes
   Graph Size: 1537

Initializing model


In [34]:
# Now the values for the monitored parameters are in the "samples" object, 
# ready for inspection.

gplus.sober <- samples$BUGSoutput$sims.list$gplus[,1]
gplus.tipsy <- samples$BUGSoutput$sims.list$gplus[,2]
gplus.drunk <- samples$BUGSoutput$sims.list$gplus[,3]

beta.sober  <- samples$BUGSoutput$sims.list$beta[,1]
beta.tipsy  <- samples$BUGSoutput$sims.list$beta[,2]
beta.drunk  <- samples$BUGSoutput$sims.list$beta[,3]

In [35]:
#################### PLOT SOME RESULTS
par (cex.main = 2.5, cex.lab = 2, cex.axis = 1.5, mar = c(5, 5, 4, 0), las = 1)
layout (matrix (1:9, 3, 3, byrow = T))

hist(npumps[1,], xlab=" ", main = "Sober: # pumps", breaks=c(0:max(npumps[1,])), xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))

plot(density(gplus.sober), xlab = expression (gamma^'+'),
	main = expression (paste ("Sober: Posterior ", gamma^'+')), xlim = c(0.6,1.8), bty = 'n')
plot (density(beta.sober), xlab = expression (beta),
	main = expression (paste ("Sober: Posterior ", beta)), xlim = c(0.2,1.4), bty = 'n')

hist(npumps[2,], xlab=" ", main = "Tipsy: # pumps", breaks=c(0:max(npumps[2,])), xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))
plot(density (gplus.tipsy), xlab = expression (gamma^'+'),
	main = expression (paste ("Tipsy: Posterior ", gamma^'+')), xlim = c(0.6,1.8), bty = 'n')
plot(density (beta.tipsy), xlab = expression (beta),
	main = expression (paste ("Tipsy: Posterior ", beta)), xlim = c(0.2,1.4), bty = 'n')

hist(npumps[3,], xlab="Number of Pumps", main = "Drunk: # pumps", breaks=c(0:max(npumps[3,])), xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))
plot(density(gplus.drunk), xlab = expression (gamma^'+'),
	main = expression(paste ("Drunk: Posterior ", gamma^'+')), xlim = c(0.6,1.8), bty = 'n')
plot(density(beta.drunk), xlab = expression (beta),
	main = expression(paste ("Drunk: Posterior ", beta)), xlim = c(0.2,1.4), bty = 'n')


Stan code


In [36]:
library(rstan)

model <- "
// BART Model of Risky Decision-Making
data {
  int<lower=1> nconds;
  int<lower=1> ntrials;
  real<lower=0,upper=1> p;
  int<lower=1> options[nconds,ntrials];
  int d[nconds,ntrials,30];
}
parameters {
  vector<lower=0>[nconds] gplus;
  vector<lower=0>[nconds] beta;
  
  // Priors
  real<lower=0,upper=10> mug;
  real<lower=0,upper=10> sigmag;
  real<lower=0,upper=10> mub;
  real<lower=0,upper=10> sigmab;
} 
transformed parameters {
  vector<lower=0>[nconds] omega;

  // Optimal Number of Pumps
  omega <- -gplus / log1m(p);
}
model {
  for (i in 1:nconds) {
    gplus[i] ~ normal(mug, sigmag)T[0,];
    beta[i] ~ normal(mub, sigmab)T[0,];
  }
  // Choice Data
  for (i in 1:nconds) {
    for (j in 1:ntrials) {
      for (k in 1:options[i,j]) {
        real theta;
        theta <- 1 - inv_logit(-beta[i] * (k - omega[i]));
        d[i,j,k] ~ bernoulli(theta);
      }
    }
  }
}"

p       <- .15  # (Belief of) bursting probability
ntrials <- 90  # Number of trials for the BART

################### READ IN THE DATA

Data <- list(
  matrix(data=as.numeric(as.matrix(read.table("GeorgeSober.txt"))[-1, ]),
         ntrials, 8),
  matrix(data=as.numeric(as.matrix(read.table("GeorgeTipsy.txt"))[-1, ]),
         ntrials, 8),
  matrix(data=as.numeric(as.matrix(read.table("GeorgeDrunk.txt"))[-1, ]),
         ntrials, 8)
)

nconds <- length(Data)                         
cash   <- npumps <- matrix (, nconds, ntrials)  # Cashes and nr. of pumps
d      <- array (-99, c(nconds, ntrials, 30))      # Data in binary format

for (i in 1:nconds) {
  cash[i, ]   <- (Data[[i]][, 7] != 0) * 1  # Cash or burst?
  npumps[i, ] <- Data[[i]][, 6]             # Nr. of pumps

  for (j in 1:ntrials) {
    if (npumps[i, j] > 0) {d[i, j, 1:npumps[i, j]] <- rep(0, npumps[i, j])}
    if (cash[i, j] == 1) {d[i, j, (npumps[i, j] + 1)] <- 1}
  }
}
options <- cash + npumps  # Nr. of decision possibilities

# To be passed on to Stan:
data <- list(nconds=nconds, ntrials=ntrials, p=p, options=options, d=d) 

myinits <- list(
  list(gplus=rep(1.2, 3), beta=rep(.5, 3), mug=1.2, sigmag=.1, mub=.8, sigmab=.8),
  list(gplus=rep(1.2, 3), beta=rep(.5, 3), mug=1.5, sigmag=.2, mub=1, sigmab=1.2))

# Parameters to be monitored:
parameters <- c("beta", "gplus", "mub", "mug", "sigmab", "sigmag")  

# The following command calls Stan with specific options.
# For a detailed description type "?rstan".
samples <- stan(model_code=model,   
                data=data, 
                init=myinits,  # If not specified, gives random inits
                pars=parameters,
                iter=1500, 
                chains=2, 
                thin=1,
                warmup=500,  # Stands for burn-in; Default = iter/2
                seed=1234  # Setting seed; Default is random seed
)
# Now the values for the monitored parameters are in the "samples" object, 
# ready for inspection.

gplus.sober <- extract(samples)$gplus[,1]
gplus.tipsy <- extract(samples)$gplus[,2]
gplus.drunk <- extract(samples)$gplus[,3]

beta.sober  <- extract(samples)$beta[,1]
beta.tipsy  <- extract(samples)$beta[,2]
beta.drunk  <- extract(samples)$beta[,3]

#################### PLOT SOME RESULTS
windows()
par (cex.main = 2.5, cex.lab = 2, cex.axis = 1.5, mar = c(5, 5, 4, 0), las = 1)
layout (matrix (1:9, 3, 3, byrow = T))

hist(npumps[1,], xlab=" ", main = "Sober: # pumps", breaks=c(0:max(npumps[1,])),
     xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), 
     labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))

plot(density(gplus.sober), xlab = expression (gamma^'+'), xlim = c(0.6,1.8), 
     main = expression (paste ("Sober: Posterior ", gamma^'+')), bty = 'n')
plot (density(beta.sober), xlab = expression (beta), bty = 'n',
      main = expression (paste ("Sober: Posterior ", beta)), xlim = c(0.2,1.4))

hist(npumps[2,], xlab=" ", main = "Tipsy: # pumps", breaks=c(0:max(npumps[2,])),
     xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), 
     labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))
plot(density (gplus.tipsy), xlab = expression (gamma^'+'), xlim = c(0.6,1.8),
     main = expression (paste ("Tipsy: Posterior ", gamma^'+')), bty = 'n')
plot(density (beta.tipsy), xlab = expression (beta), xlim = c(0.2,1.4),
     main = expression (paste ("Tipsy: Posterior ", beta)), bty = 'n')

hist(npumps[3,], xlab="Number of Pumps", main = "Drunk: # pumps",
     breaks=c(0:max(npumps[3,])), xlim = range(c(0:9)), col="lightblue", axes=F)
axis(2)
axis(1, at=seq(.5,8.5,by=1), 
     labels = c("1", "2", "3", "4", "5", "6", "7", "8", "9"))
plot(density(gplus.drunk), xlab = expression (gamma^'+'), xlim = c(0.6,1.8),
     main = expression(paste ("Drunk: Posterior ", gamma^'+')),  bty = 'n')
plot(density(beta.drunk), xlab = expression (beta), xlim = c(0.2,1.4),
     main = expression(paste ("Drunk: Posterior ", beta)),  bty = 'n')


TRANSLATING MODEL 'model' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'model' NOW.
In file included from file2bee265871.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
    static void set_zero_all_adjoints() {
                ^
In file included from file2bee265871.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
      size_t product(std::vector<size_t> dims) {
             ^
2 warnings generated.

SAMPLING FOR MODEL 'model' NOW (CHAIN 1).

Iteration:    1 / 1500 [  0%]  (Warmup)
Iteration:  150 / 1500 [ 10%]  (Warmup)
Iteration:  300 / 1500 [ 20%]  (Warmup)
Iteration:  450 / 1500 [ 30%]  (Warmup)
Iteration:  501 / 1500 [ 33%]  (Sampling)
Iteration:  650 / 1500 [ 43%]  (Sampling)
Iteration:  800 / 1500 [ 53%]  (Sampling)
Iteration:  950 / 1500 [ 63%]  (Sampling)
Iteration: 1100 / 1500 [ 73%]  (Sampling)
Iteration: 1250 / 1500 [ 83%]  (Sampling)
Iteration: 1400 / 1500 [ 93%]  (Sampling)
Iteration: 1500 / 1500 [100%]  (Sampling)
#  Elapsed Time: 2.88557 seconds (Warm-up)
#                4.4326 seconds (Sampling)
#                7.31817 seconds (Total)


SAMPLING FOR MODEL 'model' NOW (CHAIN 2).

Iteration:    1 / 1500 [  0%]  (Warmup)
Iteration:  150 / 1500 [ 10%]  (Warmup)
Iteration:  300 / 1500 [ 20%]  (Warmup)
Iteration:  450 / 1500 [ 30%]  (Warmup)
Iteration:  501 / 1500 [ 33%]  (Sampling)
Iteration:  650 / 1500 [ 43%]  (Sampling)
Iteration:  800 / 1500 [ 53%]  (Sampling)
Iteration:  950 / 1500 [ 63%]  (Sampling)
Iteration: 1100 / 1500 [ 73%]  (Sampling)
Iteration: 1250 / 1500 [ 83%]  (Sampling)
Iteration: 1400 / 1500 [ 93%]  (Sampling)
Iteration: 1500 / 1500 [100%]  (Sampling)
#  Elapsed Time: 3.86499 seconds (Warm-up)
#                6.26435 seconds (Sampling)
#                10.1293 seconds (Total)

Error in eval(expr, envir, enclos): 함수 "windows"를 찾을 수 없습니다

참고자료