Skip to content

Commit

Permalink
fixed cooperation-by-group
Browse files Browse the repository at this point in the history
  • Loading branch information
phelps-sg committed Jan 10, 2024
1 parent c2e4132 commit 0fba020
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions jupyter-book/R-MixedModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,46 +385,36 @@ theoretical_dictator <- function(group) {
group == "Cooperative" ~ 0.5,
group == "Competitive" ~ 0,
group == "Altruistic" ~ 1.0,
group == "Control" ~ 0.5
group == "Control" ~ NA
)
}

theoretical_df <- function(
theoretical_df_for_group <- function(
group, fn = function(x) x, experiment = theoretical_dilemma
) {
d <- experiment(group)
theoretical_data(group, fn(d))
}

# %%
groups <- levels(results_pd$Participant_group)
dfs <- lapply(groups, function(g) theoretical_df(g, fn = mean))
hypothesized <- reduce(dfs, rbind)
hypothesized

# %%
dfs <- lapply(
groups,
function(g) theoretical_df(g, fn = mean, experiment = theoretical_dictator)
)
hypothesized_dictator <- reduce(dfs, rbind)
hypothesized_dictator

# %%
names(hypothesized)

# %%
names(hypothesized)[5] <- "Model"
names(hypothesized)[6] <- "x"

# %%
names(hypothesized)
theoretical_df <- function(experiment) {
groups <- levels(results_pd$Participant_group)
dfs <- lapply(
groups,
function(g) theoretical_df_for_group(g, fn = mean, experiment = experiment)
)
hypothesized <- reduce(dfs, rbind)
names(hypothesized)[5] <- "Model"
names(hypothesized)[6] <- "x"
return(hypothesized)
}

# %%
names(pd_predictions)
hypothesized_dilemma <- theoretical_df(experiment = theoretical_dilemma)
hypothesized_dilemma

# %%
c(2:6, 1)
hypothesized_dictator <- theoretical_df(experiment = theoretical_dictator)
hypothesized_dictator

# %%
pd_predictions_poisson <- predictions_by_group(model_pd_poisson)
Expand All @@ -434,19 +424,15 @@ pd_predictions_poisson$conf.high <- pd_predictions_poisson$conf.high / 6
pd_predictions_poisson

# %%
pd_actual_and_theoretical <- function(predictions, h = hypothesized) {
actual_and_theoretical <- function(predictions, h = hypothesized_dilemma) {
rbind(predictions, subset(h, select = c(6, 1:5)))
}

# %%
pd_actual_and_theoretical(pd_predictions)
actual_and_theoretical(pd_predictions)

# %%
pd_predictions

# %%
hypothesized

# %%
predictions_plot <- function(predictions, title) {
ggplot(predictions) +
Expand All @@ -466,7 +452,7 @@ options(repr.plot.width = 20, repr.plot.height = 10)
pdf("figs/pd-predictions.pdf", width = 8, height = 8)
pd_predictions_plot <-
predictions_plot(
pd_actual_and_theoretical(pd_predictions),
actual_and_theoretical(pd_predictions),
"Prisoners Dilemma"
)
dev.off()
Expand All @@ -491,7 +477,7 @@ weighted_dictator <- predictions_dictator %>%
xtable(weighted_dictator, digits = 3)

# %%
predictions_dictator <- pd_actual_and_theoretical(weighted_dictator, h = hypothesized_dictator)
predictions_dictator <- actual_and_theoretical(weighted_dictator, h = hypothesized_dictator)
predictions_dictator

# %%
Expand Down

0 comments on commit 0fba020

Please sign in to comment.