Commit da47843a authored by linushof's avatar linushof
Browse files

Implement unnoisy sampling

parent 53f8520e
# load packages
pacman::p_load(tidyverse)
source("R/fun_cumulative_stats.R") # call functions for computing cumulative stats
# gambles and parameters
gambles <- read_csv("./R/data/gambles/sr_subset.csv")
gambles <- read_csv("data/gambles/sr_subset.csv")
n_agents <- 100
theta <- 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
a = c(1, 3, 5, 7)) # boundaries piecewise
a = c(1, 3, 5, 7)) # boundaries (number of required wins)
# simulation
source("./R/functions/fun_cumulative.R") # call functions for computing cumulative sums and means
set.seed(8739)
param_list <- vector("list", length(nrow(theta)))
for (set in seq_len(nrow(theta))) { # loop over parameter combinations
......@@ -24,7 +19,7 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
agents_list <- vector("list", n_agents)
for (agent in seq_along(1:n_agents)){ # loop over agents
## initial values of an agent's sampling process
## initial values of an agent's sampling process (unique trial)
fd <- tibble() # state of ignorance
p <- .5 # no attention bias
......@@ -49,8 +44,7 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
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), # add gaussian noise
A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)),
B = NA)
s <- theta[[set, "s"]]
} else {
......@@ -58,8 +52,7 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
mutate(round = round,
attended = attend,
A = NA,
B = b +
round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2))
B = b_o1)
s <- -1*theta[[set, "s"]]
}
smpl_round <- bind_rows(smpl_round, single_smpl)
......@@ -74,8 +67,7 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
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),
A = sample(x = c(a_o1, a_o2), size = 1, prob = c(a_p1, 1-a_p1)),
B = NA)
s <- theta[[set, "s"]]
} else {
......@@ -83,8 +75,7 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
mutate(round = round,
attended = attend,
A = NA,
B = b +
round(rnorm(1, mean = 0, sd = theta[[set, "sigma"]]), 2))
B = b_o1)
s <- -1*theta[[set, "s"]]
}
smpl_round <- bind_rows(smpl_round, single_smpl)
......@@ -135,5 +126,4 @@ for (set in seq_len(nrow(theta))) { # loop over parameter combinations
param_list[[set]] <- expand_grid(theta[set, ], all_gambles)
}
sim_piecewise <- param_list %>% map_dfr(as.list)
write_csv(sim_piecewise, "./R/data/simulation/sim_piecewise.csv")
write_csv(sim_piecewise, "data/simulation/sim_piecewise.csv")
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