This is the file with the results ofthe El Farol Bar Problem Simulation (Arthur, 1994)
last_simulation_file <- system("ls -t runs/ |head -n1", intern = TRUE)
runs_dir = "runs/"
sim_results <- read.csv(file.path(runs_dir,last_simulation_file))
attendance <- sim_results %>% group_by(run, step, my_play) %>%
count(my_play)
ggplot(data=subset(attendance, my_play == "GOING"), aes(x = step, y = n)) + geom_line()
ggplot(sim_results, aes(predictor_prediction, predictor_fitness, color = my_play)) + geom_point()
ggplot(sim_results, aes(predictor_prediction, predictor_fitness, color = selected_predictor)) + geom_point()
ggplot(sim_results, aes(predictor_prediction, predictor_fitness, color = selected_predictor)) + geom_point() + facet_grid(cols = vars(my_play))
ggplot(data=sim_results, aes(x = predictor_prediction, color = selected_predictor)) + geom_density()
ggplot(data=sim_results, aes(x = predictor_prediction, y = predictor_fitness, color = my_play)) + geom_point()
ggplot(data=sim_results, aes(x = log(predictor_fitness), color = selected_predictor)) + geom_density()
## Warning: Removed 50 rows containing non-finite values (stat_density).
ggplot(data=attendance, aes(x = n, color = my_play)) + geom_density()
ggplot(data=attendance, aes(x = my_play, y = n)) + geom_violin()
ggplot(sim_results, aes(color = selected_predictor, x=log(predictor_fitness))) + geom_density()
## Warning: Removed 50 rows containing non-finite values (stat_density).
predictors <- sim_results %>% group_by(run, step, selected_predictor) %>%
summarise(fitness = mean(predictor_fitness, na.rm = TRUE),
mean_prediction = mean(predictor_prediction, na.rm = TRUE),
median_prediction = median(predictor_prediction, na.rm = TRUE),
n = n()
)
## `summarise()` regrouping output by 'run', 'step' (override with `.groups` argument)
ggplot(predictors, aes(x = step, y = log(fitness), color = selected_predictor)) + geom_line()
ggplot(predictors, aes(x = step, y = mean_prediction, color = selected_predictor)) + geom_line()
ggplot(predictors, aes(x = step, y = mean_prediction, color = selected_predictor)) + geom_line() + facet_grid(rows = vars(selected_predictor))
ggplot(predictors, aes(x = step, y = mean_prediction, color = factor(selected_predictor))) + facet_grid(rows = vars(selected_predictor)) +
geom_ribbon(aes(ymin = mean_prediction - 10, ymax = mean_prediction + 10, group = selected_predictor), fill = "grey70") + geom_line()
ggplot(predictors, aes(x = step, y = median_prediction, color = selected_predictor)) + geom_line()
ggplot(predictors, aes(x = step, y = n, color = selected_predictor)) + geom_line()
frequencies <- pivot_wider(attendance, names_from = my_play, values_from = n)
freq_names = c("run", "step", "going","not_going")
colnames(frequencies) <- freq_names
frequencies_df <- as.data.frame(frequencies)
frequencies_df$last_going = shift(frequencies_df$going, fill = NA, type = "lag")
frequencies_df$last_not_going = shift(frequencies_df$not_going, fill = NA, type = "lag")
ggplot(frequencies_df, aes(going, last_going)) + geom_tile(aes(fill = going))
## Warning: Removed 1 rows containing missing values (geom_tile).
ggplot(frequencies_df, aes(not_going, last_not_going)) + geom_tile(aes(fill = not_going))
## Warning: Removed 21 rows containing missing values (geom_tile).