pilot-study.Rmd 54.8 KB
 linushof committed Jul 01, 2021 1 ---  linushof committed Jul 20, 2021 2 title: "Sampling Strategies in DfE - Pilot"  linushof committed Jul 01, 2021 3 date: "2021"  linushof committed Jul 02, 2021 4 5 6 7 8 9 10 11 bibliography: sampling-strategies-in-dfe.bib csl: apa.csl output: html_document: code_folding: hide toc: yes toc_float: yes number_sections: yes  linushof committed Jul 01, 2021 12 13 ---  linushof committed Jul 20, 2021 14 15 Some of the R code is folded but can be unfolded by clicking the Code buttons.  linushof committed Jul 02, 2021 16 17 {r} # load packages  18 pacman::p_load(tidyverse,  linushof committed Jul 02, 2021 19 20 21  knitr)   linushof committed Jul 20, 2021 22 # Description  linushof committed Jul 01, 2021 23   linushof committed Jul 20, 2021 24 Choice data will be generated by applying the *comprehensive-* and *piecewise sampling strategy* to a series of 2-prospect gambles. The simulated data will be explored for characteristic patterns of sampling strategies under varying structures of the choice environment, i.e., features of a gamble's prospects, and aspects of the sampling- and decision behavior (model parameters).  25   linushof committed Jul 20, 2021 26 # Generating Choice Data  linushof committed Jul 01, 2021 27   linushof committed Jul 12, 2021 28 ## Method  linushof committed Jul 01, 2021 29   30 ### Agents  linushof committed Jul 01, 2021 31   32 Under each condition, i.e., strategy-parameter combinations, all gambles are played by 100 synthetic agents.  linushof committed Jul 02, 2021 33 34 35 36  {r} n_agents <- 100   linushof committed Jul 01, 2021 37   38 ### Gambles  linushof committed Jul 02, 2021 39   linushof committed Jul 20, 2021 40 A set of gambles, in which one of the prospects contains a safe outcome and the other two risky outcomes (*safe-risky gambles*) will be tested. 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_L$. The probabilities of the higher risky outcomes are $1-p_L$, 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.  linushof committed Jul 02, 2021 41   42 {r eval = FALSE}  linushof committed Jul 20, 2021 43 source("./R/functions/fun_gambles.R") # call generate_gambles() function  linushof committed Jul 01, 2021 44   linushof committed Jul 02, 2021 45 46 47 48 49 50 # generate and select subset of safe-risky gambles set.seed(3211) sr_gambles <- generate_gambles(n = 10000, safe = TRUE, lower = 0, upper = 20) sr_gambles <- sr_gambles %>% mutate(rare = case_when(a_p1 >= .2 & a_p1 <= .8 ~ "None", a_p1 < .2 ~ "Unattractive", # a_o1 < a_o2 a_p1 > .8 ~ "Attractive"))  linushof committed Jul 12, 2021 51 write_rds(sr_gambles, "./R/data/sr_gambles.rds")  linushof committed Jul 02, 2021 52 53 54 55 56 57 58  sr_subset <- tibble() for(i in unique(sr_gambles$rare)) { type <- sr_gambles %>% filter(rare == i) smpl <- sample(seq_len(nrow(type)), size = 20) sr_subset <- bind_rows(sr_subset, type[smpl, ]) }  linushof committed Jul 12, 2021 59 write_rds(sr_subset, "./R/data/sr_subset.rds")  60 61 62  {r}  linushof committed Jul 26, 2021 63 sr_subset <- read_rds(file = "./R/data/sr_subset.rds")  linushof committed Jul 02, 2021 64 65 66 kable(sr_subset)   linushof committed Jul 20, 2021 67 ### Model Parameters  linushof committed Jul 12, 2021 68   linushof committed Jul 20, 2021 69 **Switching probability:**$s$is the probability increment added to the unbiased probability$p = .5$with which agents draw the succesive single sample from the same prospect they get their most recent single sample from.$s$is varied between -.5 to .4 in increments of .1. To ease interpretation during data analysis,$s$is transformed by$s_{rec}= 1-(p + s)$after the simulation such that it ranges from .1 to 1.  linushof committed Jul 02, 2021 70   linushof committed Jul 20, 2021 71 **Boundary type**: Is either the minimum value *any* prospect's sample statistic must reach (absolute) or the minimum value for the difference of these statistics (relative). Sample statistics are sums over outcomes (comprehensive strategy) and sums over wins (piecewise strategy), respectively.  linushof committed Jul 01, 2021 72   linushof committed Jul 20, 2021 73 **Boundary value:** For comprehensive sampling,$a$is varied between 15 to 35 in increments of 5, for piecewise sampling$a$is varied between 1 to 7 in increments of 2.  linushof committed Jul 01, 2021 74   linushof committed Jul 20, 2021 75 **Noise parameter:** Representations of the sampled outcomes are assumed to be stochastical. Therefore, Gaussian noise$\epsilon \sim N(0, \sigma)$in units of outcomes is added. To reduce computational load,$\sigma$is fixed to .5.  linushof committed Jul 01, 2021 76   linushof committed Jul 20, 2021 77 78 79 80 81 82 83 84 {r eval = FALSE, class.source = "fold-show"} # parameters parameters <- expand_grid(s = seq(-.5, .4, .1), # probability increment added to unbiased sampling probability of p = .5 sigma = .5, # noise boundary = c("absolute", "relative")) # boundary type theta_c <- expand_grid(parameters, a = c(15, 20, 25, 30, 35)) # boundaries comprehensive theta_p <- expand_grid(parameters, a = c(1, 3, 5, 7)) # boundaries piecewise   85   86 ## Simulation  linushof committed Jul 01, 2021 87   linushof committed Jul 12, 2021 88 {r}  linushof committed Jul 02, 2021 89 90 # dataset gambles <- sr_subset  linushof committed Jul 12, 2021 91   linushof committed Jul 01, 2021 92   linushof committed Jul 12, 2021 93 {r}  linushof committed Jul 26, 2021 94 source("./R/functions/fun_moving_stats.R") # call cumsum2() and cummean2() function  linushof committed Jul 01, 2021 95 96   linushof committed Jul 20, 2021 97 ### Comprehensive sampling  linushof committed Jul 02, 2021 98   linushof committed Jul 20, 2021 99 {r eval = FALSE, class.source = "fold-show"}  linushof committed Jul 02, 2021 100 101 102  # simulation  linushof committed Jul 12, 2021 103 theta <- theta_c  linushof committed Jul 02, 2021 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 set.seed(765) param_list <- vector("list", length(nrow(theta))) for (set in seq_len(nrow(theta))) { gamble_list <- vector("list", length(nrow(gambles))) for (gamble in seq_len(nrow(gambles))) { agents_list <- vector("list", n_agents) for (agent in seq_along(1:n_agents)){ ## initial values of an agent's sampling process fd <- tibble() # state of ignorance p <- .5 # no attention bias s <- 0 # no switching at process initiation init <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) # prospect attended first attend <- init boundary_reached <- FALSE ## agent's sampling process while(boundary_reached == FALSE) { #### draw single sample if(attend == "a") { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)) + round(rnorm(n = 1, mean = 0, sd = theta[[set, "sigma"]]), 2), # gaussian noise B = NA) s <- theta[[set, "s"]] # get switching probability } else { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = NA, B = b + round(rnorm(n = 1, mean = 0, theta[[set, "sigma"]]), 2)) s <- -1*theta[[set, "s"]] } #### integrate single sample into frequency distribution fd <- bind_rows(fd, single_smpl) %>% mutate(A_sum = cumsum2(A, na.rm = TRUE), B_sum = cumsum2(B, na.rm = TRUE)) #### evaluate accumulated evidence if(theta[[set, "boundary"]] == "absolute") { fd <- fd %>% mutate(choice = case_when(A_sum >= theta[[set, "a"]] ~ "A", B_sum >= theta[[set, "a"]] ~ "B")) } else { fd <- fd %>% mutate(diff = round(A_sum - B_sum, 2), choice = case_when(diff >= theta[[set, "a"]] ~ "A", diff <= -1*theta[[set, "a"]] ~ "B")) } if(is.na(fd[[nrow(fd), "choice"]]) == FALSE) { boundary_reached <- TRUE } else { attend <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) } } agents_list[[agent]] <- expand_grid(agent, fd) } all_agents <- agents_list %>% map_dfr(as.list) gamble_list[[gamble]] <- expand_grid(gamble, all_agents) } all_gambles <- gamble_list %>% map_dfr(as.list) param_list[[set]] <- expand_grid(theta[set, ], all_gambles) }  175 sim_comprehensive <- param_list %>% map_dfr(as.list)  linushof committed Jul 02, 2021 176   linushof committed Jul 20, 2021 177 # store full simulation  linushof committed Jul 02, 2021 178   linushof committed Jul 12, 2021 179 write_rds(sim_comprehensive, "./R/data/sim_comprehensive.rds")  180   linushof committed Jul 20, 2021 181 # summarize unique sampling processes  linushof committed Jul 12, 2021 182 183 184 185 186 187  summary_comprehensive <- sim_comprehensive %>% group_by(s, sigma, boundary, a, gamble, agent) %>% # group by unique sampling process mutate(n_sample = n(), # number of single samples switch = case_when(attended != lag(attended) ~ 1, attended == lag(attended) ~ 0),  188 189 190  n_switch = sum(switch, na.rm = TRUE), # number of switches a_ev_exp = round(mean(A, na.rm = TRUE), 2), # experienced expected value b_ev_exp = round(mean(B, na.rm = TRUE), 2)) %>%  linushof committed Jul 12, 2021 191 192 193  filter(!is.na(choice)) %>% # only return choice data (last obs of unique sampling process) select(!c(attended, A, B, switch)) %>% ungroup() %>%  194 195 196  mutate(strategy = "comprehensive", s = 1-(s+.5)) %>% select(strategy, s:gamble, rare, a_p1:ev_ratio, agent, n_sample, n_switch, A_sum, B_sum, diff, a_ev_exp, b_ev_exp, choice)  linushof committed Jul 12, 2021 197 write_rds(summary_comprehensive, "./R/data/summary_comprehensive.rds")  198 199   linushof committed Jul 26, 2021 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 #### Expansion of boundary range Because results of the initial analysis indicate scaling issues for the boundary values, the simulation of the comprehensive strategy is rerun. Specifically, the initial set of boundary values$\{15, 20, 25, 30, 35\}$is relatively small compared to the range of possible outcomes$[0;20]$. As a consequence, boundaries are reached for rather small sample sizes. This may cause potential influences of the boundary value e.g. on decision quality to be masked by a ceiling effect. Furthermore, the effects of switching probability on decision behavior may be confounded with the effect of boundary values. I.e., small switching probabilities cause comparisons of sums over unequal sample sizes - the discrepance in sample size increases with decreasing switching probabilities - immediately after switching. If boundaries are low, decisions may terminate early, however, not so because of real differences in EV but because of the comparison of very different sample sizes. In the following, the extended boundary range of$\{40, 45, 50, 55, 60, 65, 70, 75, 80\}$will be tested. {r eval = FALSE, class.source = "fold-show"} # parameters parameters <- expand_grid(s = seq(-.5, .4, .1), # probability increment added to unbiased sampling probability of p = .5 sigma = .5, # noise boundary = c("absolute", "relative")) # boundary type theta_c <- expand_grid(parameters, a = c(40, 45, 50, 55, 60, 65, 70, 75, 80)) # boundaries comprehensive  {r eval = FALSE, class.source = "fold-show"} # param combinations 1:122 theta <- theta_c set.seed(76754) param_list <- vector("list", length(nrow(theta))) for (set in 1:122) { gamble_list <- vector("list", length(nrow(gambles))) for (gamble in seq_len(nrow(gambles))) { agents_list <- vector("list", n_agents) for (agent in seq_along(1:n_agents)){ ## initial values of an agent's sampling process fd <- tibble() # state of ignorance p <- .5 # no attention bias s <- 0 # no switching at process initiation init <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) # prospect attended first attend <- init boundary_reached <- FALSE ## agent's sampling process while(boundary_reached == FALSE) { #### draw single sample if(attend == "a") { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)) + round(rnorm(n = 1, mean = 0, sd = theta[[set, "sigma"]]), 2), # gaussian noise B = NA) s <- theta[[set, "s"]] # get switching probability } else { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = NA, B = b + round(rnorm(n = 1, mean = 0, theta[[set, "sigma"]]), 2)) s <- -1*theta[[set, "s"]] } #### integrate single sample into frequency distribution fd <- bind_rows(fd, single_smpl) %>% mutate(A_sum = cumsum2(A, na.rm = TRUE), B_sum = cumsum2(B, na.rm = TRUE)) #### evaluate accumulated evidence if(theta[[set, "boundary"]] == "absolute") { fd <- fd %>% mutate(choice = case_when(A_sum >= theta[[set, "a"]] ~ "A", B_sum >= theta[[set, "a"]] ~ "B")) } else { fd <- fd %>% mutate(diff = round(A_sum - B_sum, 2), choice = case_when(diff >= theta[[set, "a"]] ~ "A", diff <= -1*theta[[set, "a"]] ~ "B")) } if(is.na(fd[[nrow(fd), "choice"]]) == FALSE) { boundary_reached <- TRUE } else { attend <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) } } agents_list[[agent]] <- expand_grid(agent, fd) } all_agents <- agents_list %>% map_dfr(as.list) gamble_list[[gamble]] <- expand_grid(gamble, all_agents) } all_gambles <- gamble_list %>% map_dfr(as.list) param_list[[set]] <- expand_grid(theta[set, ], all_gambles) } sim_comprehensive_ext_122 <- param_list %>% map_dfr(as.list) summary_comprehensive_ext_l122 <- l122 %>% group_by(s, sigma, boundary, a, gamble, agent) %>% # group by unique sampling process mutate(n_sample = n(), # number of single samples switch = case_when(attended != lag(attended) ~ 1, attended == lag(attended) ~ 0), n_switch = sum(switch, na.rm = TRUE), # number of switches a_ev_exp = round(mean(A, na.rm = TRUE), 2), # experienced expected value b_ev_exp = round(mean(B, na.rm = TRUE), 2)) %>% filter(!is.na(choice)) %>% # only return choice data (last obs of unique sampling process) select(!c(attended, A, B, switch)) %>% ungroup() %>% mutate(strategy = "comprehensive", s = 1-(s+.5)) %>% select(strategy, s:gamble, rare, a_p1:ev_ratio, agent, n_sample, n_switch, A_sum, B_sum, diff, a_ev_exp, b_ev_exp, choice) write_rds(summary_comprehensive_ext_122, "./R/data/summary_comprehensive_ext_122.rds")  {r} # # param combinations 1:122 theta <- theta_c set.seed(659) param_list <- vector("list", length(nrow(theta))) for (set in 123:nrow(theta)) { gamble_list <- vector("list", length(nrow(gambles))) for (gamble in seq_len(nrow(gambles))) { agents_list <- vector("list", n_agents) for (agent in seq_along(1:n_agents)){ ## initial values of an agent's sampling process fd <- tibble() # state of ignorance p <- .5 # no attention bias s <- 0 # no switching at process initiation init <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) # prospect attended first attend <- init boundary_reached <- FALSE ## agent's sampling process while(boundary_reached == FALSE) { #### draw single sample if(attend == "a") { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)) + round(rnorm(n = 1, mean = 0, sd = theta[[set, "sigma"]]), 2), # gaussian noise B = NA) s <- theta[[set, "s"]] # get switching probability } else { single_smpl <- gambles[gamble, ] %>% mutate(attended = attend, A = NA, B = b + round(rnorm(n = 1, mean = 0, theta[[set, "sigma"]]), 2)) s <- -1*theta[[set, "s"]] } #### integrate single sample into frequency distribution fd <- bind_rows(fd, single_smpl) %>% mutate(A_sum = cumsum2(A, na.rm = TRUE), B_sum = cumsum2(B, na.rm = TRUE)) #### evaluate accumulated evidence if(theta[[set, "boundary"]] == "absolute") { fd <- fd %>% mutate(choice = case_when(A_sum >= theta[[set, "a"]] ~ "A", B_sum >= theta[[set, "a"]] ~ "B")) } else { fd <- fd %>% mutate(diff = round(A_sum - B_sum, 2), choice = case_when(diff >= theta[[set, "a"]] ~ "A", diff <= -1*theta[[set, "a"]] ~ "B")) } if(is.na(fd[[nrow(fd), "choice"]]) == FALSE) { boundary_reached <- TRUE } else { attend <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) } } agents_list[[agent]] <- expand_grid(agent, fd) } all_agents <- agents_list %>% map_dfr(as.list) gamble_list[[gamble]] <- expand_grid(gamble, all_agents) } all_gambles <- gamble_list %>% map_dfr(as.list) param_list[[set]] <- expand_grid(theta[set, ], all_gambles) svMisc::progress(set, 58, progress.bar = TRUE) } sim_comprehensive_ext_123 <- param_list %>% map_dfr(as.list) summary_comprehensive_ext_123 <- sim_comprehensive_ext_123 %>% group_by(s, sigma, boundary, a, gamble, agent) %>% # group by unique sampling process mutate(n_sample = n(), # number of single samples switch = case_when(attended != lag(attended) ~ 1, attended == lag(attended) ~ 0), n_switch = sum(switch, na.rm = TRUE), # number of switches a_ev_exp = round(mean(A, na.rm = TRUE), 2), # experienced expected value b_ev_exp = round(mean(B, na.rm = TRUE), 2)) %>% filter(!is.na(choice)) %>% # only return choice data (last obs of unique sampling process) select(!c(attended, A, B, switch)) %>% ungroup() %>% mutate(strategy = "comprehensive", s = 1-(s+.5)) %>% select(strategy, s:gamble, rare, a_p1:ev_ratio, agent, n_sample, n_switch, A_sum, B_sum, diff, a_ev_exp, b_ev_exp, choice) write_rds(summary_comprehensive_123, "./R/data/summary_comprehensive_123.rds")   linushof committed Jul 12, 2021 409 410 ### Piecewise sampling  linushof committed Jul 20, 2021 411 {r eval = FALSE, class.source = "fold-show"}  linushof committed Jul 02, 2021 412 413 414  # simulation  linushof committed Jul 12, 2021 415 theta <- theta_p  linushof committed Jul 02, 2021 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 set.seed(8739) param_list <- vector("list", length(nrow(theta))) for (set in seq_len(nrow(theta))) { gamble_list <- vector("list", length(nrow(gambles))) for (gamble in seq_len(nrow(gambles))) { agents_list <- vector("list", n_agents) for (agent in seq_along(1:n_agents)){ ## initial values of an agent's sampling process fd <- tibble() # state of ignorance p <- .5 # no attention bias s <- 0 # no switching at process initiation init <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) # prospect attended first attend <- init round <- 1 boundary_reached <- FALSE ## agent's sampling process while(boundary_reached == FALSE) { #### sampling round smpl_round <- tibble() while(attend == init) { ##### draw single sample from prospect attended first if(attend == "a") { single_smpl <- gambles[gamble, ] %>% mutate(round = round, attended = attend, A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)) + round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2), B = NA) s <- theta[[set, "s"]] } else { single_smpl <- gambles[gamble, ] %>% mutate(round = round, attended = attend, A = NA, B = b + round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2)) s <- -1*theta[[set, "s"]] } smpl_round <- bind_rows(smpl_round, single_smpl) attend <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) } while(attend != init) { ##### draw single sample from prospect attended second if(attend == "a") { single_smpl <- gambles[gamble, ] %>% mutate(round = round, attended = attend, A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)) + round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2), B = NA) s <- theta[[set, "s"]] } else { single_smpl <- gambles[gamble, ] %>% mutate(round = round, attended = attend, A = NA, B = b + round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2)) s <- -1*theta[[set, "s"]] } smpl_round <- bind_rows(smpl_round, single_smpl) attend <- sample(c("a", "b"), size = 1, prob = c(p + s, p - s)) } ##### compare mean outcomes smpl_round <- smpl_round %>% mutate(A_rmean = cummean2(A, na.rm = TRUE), B_rmean = cummean2(B, na.rm = TRUE), rdiff = A_rmean - B_rmean) smpl_round[[nrow(smpl_round), "A_win"]] <- case_when(smpl_round[[nrow(smpl_round), "rdiff"]] > 0 ~ 1, smpl_round[[nrow(smpl_round), "rdiff"]] <= 0 ~ 0) smpl_round[[nrow(smpl_round), "B_win"]] <- case_when(smpl_round[[nrow(smpl_round), "rdiff"]] >= 0 ~ 0, smpl_round[[nrow(smpl_round), "rdiff"]] < 0 ~ 1) ##### integrate sampling round into frequency distribution fd <- bind_rows(fd, smpl_round) fd[[nrow(fd), "A_sum"]] <- sum(fd[["A_win"]], na.rm = TRUE) fd[[nrow(fd), "B_sum"]] <- sum(fd[["B_win"]], na.rm = TRUE) #### evaluate accumulated evidence if(theta[[set, "boundary"]] == "absolute") { fd <- fd %>% mutate(choice = case_when(A_sum >= theta[[set, "a"]] ~ "A", B_sum >= theta[[set, "a"]] ~ "B")) } else { fd[[nrow(fd), "wdiff"]] <- fd[[nrow(fd), "A_sum"]] - fd[[nrow(fd), "B_sum"]] fd <- fd %>% mutate(choice = case_when(wdiff >= theta[[set, "a"]] ~ "A", wdiff <= -1*theta[[set, "a"]] ~ "B")) } if(is.na(fd[[nrow(fd), "choice"]]) == FALSE) { boundary_reached <- TRUE } else { round <- round + 1 } } agents_list[[agent]] <- expand_grid(agent, fd) } all_agents <- agents_list %>% map_dfr(as.list) gamble_list[[gamble]] <- expand_grid(gamble, all_agents) } all_gambles <- gamble_list %>% map_dfr(as.list) param_list[[set]] <- expand_grid(theta[set, ], all_gambles) } sim_piecewise <- param_list %>% map_dfr(as.list)  linushof committed Jul 12, 2021 535 536 537 538 539 540 541 542 543 544  # store simulation write_rds(sim_piecewise, "./R/data/sim_piecewise.rds") # summarize unique sampling processes summary_piecewise <- sim_piecewise %>% group_by(s, sigma, boundary, a, gamble, agent) %>% mutate(n_sample = n(),  545 546  a_ev_exp = mean(A, na.rm = TRUE), b_ev_exp = mean(B, na.rm = TRUE)) %>%  linushof committed Jul 12, 2021 547 548 549  ungroup() %>% filter(!is.na(choice)) %>% mutate(strategy = "piecewise",  550 551 552 553 554  s = 1-(s+.5), diff = wdiff, n_switch = (round*2)-1) %>% select(!c(attended, A, B, A_rmean, B_rmean, rdiff, A_win, B_win, wdiff)) %>% select(strategy, s:gamble, rare, a_p1:ev_ratio, agent, n_sample, n_switch, A_sum, B_sum, diff, a_ev_exp, b_ev_exp, choice)  linushof committed Jul 12, 2021 555 write_rds(summary_piecewise, "./R/data/summary_piecewise.rds")  linushof committed Jul 02, 2021 556 557   linushof committed Jul 20, 2021 558 ## Summary  559   linushof committed Jul 20, 2021 560 {r eval = FALSE, class.source = "fold-show"}  561 562 563 564 565 sr_data <- bind_rows(summary_comprehensive, summary_piecewise) %>% mutate(across(c(strategy, boundary, a, gamble, agent, rare, choice), as.factor)) # convert to factor write_rds(sr_data, "./R/data/sr_data.rds")   linushof committed Jul 20, 2021 566 # Descriptive Analyses  linushof committed Jul 02, 2021 567   linushof committed Jul 20, 2021 568 Analyses of the generated choice data focuses on the interplay of sampling strategies, different gamble features (e.g. existence and valence of rare outcomes), and parameter combinations in their effects on sample sizes and choice behavior.  linushof committed Jul 12, 2021 569   570 {r}  linushof committed Jul 20, 2021 571 572 573 574 # read summary data set data <- read_rds("./data/sr_data.rds") data <- data %>% filter(!(is.na(a_ev_exp) | is.na(b_ev_exp))) # use only choices in which all prospects were seen  575 576   linushof committed Jul 20, 2021 577 578 579 ## Sample Size Below, median sample sizes of all strategy-parameter combinations (circles) are plotted, ranging from$2 \leq \tilde{x} \leq 162$for piecewise sampling and$3 \leq \tilde{x} \leq 18$for comprehensive sampling.  580 581  {r}  linushof committed Jul 20, 2021 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 data %>% filter(strategy == "piecewise") %>% group_by(boundary, a, s) %>% summarise(group = as.factor(cur_group_id()), med = round(median(n_sample), 0)) %>% ggplot(.) + geom_point(aes(x = reorder(group, med), y = med, color = s, size = a), alpha = .8) + facet_wrap(~boundary) + scale_color_gradient(low = "blue", high = "red") + scale_y_continuous(breaks = seq(0, 170, 10)) + scale_x_discrete(breaks = NULL, expand = expansion(add = 3)) + theme_minimal() + labs(title = "Piecewise Sampling", x ="Strategy-Parameter Combination", y="Sample Size", size="Boundary Value", col="Switching Probability")  598 599 600 601  {r} data %>%  linushof committed Jul 20, 2021 602 603 604 605  filter(strategy == "comprehensive") %>% group_by(boundary, a, s) %>% summarise(group = as.factor(cur_group_id()), med = round(median(n_sample), 0)) %>%  606  ggplot(.) +  linushof committed Jul 20, 2021 607 608 609 610 611 612 613 614 615 616  geom_point(aes(x = reorder(group, med), y = med, color = s, size = a), alpha = .7) + facet_wrap(~boundary) + scale_color_gradient(low = "blue", high = "red") + scale_y_continuous(breaks = seq(0, 25, 1)) + scale_x_discrete(breaks = NULL, expand = expansion(add = 3)) + theme_minimal() + labs(title = "Comprehensive Sampling", x ="Strategy-Parameter Combination", y="Sample Size", size="Boundary Value", col="Switching Probability")  617 618 619 620  ### Boundary value  linushof committed Jul 20, 2021 621 622 623 624 625 626 {r} col_a_p = c("#0302FC", "#A1015D", "#63009E", "#FE0002") col_a_c = c("#0302FC", "#A1015D", "#63009E", "#2A00D5", "#FE0002")  Both sampling strategies show a similiar effect of boundary value on sample size. I.e., large boundary values lead to larger sample sizes.  627 628  {r}  linushof committed Jul 20, 2021 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673  # piecewise med_a <- data %>% filter(strategy == "piecewise") %>% group_by(boundary, a) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "piecewise") %>% group_by(boundary, a, s) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = a, y = med, color = a)) + facet_wrap(~boundary) + geom_jitter(alpha = .5, size = 2) + geom_point(data = med_a, size = 4) + scale_color_manual(values = col_a_p) + labs(title = "Piecewise Sampling", x ="Boundary value", y="Sample Size", col="Boundary Value") + theme_minimal() # comprehensive med_a <- data %>% filter(strategy == "comprehensive") %>% group_by(boundary, a) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive") %>% group_by(boundary, a, s) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = a, y = med, color = a)) + facet_wrap(~boundary) + geom_jitter(alpha = .5, size = 2) + geom_point(data = med_a, size = 4) + scale_color_manual(values = col_a_c) + labs(title = "Comprehensive Sampling", x ="Boundary value", y="Sample Size", col="Boundary Value") + theme_minimal()  674 675 676 677  ### Boundary type  linushof committed Jul 20, 2021 678 For both sampling strategies, relative (as compared to absolute) boundaries lead to larger sample sizes as sequential sampling can either stabilize or reduce a prospects' distance to absolute boundaries while the distance to relative boundaries can also increase.  679 680  {r}  linushof committed Jul 20, 2021 681 682 683 684 685 686 687 688  # piecewise med_a <- data %>% filter(strategy == "piecewise") %>% group_by(boundary, a) %>% summarise(med = round(median(n_sample), 0))  689 data %>%  linushof committed Jul 20, 2021 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723  filter(strategy == "piecewise") %>% group_by(boundary, a, s) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = a, y = med, color = boundary)) + geom_jitter(alpha = .5, size = 2) + geom_point(data = med_a, size = 4) + scale_color_manual(values = col_a_p) + labs(title = "Piecewise Sampling", x ="Boundary value", y="Sample Size", col="Boundary Type") + theme_minimal() # comprehensive med_a <- data %>% filter(strategy == "comprehensive") %>% group_by(boundary, a) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive") %>% group_by(boundary, a, s) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = a, y = med, color = boundary)) + geom_jitter(alpha = .5, size = 2) + geom_point(data = med_a, size = 4) + scale_color_manual(values = col_a_p) + labs(title = "Comprehensive Sampling", x ="Boundary value", y="Sample Size", col="Boundary Type") + theme_minimal()  724 725 726 727  ### Switching probability  linushof committed Jul 20, 2021 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 For piecewise sampling, there is an inverse relationship between switching probability and sample size. I.e., the lower the switching probability, the the less frequent prospects are compared and thus, boundaries are only approached with larger sample sizes. This effect is particularly pronounced for low probabilities such that the increase in sample size accelerates as switching probability decreases. Consequentially, the magnitude of the effect of the boundary value increases. {r} med_s <- data %>% filter(strategy == "piecewise") %>% group_by(boundary, s) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "piecewise") %>% group_by(boundary, s, a) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = s, y = med, color = s, shape = boundary)) + geom_jitter(size = 2, alpha = .5) + geom_point(data = med_s, size = 4) + geom_line(data = med_s) + scale_color_gradient(low = "blue", high = "red") + labs(title = "Piecewise Sampling", x ="Switching Probability", y="Sample Size", col="Switching Probability", shape = "Boundary Type") + theme_minimal()  For comprehensive sampling, boundary types differ in the effects of switching probability. Regarding absolute boundaries, switching probability has no apparent effect on sample size as the distance of a given prospect to its absolute boundary is not changed by switching to (and sampling from) the other prospect. {r} med_s <- data %>% filter(strategy == "comprehensive", boundary == "absolute") %>% group_by(boundary, s) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive", boundary == "absolute") %>% group_by(s, a) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = s, y = med, color = s)) + geom_jitter(size = 2, alpha = .5) + geom_point(data = med_s, size = 4) + geom_line(data = med_s) + scale_color_gradient(low = "blue", high = "red") + labs(title = "Comprehensive Sampling - Absolute Boundary", x ="Switching Probability", y="Sample Size", col="Switching Probability", shape = "Boundary Type") + theme_minimal()  For relative boundaries, switching probability has a more nuanced effect on sample size. Particularly, plotting sample size as a function of switching probability across all gambles produces a somewhat unexpected U-shaped pattern of an inverse relationship for small probabilities and a positive relationship for larger probabilities. {r} med_s <- data %>% filter(strategy == "comprehensive", boundary == "relative") %>% group_by(s) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive", boundary == "relative") %>% group_by(s, a) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = s, y = med, color = s)) + geom_jitter(size = 2, alpha = .5) + geom_point(data = med_s, size = 4) + geom_line(data = med_s) + scale_color_gradient(low = "blue", high = "red") + labs(title = "Comprehensive Sampling - Relative Boundary", x ="Switching Probability", y="Sample Size", col="Switching Probability", shape = "Boundary Type") + theme_minimal()  However, inspecting all gambles separately, one does not observe an U-shaped relation but rather two gamble clusters, one of which shows a positive and the other an inverse relationship. Inspecting the qualitative differences between the gamble features, one finds that the "positive" cluster is indicated by only small differences in the expected value (EV) of prospects ($0.5 \leq \frac{EV_{safe}}{EV_{risky}} \leq 1.5$), whereas the negative" cluster is indicated by larger EV-differences ($0.5 < \frac{EV_{safe}}{EV_{risky}} > 1.5$). Specifically, for gambles (in the gain range), the distance of a given prospect to its relative boundary is probabilistically reduced by switching and sampling from the other prospect. If the EV-difference is low, then frequent switching will lead to a more oscillating behavior of prospects approaching and moving away from the relative border. I.e., for small EV-differences frequent switching reduces the probability that the relative boundary can be reached with the subsequent sample(s) of a given prospect. {r} med_s <- data %>% filter(strategy == "comprehensive", boundary == "relative") %>% filter(ev_ratio >= .5 & ev_ratio <= 1.5) %>% group_by(gamble, s) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive", boundary == "relative") %>% filter(ev_ratio >= .5 & ev_ratio <= 1.5) %>% group_by(gamble, s, a) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = s, y = med, color = s)) + geom_jitter(size = 1, alpha = .5) + geom_point(data = med_s, size = 2) + geom_line(data = med_s) + facet_wrap(~gamble) + scale_color_gradient(low = "blue", high = "red") + scale_y_continuous(limits = c(0, 50)) + labs(title = "Comprehensive Sampling - Relative Boundary - Small EV-Difference", x ="Switching Probability", y="Sample Size", col="Switching Probability", shape = "Boundary Type") + theme_minimal()  In contrast, if the EV-difference is high, small samples are already diagnostic for the difference of prospects, i.e., we do not expect stark oscillation but rather a continuous drift to the boundary of the higher EV-prospect. Consequentially, small switching probabilities may lead to larger samples than is actually required. {r} med_s <- data %>% filter(strategy == "comprehensive", boundary == "relative") %>% filter(ev_ratio < .5 | ev_ratio > 1.5) %>% group_by(gamble, s) %>% summarise(med = round(median(n_sample), 0)) data %>% filter(strategy == "comprehensive", boundary == "relative") %>% filter(ev_ratio < .5 | ev_ratio > 1.5) %>% group_by(gamble, s, a) %>% summarise(med = round(median(n_sample), 0)) %>% ggplot(., aes(x = s, y = med, color = s)) + geom_jitter(size = 1, alpha = .5) + geom_point(data = med_s, size = 2) + geom_line(data = med_s) + facet_wrap(~gamble) + scale_color_gradient(low = "blue", high = "red") + labs(title = "Comprehensive Sampling - Relative Boundary - Large EV-difference", x ="Switching Probability", y="Sample Size", col="Switching Probability", shape = "Boundary Type") + theme_minimal()  ## Choice Behavior and Underweighting Below, in extension to Hills and Hertwig [-@hillsInformationSearchDecisions2010], the interplay of sampling strategies, gambles' features, and model parameters in their effects on choice behavior in general and their contribution to underweighting of rare events in particular is investigated. The working definition of underweighting of rare events is as follows: The rarity of an attractive (unattractive) outcome leads to choose the safe (risky) prospect although the risky (safe) prospect has a higher expected value. ### Interpretation of heatmaps The heatmaps below show the proportions of normatively (i.e., according to the EV-difference) false choices with blueish cells indicating low proportions and redish cells indicating high proportions. For each combination of sampling strategy and boundary type, 6 heatmaps are plotted (3 x 2 grid). The upper panel of each grid shows the proportions of false safe choices and the lower panel of false risky choices. The horizontal grid dimension separates gambles in which the rare outcome ($p <= .2$) of the risky option is either larger (attractive) or smaller (unattractive) than the safe outcome. Accordingly, underweighting of rare events is indicated in the Attractive Rare-False Safe (top left) and the Unattractive Rare-False Risky heatplots (bottom right). Within each heatplot, false response proportions are plotted as a function of the model parameters$s$(switching probability) and$a\$ (boundary value). ### Piecewise sampling As can be seen below, the differences between both boundary types (absolute vs. relative) are rather minor and of magnitude than of qualitative pattern. Therefore, the remaining analyses are aggregated over both boundary types. However, false response proportions across the cell configurations are systematically different. Apparently, the piecewise sampling strategy produces extreme response proportions in either direction, for some configurations generating almost no EV-incoherent decisions (blue areas) and for some almost only EV-incoherent decisions (red areas). Below, possible determinants of these distinct patterns of false response rates are identified. {r} ## Absolute data %>% filter(strategy == "piecewise", boundary == "absolute") %>% mutate(optimal = case_when(ev_ratio > 1 ~ "A", ev_ratio < 1 ~ "B")) %>% group_by(optimal, rare, s, a, choice) %>% summarise(n = n()) %>% mutate(prop = round(n/sum(n), 2)) %>% mutate(kind = case_when(optimal == choice ~ "norm", optimal == "A" & choice == "B" ~ "False Safe", optimal == "B" & choice == "A" ~ "False Risky")) %>% mutate(kind = as.factor(kind)) %>% filter(kind != "norm") %>% ggplot(., aes(x = a, y = s, fill = prop)) + facet_grid(kind~rare, switch = "y") + geom_tile(colour="white",size=0.25) + scale_x_discrete(expand=c(0,0), name = "Boundary Value")+ scale_y_continuous(expand=c(0,0), breaks = seq(.1, 1, .1), name = "Switching Probability")+ scale_fill_gradient(low="blue", high="red") + theme_minimal() + labs(title = "Piecewise Sampling - Absolute Boundary", x = "Boundary Value", y= "Switching Probability", fill = "% False Responses") ## Relative data %>% filter(strategy == "piecewise", boundary == "relative") %>% mutate(optimal = case_when(ev_ratio > 1 ~ "A", ev_ratio < 1 ~ "B")) %>% group_by(optimal, rare, s, a, choice) %>% summarise(n = n()) %>% mutate(prop = round(n/sum(n), 2)) %>% mutate(kind = case_when(optimal == choice ~ "norm", optimal == "A" & choice == "B" ~ "False Safe", optimal == "B" & choice == "A" ~ "False Risky")) %>% mutate(kind = as.factor(kind)) %>% filter(kind != "norm") %>% ggplot(., aes(x = a, y = s, fill = prop)) + facet_grid(kind~rare, switch = "y") + geom_tile(colour="white",size=0.25) + scale_x_discrete(expand=c(0,0), name = "Boundary Value")+ scale_y_continuous(expand=c(0,0), breaks = seq(.1, 1, .1), name = "Switching Probability")+ scale_fill_gradient(low="blue", high="red") + theme_minimal() + labs(title = "Piecewise Sampling - Relative Boundary", x = "Boundary Value", y= "Switching Probability", fill = "% False Responses")  #### Existence and Attractiveness of Rare Events The inversed color gradients from left to right panels indicate that the presence and attractiveness of rare events is a large determinant of false response rates with the direction of the effect dependent on whether the risky or the safe prospect has a higher EV. I.e., consistent with the notion of underweighting, the rarity of an attractive outcome leads to choose the safe prospect although the risky prospect has a higher expected value (top panel). Conversely, the rarity of an unattractive outcome leads to choose the risky prospect although the safe prospect has a higher expected value (bottom panel). Below, this relation is emphasized by plotting the false response proportions against the probability of the unattractive outcome. If the latter increases, the piecewise strategy is more likely to falsely choose the safe option (top panel) but less likely to falsely choose the risky option (bottom panel) - cf. signal-detection-theory. {r} data %>% filter(strategy == "piecewise") %>% mutate(optimal = case_when(ev_ratio > 1 ~ "A", ev_ratio < 1 ~ "B")) %>% group_by(optimal, gamble, a_p1, s, a, choice) %>% summarise(n = n()) %>% mutate(prop = round(n/sum(n), 2)) %>% mutate(kind = case_when(optimal == choice ~ "norm", optimal == "A" & choice == "B" ~ "False Safe", optimal == "B" & choice == "A" ~ "False Risky")) %>% mutate(kind = as.factor(kind)) %>% filter(kind != "norm") %>% ggplot(., aes(x = a_p1, y = prop, color = prop)) + geom_jitter(alpha = .5, size = 2) + scale_color_gradient(low="blue", high="red")+ facet_wrap(~kind, nrow = 2) + labs(title = "Piecewise Sampling", x = "Propability of Unattractive Event", y= "% False responses", color = "% False Responses") + theme_minimal()   963   linushof committed Jul 20, 2021 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 #### Switching Probability and Boundary Value The heatplots and scatterplots indicate that above and beyond the interplay of the rarity and attractiveness of outcomes, there are additional sources of variation of the choice pattern. I.e., within some of the panels of the 3 x 2 grids, especially in those indicative for underweighting, we observe a color gradient from low to high switching probabilities. Precisely, the plots below indicate that rates of false responses in general and underweighting in particular increase if switching probability increases. This is because round-wise comparisons are based on smaller sample sizes for high switching probabilities, pronouncing the effect of rare events described above. {r} data %>% filter(strategy == "piecewise") %>% filter(!(is.na(a_ev_exp) | is.na(b_ev_exp))) %>% mutate(optimal = case_when(ev_ratio > 1 ~ "A", ev_ratio < 1 ~ "B")) %>% group_by(optimal, boundary, rare, s, a, choice) %>% summarise(n = n()) %>% mutate(prop = round(n/sum(n), 2)) %>% mutate(kind = case_when(optimal == choice ~ "norm", optimal == "A" & choice == "B" ~ "False Safe", optimal == "B" & choice == "A" ~ "False Risky")) %>% mutate(kind = as.factor(kind)) %>% filter(kind != "norm") %>% ggplot(., aes(x = s, y = prop, color = prop)) + facet_grid(kind~rare, switch = "y") + geom_jitter(size = 3) + scale_color_gradient(low="blue", high="red") + labs(title = "Piecewise Sampling", x = "Switching Probability", y= "% False responses", color = "% False Responses") + theme_minimal()  The effects of different boundary values are less independent, and therefore relatively nuanced, but in the expexted directions. I.e., in the absence of rare events, larger boundary values (indicating a larger number of rounds that must be won) lead to lower false response proportions - in line with the law of large numbers. In contrast, in the presence of rare events, the influence of the boundary value appears to be rather low, indicating that a larger number of necessary wins does not reduce the underweighting of rare events. I.e., also a larger number of rounds increases the likelihood of a rare event being sampled, the latters magnitude is largely ignored because all rounds are weighted equally.  994 995 996 997  {r} data %>% filter(strategy == "piecewise") %>%  linushof committed Jul 20, 2021 998 999 1000  filter(!(is.na(a_ev_exp) | is.na(b_ev_exp))) %>% mutate(optimal = case_when(ev_ratio > 1 ~ "A", ev_ratio < 1 ~ "B")) %>% `