File: winke_stevens_2017_rcode.R

Comment: Subset data that includes only partner cooperation means within 0.4  0.6
Category: Data Variable
Code:
bound_data <- subset(expt1_data, expt1_data$cooplc_means >= 0.4 & expt1_data$cooplc_means <= 0.6 & expt1_data$readlc_means >= 0.4 & expt1_data$readlc_means <= 0.6)

Comment: Plot histogram of chances that partner's choice was positive for all data
Category: Visualization
Code:
coop_hist_ggplot <- ggplot(all_pc, aes(x = alllc_means * 100)) + geom_histogram(aes(fill = included), bins = 50) +  # plot histogram scale_fill_manual(values = c("black", "grey50"), name="", label=c("Included", "Not included")) +  # color values inside and outside of 0.4-0.6 differently labs(x = "Percent partner positive actions", y = "Number of participants") + # label axes theme_classic() + # use classic theme theme(axis.title=element_text(size=45), axis.text=element_text(size=30), legend.text=element_text(size=30), legend.position = c(0.25, 0.9), legend.key.size = unit(2.5, 'lines')) png(file = "figures/partner_action_histogram.png", width = 1200, height = 750) # open device plot(coop_hist_ggplot) # plot figure dev.off() # close device

Comment:   Analyze accuracy as a function of payoff scheme (Standard or Costly), context (Cooperation or Newspaper), and partner action (Cooperate or Defect)   Conduct binomial GLMM of payoff scheme * partner action + context for memory accuracy 
Category: Statistical Modeling
Code:
accuracy_glmer_full <- glmer(accuracy ~ payoff_scheme * partner_action * context + (1 | subject), bound_data, family = binomial(link = "logit"))   # calculate GLMM of full model

Comment: Conduct binomial GLMMs for memory accuracy to calculate BIC values to transform to Bayes factors
Category: Statistical Modeling
Code:
accuracy_glmer_null <- summary(glmer(accuracy ~ (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for null model accuracy_glmer_payoff <- summary(glmer(accuracy ~ payoff_scheme  + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for payoff scheme accuracy_glmer_context <- summary(glmer(accuracy ~ context + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for context accuracy_glmer_action <- summary(glmer(accuracy ~ partner_action + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for partner action accuracy_glmer_payoff_action <- summary(glmer(accuracy ~ payoff_scheme + partner_action + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for payoff_scheme + partner_action accuracy_glmer_payoff_action_inter <- summary(glmer(accuracy ~ payoff_scheme * partner_action + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for payoff_scheme * partner_action accuracy_glmer_action_context <- summary(glmer(accuracy ~ partner_action + context + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for partner_action + context accuracy_glmer_action_context_inter <- summary(glmer(accuracy ~ partner_action * context + (1 | subject), bound_data, family = binomial(link = "logit")))    # calculate GLMM for partner_action * context accuracy_glmer_payoff_action_context <- summary(glmer(accuracy ~ payoff_scheme + partner_action + context + (1 | subject), bound_data, family = binomial(link = "logit")))   # calculate GLMM for payoff_scheme * partner_action * context last_accuracy_glmer_null <- summary(glmer(accuracy ~ (1 | subject), last_data, family = binomial(link = "logit")))    # calculate GLMM for null model last_accuracy_glmer_payoff <- summary(glmer(accuracy ~ payoff_scheme  + (1 | subject), last_data, family = binomial(link = "logit")))    # calculate GLMM for payoff scheme last_accuracy_glmer_action <- summary(glmer(accuracy ~ partner_action + (1 | subject), last_data, family = binomial(link = "logit")))    # calculate GLMM for partner action last_accuracy_glmer_payoff_action <- summary(glmer(accuracy ~ payoff_scheme + partner_action + (1 | subject), last_data, family = binomial(link = "logit")))    # calculate GLMM for payoff_scheme + partner_action last_accuracy_glmer_payoff_action_inter <- summary(glmer(accuracy ~ payoff_scheme * partner_action + (1 | subject), last_data, family = binomial(link = "logit")))    # calculate GLMM for payoff_scheme * partner_action

Comment: Conduct binomial GLMM of payoff scheme * partner action + context for memory accuracy
Category: Statistical Modeling
Code:
last_accuracy_glmer_full <- glmer(accuracy ~ payoff_scheme * partner_action + (1 | subject), last_data, family = binomial(link = "logit"))   # calculate GLMM of full model

Comment: Calculate correlation between mean number of contacts and mean memory accuracy
Category: Statistical Test
Code:
coop_contacts_cor2 <- cor.test(expt2_data_subj$accuracy, expt2_data_subj$contacts)  # calculate network size/accuracy correlation coop_contacts2_bfdf <- data.frame(accuracy = expt2_data_subj$accuracy, contacts = expt2_data_subj$contacts) # create new data frame for Bayesian analysis coop_contacts2_lmbf <- lmBF(accuracy ~ contacts, data = coop_contacts2_bfdf)  # calculate Bayes regression coop_contacts2_bf <- extractBF(coop_contacts2_lmbf)$bf  # extract Bayes factor