Commit 6a82f9b0 authored by linushof's avatar linushof
Browse files

Move code for CPT

parent 3777b9e0
# parameters
parameters <- c("alpha",
"gamma",
"delta",
"rho")
n_chains <- 4
# prepare data for JAGS
## select strategy-parameter combination
choices_MCMC <- choices %>%
filter(strategy == "piecewise" & boundary == "relative" & s == 1-.9, a == 7) %>%
mutate(choice_A = case_when(choice == "A" ~ 1,
choice == "B" ~ 0),
i = row_number(),
a_p2 = 1-a_p1,
b_o1 = b,
b_p1 = b_p,
b_o2 = 0,
b_p2 = 0) %>%
select(strategy:rare, a_p1, a_o1, a_p2, a_o2, a_ev, b_p1, b_o1, b_p2, b_o2, choice_A, i)
data = list(
resp = choices_MCMC$choice_A,
x_A = choices_MCMC$a_o2, # higher risky outcome
y_A = choices_MCMC$a_o1, # lower risky outcome
x_B = choices_MCMC$b_o1, # safe outcome
y_B = choices_MCMC$b_o2, # 0
px_A = choices_MCMC$a_p2, # probability higher risky outcome
py_A = choices_MCMC$a_p1, # probability lower risky outcome
px_B = choices_MCMC$b_p1, # probability safe outcome (1)
py_B = choices_MCMC$b_p2, # 0
min_i = min(choices_MCMC$i),
max_i = max(choices_MCMC$i)
)
# MCMC sampling
samples <- jags.parallel(data,
parameters,
model.file = "JAGS/cpt_trial_level.txt",
inits = NULL,
n.chains = n_chains,
n.iter = 10000,
n.burnin = 5000,
n.thin = 1,
n.cluster = n_chains,
jags.seed = 888)
# MCMC diagnostics
samples$BUGSoutput$summary
mcmcplots::mcmcplot(samples)
---
title: "Sampling in DfE: Pilot Study"
title: "Sampling in DfE: Simulation Study"
author: "Linus Hof, Veronika Zilker & Thorsten Pachur"
bibliography: sampling-strategies-in-dfe.bib
csl: apa.csl
......@@ -39,7 +39,7 @@ A formal introduction to sampling in DfE and the data generating models of this
# Method
## Data Set
## Test set
Under each condition, i.e., strategy-parameter combinations, all gambles are played by 100 synthetic agents. We test a set of gambles, in which one of the prospects contains a safe outcome and the other two risky outcomes (*safe-risky gambles*). Therefore, 60 gambles from an initial set of 10,000 are sampled. Both, outcomes and probabilities are drawn from uniform distributions, ranging from 0 to 20 for outcomes and from .01 to .99 for probabilities of the lower risky outcomes $p_{low}$. The probabilities of the higher risky outcomes are $1-p_{low}$, respectively. To omit dominant prospects, safe outcomes fall between both risky outcomes. The table below contains the test set of 60 gambles. Sampling of gambles was stratified, randomly drawing an equal number of 20 gambles with no, an attractive, and an unattractive rare outcome. Risky outcomes are considered *"rare"* if their probability is $p < .2$ and *"attractive"* (*"unattractive"*) if they are higher (lower) than the safe outcome.
......@@ -581,67 +581,5 @@ choices %>%
### Modeling Choices in Cumulative Prospect Theory
```{r}
# parameters
parameters <- c("alpha",
"gamma",
"delta",
"rho")
n_chains <- 4
```
```{r}
# prepare data for JAGS
## select strategy-parameter combination
choices_MCMC <- choices %>%
filter(strategy == "piecewise" & boundary == "relative" & s == 1, a == 7) %>%
mutate(choice_A = case_when(choice == "A" ~ 1,
choice == "B" ~ 0),
i = row_number(),
a_p2 = 1-a_p1,
b_o1 = b,
b_p1 = b_p,
b_o2 = 0,
b_p2 = 0) %>%
select(strategy:rare, a_p1, a_o1, a_p2, a_o2, a_ev, b_p1, b_o1, b_p2, b_o2, choice_A, i)
data = list(
resp = choices_MCMC$choice_A,
x_A = choices_MCMC$a_o2, # higher risky outcome
y_A = choices_MCMC$a_o1, # lower risky outcome
x_B = choices_MCMC$b_o1, # safe outcome
y_B = choices_MCMC$b_o2, # 0
px_A = choices_MCMC$a_p2, # probability higher risky outcome
py_A = choices_MCMC$a_p1, # probability lower risky outcome
px_B = choices_MCMC$b_p1, # probability safe outcome (1)
py_B = choices_MCMC$b_p2, # 0
min_i = min(choices_MCMC$i),
max_i = max(choices_MCMC$i)
)
```
```{r}
# MCMC sampling
samples <- jags.parallel(data,
parameters,
model.file = "JAGS/cpt_trial_level.txt",
inits = NULL,
n.chains = n_chains,
n.iter = 10000,
n.burnin = 5000,
n.thin = 1,
n.cluster = n_chains,
jags.seed = 888)
# MCMC diagnostics
samples$BUGSoutput$summary
mcmcplots::mcmcplot(samples)
```
# References
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment