Commit 0ce25153 by linushof

Example Code for Bayesian estimation of CPT parameters

parent ecd260e8
 ... ... @@ -581,5 +581,67 @@ 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!