Skip to content

Commit

Permalink
initial dictator GLMM
Browse files Browse the repository at this point in the history
  • Loading branch information
phelps-sg committed Dec 31, 2023
1 parent c43738c commit f836efd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions jupyter-book/R-MixedModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
results.pd = results.clean[results.clean$Experiment == 'dilemma', ]
results.pd

# %%
results.dictator <- results.clean[results.clean$Experiment == 'dictator', ]
results.dictator

# %%
results.pd$Num_cooperates = round(results.pd$Cooperation_frequency * 6)

Expand All @@ -197,6 +201,25 @@
cat(txt, sep="\n")
}

# %%
results.dictator %>% count(Cooperation_frequency == 1) %>% mutate(prop = n / sum(n))

# %%
results.dictator %>% count(Cooperation_frequency == 0) %>% mutate(prop = n / sum(n))

# %%
results.dictator <- results.dictator %>%
mutate(Cooperation_frequency = ifelse(Cooperation_frequency == 0, 0.001, Cooperation_frequency)) %>%
mutate(Cooperation_frequency = ifelse(Cooperation_frequency == 1, 0.999, Cooperation_frequency))

# %%
model.dictator <- glmmTMB(Cooperation_frequency ~
Participant_group + Participant_group:Model + t + Model + Temperature +
(1|Participant_id),
data = results.dictator,
family = beta_family)
summary(model.dictator)

# %%
model.pd <- glmmTMB(cbind(Num_cooperates, 6 - Num_cooperates) ~
Participant_group + Participant_group:Partner_condition + t + Model + Temperature +
Expand Down Expand Up @@ -313,6 +336,20 @@
dev.off()
pd.predictions.plot

# %%
options(repr.plot.width = 20, repr.plot.height = 10)
dictator.predictions.plot <-
ggplot(ggpredict(model.dictator, c("Participant_group", "Model"))) +
aes(x = x, y = predicted, group = group) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .1,
position = position_dodge(0.06)) +
geom_line(aes(color=group), size = 1) + scale_y_continuous(limits = c(0, 1)) +
scale_color_brewer(palette = "Dark2", direction = -1) +
labs(title = "Dictator",
x = "Participant group", y = "Probability of cooperation") +
theme(legend.position = "bottom")
dictator.predictions.plot

# %%
predictions.for <- function(model, participant.group) {
ggpredict(model.pd.1, c("Partner_condition",
Expand Down

0 comments on commit f836efd

Please sign in to comment.