Chimpanzees rationally revise their beliefs
Data files
Oct 03, 2025 version files 5.47 GB
-
All_Analyses.Rmd
103.83 KB
-
Data.zip
22.10 KB
-
Functions.zip
30.48 KB
-
R_Data_Part_1.RData
1.32 GB
-
R_Data_Part_2.RData
4.15 GB
-
README.md
28.43 KB
-
Stan_Models.zip
23.51 KB
-
Unintentional_Cueing_Analysis.zip
66.70 KB
Abstract
The selective revision of beliefs in light of new evidence has been considered one of the hallmarks of human-level rationality. However, tests of this ability in other species are lacking. We examined whether and how chimpanzees (Pan troglodytes) update their initial belief about the location of a reward in response to conflicting evidence. Chimpanzees responded to counter-evidence in ways predicted by a formal model of rational belief revision: they remained committed to their initial belief when the evidence supporting the alternative belief was weaker, but they revised their initial belief when the supporting evidence was stronger. Results suggest that this pattern of belief revision was guided by the explicit representation and weighing of evidence. Taken together, these findings indicate that chimpanzees metacognitively evaluate conflicting pieces of evidence within a reflective process.
Chimpanzees Rationally Revise Their Beliefs
This repository contains data, code, and output for the paper "Chimpanzees Rationally Revise Their Beliefs," published in Science.
For questions or comments, please contact Emily M. Sanford at esanford@berkeley.edu.
Analysis Files
- [
All_Analyses.Rmd]: Contains all analyses for all experiments.- The first chunk in the file specifies the packages that must be installed in R to run the script.
- To run the full analysis, you will need to download [
Functions.zip] and place the unzipped folder in your working directory. - You must also download [
Stan_Models.zip] and place the unzipped folder in your working directory to fit the Bayesian computational models.
- [
R_Data_Part_1.RData] and [R_Data_Part_2.RData]: These two files contain the results of running the [All_Analyses.Rmd] file, which is time consuming to run. These objects can be loaded in the first chunk of [All_Analyses.Rmd] to view the outputs of the analysis without running the entire script.
This repository contains four zip folders:
- [
Data.zip]: .csv files containing all data for all experiments. - [
Functions.zip]: .R files containing auxiliary functions required to run the [All_Analyses.Rmd] file. - [
Stan_Models.zip]: .stan files containing the computational models tested for each experiment. - [
Unintentional_Cueing_Analysis.zip]: Contains sub-folders with box position coding data for each experiment, and the [Unintentional_Cueing_Analysis.Rmd] file to run this control analysis.
The contents of each folder are explained in more detail below.
1. [Data]
- [
experiment_1_data.csv]: Data from Experiment 1Date: Date on which the data were collectedChimpanzee: Subject nameCounterbalance: Order in which the evidence conditions were presented to this subject across trials. There are two possible counterbalancing orders:strong_first_weak_second: This subject was tested in the "strong first" condition (where strong evidence was presented prior to weak evidence) before they were tested in the "weak first" condition (where weak evidence was presented prior to strong evidence)weak_first_strong_second: This subject was tested in the "weak first" condition (where weak evidence was presented prior to strong evidence) before they were tested in the "strong first" condition (where strong evidence was presented prior to weak evidence)
Trial: Trial number for this subject overall (integer, ranges from 1-11)Condition: Indicates the order evidence was presented in on this trialstrong_first: Strong evidence was presented before weak evidence (Trial structure: Strong evidence, Choice 1; Weak evidence, Choice 2)weak_first: Weak evidence was presented before strong evidence (Trial structure: Weak evidence, Choice 1; Strong evidence, Choice 2)filler_strong: Filler trial where the subject was rewarded for their first choice; only strong evidence was presented (Trial structure: Strong evidence, Choice 1)filler_weak: Filler trial where the subject was rewarded for their first choice; only weak evidence was presented (Trial structure: Weak evidence, Choice 1)
First_Choice: Indicates which box (the one supported bystrongorweakevidence) the subject chose on their first choice in that trial- On
fillertrials, the subject chose between the evidence box (eitherstrongorweak, depending on the condition) and a no evidence box (empty)
- On
Second_Choice: Indicates which box (the one supported bystrongorweakevidence) the subject chose on their second choice in that trial- Note: On
fillertrials, subjects only made one choice, so there was noSecond_Choice; this is denoted by a/
- Note: On
Belief_Revision: Indicates whether the subject revised their beliefs (i.e., switched from one option to the other) between theirFirst_ChoiceandSecond_Choice- If
First_Choice=Second_Choice,Belief_Revision=No - If
First_Choice=/=Second_Choice,Belief_Revision=Yes - If there was no
Second_Choice(as onfillertrials),Belief_Revision=/
- If
trialType: Binary variable indicating whether a trial was afillertrial (0) or atesttrial (1)cond: Binary variable indicating whether a trial was in thestrong_firstcondition (1) or theweak_firstcondition (0)choice1: Binary variable indicating whether the subject chose thestrongevidence box (1) or theweakevidence box (0) on their first choicechoice2: Binary variable indicating whether the subject chose thestrongevidence box (1) or theweakevidence box (0) on their second choice; this isNAfor filler trialsbelief_r: Binary variable indicating whether the subject changed their response from choice 1 to choice 2 (1) or gave the same response for both choices (0); this isNAfor filler trialsevidence1: Categorical variable indicating what kind of evidence was presented firstvisual_strong: experimenter turned box around, subject could see food inside through glass paneauditory_weak: experimenter picked up and shook box, subject could hear something moving inside
choice1_ev1: Binary variable indicating whether, at their first choice, the subject chose the box that was supported by the first piece of evidence (1) or they chose the box that had not yet received any evidence (0)trial.per.evidence: Integer variable indicating how many times the subject received that evidence type (strongorweak) as the first piece of evidence (ranges from 1-6)subjID: Numeric subject IDtrial.per.condition: Integer variable indicating trial number for this subject for this condition (ranges from 1-4)- Note:
trial.per.evidenceandtrial.per.conditionare distinct from one another because of thefillertrials. E.g.,trial.per.conditiondifferentiates between thestrong_firstcondition (where subjects received two pieces of evidence and made two choices) from thefiller_strongcondition, where subjects received one piece of evidence and made only one choice.trial.per.evidenceonly corresponds to the first evidence received, sostrong_firstandfiller_strongare categorized together in that variable.
- Note:
- [
experiment_2_data.csv]: Data from Experiment 2. The structure of the data is identical to Experiment 1 (see above), with the following exception:evidence1: Categorical variable indicating what kind of evidence was presented firstauditory_strong: experimenter picked up and shook box, subject could hear something moving inside (equivalent toauditory_weakfrom Experiment 1)visual_weak: experimenter moved boxes to the sides of the table, subject could see a trail of food leading towards the box
- [
experiment_3_data.csv]: Data from both versions of Experiment 3 (Version 1 is included in the main text of the paper, while Version 2 is included in the supplemental materials)Chimpanzee: Subject nameDate: Date on which the data were collectedTrial: Trial number for this subject in this version of Experiment 3 (integer, ranges from 1-8)First.choice: Categorical variable indicating which box the subject chose for their first choice in version 2 onlyNA: Version 1, does not applyS: Box supported by strong evidenceW: Box supported by weak evidenceN: Box supported by no evidence
Second.choice: Categorical variable indicating which box the subject chose for their second choice in version 2 onlyNA: Version 1, does not applyS: Box supported by strong evidenceW: Box supported by weak evidenceN: Box supported by no evidence
choice1: Numeric variable corresponding to the subject's first choice in both versions 1 and 2- Version 1:
1: Box supported by weak evidence0: Box supported by no evidence
- Version 2:
2: Box supported by weak evidence1: Box supported by strong evidence0: Box supported by no evidence
- Version 1:
choice2: Numeric variable corresponding to the subject's second choice in version 2 only1: Subject chose the remaining box supported by the most evidence. If subject chose the strong box (S) at Choice 1, this corresponds to choosing the weak box (W); if they chose the weak (W) or no evidence (N) box at Choice 1, this corresponds to choosing the strong (S) box2: Subject chose the remaining box supported by the least evidence. This indicates that the subject either chose the no evidence (N) box at Choice 2, or that they chose the no evidence box at Choice 1 and the weak box (W) at Choice 2
target: Categorical variable indicating whether the subject chose the two boxes supported by evidence (SandW) in any order for choices 1 and 2yes: Subject choseSfor Choice 1 or 2 andWfor Choice 1 or 2no: Subject choseNfor either Choice 1 or 2
targetN: Binary variable converted fromtarget;yes=1,no=0z.Trial: Continuous variable; z-scaledTrialvariableVersion: Numeric variable with two levels, indicates which version of the experiment this trial belongs to1: Version 1 (included in the main text of the paper) (Trial structure: Subject received strong evidence for one box, weak evidence for a second box, and no evidence for a third box; The strong evidence box was removed; Subject made a single choice)2: Version 2 (included in the supplementary materials of the paper) (Trial structure: Subject received strong evidence for one box, weak evidence for a second box, and no evidence for a third box; Subject made a choice; The box they chose was removed; Subject made a second choice)
subjID: Numeric subject ID
- [
experiment_4_data.csv]: Data from Experiment 4Chimpanzee: Subject namedate: Date on which the data were collectedsession: Each chimpanzee was tested for two days, this variable indicates which of those two days the given trial was collected oncounterbalance: Order in which the evidence conditions were presented to this subject across trials. There are two possible counterbalancing orders:independent_first_then_dependent: This subject was tested in the "independent evidence" condition before they were tested in the "dependent evidence" conditiondependent_first_then_independent: This subject was tested in the "dependent evidence" condition before they were tested in the "independent evidence" condition
trial: Integer, ranging from 1-10. Trial number for this subject for this evidence type, with missing numbers corresponding to filler trials that were not analyzedtrial.2: Integer, ranging from 1-8. Trial number for this subject for this condition (re-numbered to exclude filler trials)condition_name: Indicates what type of evidence was presented on this trialindependent: In theindependentevidence condition, subjects heard the sound of food dropping into the box (Trial structure: Auditory dropping evidence, Visual evidence, Choice 1; Auditory dropping evidence, Choice 2)dependent: In thedependentevidence condition, subjects heard the sound of food rattling around in the box when it was picked up and shaken (Trial structure: Auditory shaking evidence, Visual evidence, Choice 1; Auditory shaking evidence, Choice 2)
First.evidence: Indicates which box (the box on theleftorrightside of the table) was given the first evidenceSecond.evidence: Indicates which box (the box on theleftorrightside of the table) was given the second evidence (will always be opposite fromFirst.evidence)First.choice: Indicates which box the chimpanzee chose at Choice 1 (the box on theleftorrightside of the table)Third.evidence: Indicates which box (the box on theleftorrightside of the table) was given the third evidenceSecond.choice: Indicates which box the chimpanzee chose at Choice 2 (the box on theleftorrightside of the table)Belief.revision: Indicates whether or not the chimpanzee switched choices between Choice 1 and Choice 2 (yesorno)cond: Binary variable indicating whether a trial was in theindependentcondition (0) or thedependentcondition (1)strongSide: Indicates which side (leftorright) received strong (visual) evidencechoice1: Binary variable indicating whether the subject chose the visual evidence box (1) or the auditory (shaking or dropping) evidence box (0) on their first choicechoice2: Binary variable indicating whether the subject chose the visual evidence box (1) or the auditory (shaking or dropping) evidence box (0) on their second choicebelief_r: Binary variable indicating whether the subject changed their response from choice 1 to choice 2 (1) or gave the same response for both choices (0)conditionF: Repeat ofcondition_namevariablesubjID: Numeric subject IDtrial.per.condition: Repeat oftrial.2
- [
experiment_5_data.csv]: Data from Experiment 5Chimpanzee: Subject namedate: Date on which the data were collectedsession: Each chimpanzee was tested for two days, this variable indicates which of those two days the given trial was collected on (with NAs for "defeater alone" trials, which were tested after the main test trials)counterbalance: Order in which the evidence conditions were presented to this subject across trials. There are two possible counterbalancing orders:defeater_first: This subject was tested in the "defeater" condition before they were tested in the "non-defeater" conditionnon_defeater_first: This subject was tested in the "non-defeater" condition before they were tested in the "defeater" conditionNA: Defeater alone trials
all.trials: Integer, ranging from 1-18. Trial number for this subject for this evidence type. Includes filler and failed trials.trial: Character variable indicating the trial number for that condition. Filler trials are indicated by "F_" and "extra_filler." Trials that were cancelled and repeated (because they did not follow the strong evidence initially) are indicated by "failed." Otherwise, trials are numbered from 1 to 8 for thedefeaterandnon_defeaterconditions, and 1-10 for thedefeater_alonecondition.domain: Indicates whether thedefeatedevidence is in thevisualorauditorydomaincondition: Variable indicating trial condition (numeric for test trials)fillerorextra_filler: Filler trial (Trial structure: Strong evidence, Choice 1)failed: Trial failed (terminated and repeated) because subject did not follow strong evidence at choice 11: Defeater condition (Trial structure: Weak evidence, Strong evidence, Choice 1; Defeater for Strong box, Choice 2)0: Non-defeater condition (Trial structure: Weak evidence, Strong evidence, Choice 1; Non-defeater for Strong box, Choice 2)2: Defeater alone condition (Trial structure: Defeater, Choice 1)
first.evidence: Categorical variable indicating what type of evidence was presented first- For test trials in the
visualdomain, this isauditory_shakingevidence - For filler trials in the
visualdomain, this isblurry_visualevidence - For
defeater_alonetrials in thevisualdomain, this is thevisual_defeater(a pane of glass with a sticker of the food on it) - For test trials in the
auditorydomain, this isvisual_traceevidence - For filler trials in the
auditorydomain, this isauditory_shakingevidence - For For
defeater_alonetrials in theauditorydomain, this is theauditory_defeater(a rock that is removed from the box and tapped on its side)
- For test trials in the
first.evidence.side: Indicates which box (the box on theleftorrightside of the table) was given the first evidencesecond.evidence: Categorical variable indicating what type of evidence was presented second- For filler and
defeater_alonetrials, this isNA - For test trials in the
visualdomain, this isblurry_visualevidence - For test trials in the
auditorydomain, this isauditory_shakingevidence
- For filler and
second.evidence.side: Indicates which box (on theleftorrightside of the table) was given the second evidence- This is
NAfor filler &defeater_alonetrials
- This is
first.choice: Categorical variable indicating which side the chimpanzee chose in Choice 1 (leftorright)third.evidence: Categorical variable indicating what type of evidence was presented third- For filler &
defeater_alonetrials, this isNA - For test trials in the
visualdomain, this is thevisual_defeater(defeatercondition) orvisual_non_defeater(non_defeatercondition) - For test trials in the
auditorydomain, this is theauditory_defeater(defeatercondition) orauditory_non_defeater(non_defeatercondition)
- For filler &
third.evidence.side: Indicates which box (leftorright) was given the third evidence- This is
NAfor filler &defeater_alonetrials
- This is
second.choice: Categorical variable indicating which side the chimpanzee chose in Choice 2 (leftorright)- This is
NAfor filler &defeater_alonetrials
- This is
food.received: Categorical variable indicating whether the chimpanzee was rewarded (yesorno) at the end of this trialbelief.revision: Indicates whether or not the chimpanzee switched choices between Choice 1 and Choice 2 (yes,no, orNAif there were not two choices on this trial)alone: Indicates whether the trial was in thedefeater_alonecondition (yesorno)condition_name: Categorical variable indicating condition for test trials &defaeter_alonetrials only (defeaterornon-defeater)defeatedSide: Categorical variable indicating which side (leftorright) receiveddefeaterornon-defeaterevidencedefeatedTime: Categorical variable indicating whether thefirst(defeater_alonetrials only) orsecond(defeaterandnon-defeaterconditions) evidence presented on this trial was defeatedchoice1: Binary variable indicating whether the subject chose the strong evidence box (0) or the weak evidence box (1) on their first choice- For the
defeater_alonecondition, this is1for the side that did not receive the defeater and0for the side that did receive the defeater
- For the
choice2: Binary variable indicating whether the subject chose the strong evidence box (0) or the weak evidence box (1) on their second choicebelief_r: Binary variable indicating whether the subject changed their response from choice 1 to choice 2 (1) or gave the same response for both choices (0)subjID: Numeric subject IDconditionF: Categorical variable indicating whether the trial was in thedefeater,non-defeater, ordefeater_alonecondition (blank for trials that were not included in the main analyses)trial.per.condition: Numerical variable indicating trial # (within condition) for that chimpanzee
2. [Functions]
- [
fitting_and_plotting_functions.R]: Contains organizing functions to fit all GLMs and Stan models, and to generate all plotsinv_logit: Defines inverse logit functionglm_prep: Takes inputs of data, formula for GLM, list of dummy variable(s), and name of "trial" variable; Returns list containing summary of fixed and random effects, and data in correct format for the specified GLMglm_assumptions: Takes input of GLM model; Returns list containing results of model assumption checks (overdispersion, variance inflation factor if vif=T, and stability)glm_bootstraps: Takes inputs of model, desired number of bootstraps, and variables to include; Returns bootstrapped resultsglm_many_models: Executes the '100 altered models' analysis used for models with complete separation issues (Experiment 1 - 2nd choice GLMs, Full Analysis GLMs; Experiment 2 - 2nd Choice GLMs); Fits N models, perturbing the problematic data by a small amount each time, then compiles the average results from these models to estimate the true model values- Inputs: N = # models (default = 100), n_boots = # bootstraps (default = 10), model_data = data to be used in models, cells_to_change = list of problematic conditions, response_var = name of response variable, store_df = dataframe object to store analysis results
- Returns a list containing:
- Number of models that converged (out of N)
- Dataframe containing model information for all perturbed models
- Dataframe of model comparisons (for all N perturbations)
- Dataframe of averaged coefficients across all N full models
- List of dataframes containing bootstraps for all models
fit_stan_models: Fits specified computational models for each experiment- Inputs: data and experiment number (to determine which models to run)
- Converts data to correct form for the specified models
- Fits all Bayesian models for that experiment:
- Experiments 1 & 2: Rational Choice, Belief Perseveration, Recency Bias, Cue Saliency, Null
- Experiments 3 & 4: Rational Choice, Cue Saliency, Null
- Experiment 5: Rational Choice, D Alone, Cue Saliency, Null
- Outputs: List containing Stan fit objects and log likelihoods for all fitted models
med_post_lik: Takes log likelihood object from Stan fit, returns median posterior log likelihood for that modelcollate_med_post_lik: Takes list of LLs for multiple models, returns DF containing median posterior likelihoods for those modelsextract_params: Takes inputs of Stan model fit objects, subject names, model names, and a list containing lists of parameters in each model; Returns dataframe containing best-fitting parameters for all subjects for all modelsplot_halfViolin: Returns a half-violin plot with subject points and CIs- Inputs: data, xvar = variable for x-axis, yvar = variable for y-axis, colvar = variable for coloring, model_ci = dataframe containing model CIs, levels = levels of x variable, plotlabels = labels to be displayed for each level of x variable, beginCol = value to start color scale, endCol = value to end color scale, ylim = y-axis limits (default = c(0,1)), ylab = label for y-axis (default = "% following evidence"), jitterWidth = amount to jitter x-values (default = 0), adjust.width = binary value indicating whether half-violin needs to be moved to the side to make room for all subject points (default = F)
plot_sigmoid: Returns a plot containing a sigmoid (cumulative gaussian) with overlaid points representing subject and average fitted evidence strengths for each evidence type- Inputs: dataframe containing parameter fits, dataframe containing CIs from parameter fits
- Note: Only used for Experiments 1 & 2, so the parameters are fixed to eStrong & eWeak
- [
storage_objects.R]: Contains code that generates empty dataframes to store the results of the '100 altered models' analyses for Experiment 1 (2nd choice GLMs, Full Analysis GLMs) and Experiment 2 (2nd Choice GLMs)
The following functions in the [Functions] folder were written by Roger Mundry (RMundry@dpz.eu).
- [
boot_glm.r]: Contains function [boot.glmm.pred] to run bootstraps to fit confidence intervals for model estimates and predicted values - [
diagnostic_fcns.r]: Contains functions to perform diagnostics for evaluating GLM assumptions and stabilityranef.diagn.plot: Generates a random effect diagnostic plotoverdisp.test: Overdispersion testfe.re.tab: Fixed/random effects table, which helps to determine which random slopes are neededm.stab.plot: Plot model stability or CIs
- [
glmm_stability.r]: Contains function [glmm.model.stab] to calculate model stability by removing one individual at a time and fitting the model again; The output shows the range of estimates
3. [Stan_Models]
- Experiments 1 and 2:
- [
rational_model_exp1_2.stan]: Rational Choice Model. Assumes that b1 (i.e., the subject's belief at Choice 1) is a function of the first evidence, b2 is a function of the sum of the first evidence + second evidence - [
cue_model_exp1_2.stan]: Cue Saliency Model. Assumes that b1 is a function of the first evidence, b2 is a function of only the stronger of the first and second evidence - [
persev_model_exp1_2.stan]: Belief Perseveration Model. Assumes that b1 and b2 are both functions of the first evidence only - [
recency_model_exp1_2.stan]: Recency Bias Model. Assumes that b1 is a function of the first evidence, b2 is a function of the second evidence only - [
null_model_exp1_2.stan]: Null Model. Assumes that neither choice is driven by evidence
- [
- Experiment 3:
- Experiment 3.1:
- [
rational_model_exp3_v1.stan]: Rational Choice Model. Assumes that choice is driven by weak evidence alone - [
null_model_exp3_v1.stan]: Null Model. Assumes that choice is not based on evidence
- [
- Experiment 3.2:
- [
rational_model_exp3_v2.stan]: Rational Choice Model. Assumes that b1 is based on the sum of evidence for 3 options, b2 is based on the sum of the evidence for the remaining 2 options - [
cue_model_exp3_v2.stan]: Cue Saliency Model. Assumes that b1 is based on the strong evidence, and b2 is a coin flip (if the strong box was chosen first) or only on the strong evidence (if the strong box was not chosen first) - [
null_model_exp3_v2.stan]: Null Model. Assumes that choices are not based on evidence
- [
- Experiment 3.1:
- Experiment 4:
- [
rational_model_exp4.stan]: Rational Choice Model. Assumes that b1 is a function of the sum of the first two evidences, and that b2 is a function of b1 + the third evidence, but only in the New (independent) evidence condition - [
cue_model_exp4.stan]: Cue Saliency Model. Assumes that b1 and b2 are both functions of the stronger of the first two evidences - [
null_model_exp4.stan]: Null Model. Assumes that choices are not based on evidence
- [
- Experiment 5:
- [
rational_model_exp5.stan]: Rational Choice Model. Assumes that b1 is a function of the sum of the first two evidences, and that b2 is a function of b1 + the defeater (which will negate the strong evidence in the defeating condition only) - [
d_alone_model_exp5.stan]: Defeater Alone Model. Fit to trials from thedefeater alonecondition only; Assumes that the b1 is a function of the defeater when presented alone (i.e., without first-order evidence) - [
cue_model_exp5.stan]: Cue Saliency Model. Assumes that b1 and b2 are both functions of the stronger of the first two evidences - [
null_model_exp5.stan]: Null Model. Assumes that choices are not based on evidence
- [
4. [Unintentional_Cueing_Analysis]
- [
Experiment 1] through [Experiment 5]: Folders containing box coding data for each experiment- [
..._Coding.csv]: Coder #1's judgment for which box is closer - Left (L), Right (R), or Same distance (S) - for every choice in the given experiment - [
..._Reliability.csv]: Coder #2's judgments on a random 20% of choices for each experiment - [
..._Image_Key.csv]: File used to link blind coding with the experimental data
- [
- [
Unintentional_Cueing_Analysis.Rmd]: File to run Unintentional Cueing Analysis (Did chimpanzees pick the box that was closest to them, rather than the box that had received more evidence?)- Lines 6-616: Import and clean data, add condition information to determine which box had received more evidence at the time of each choice, and compiles all experiments into a single data frame for meta-analysis
- Lines 618-741: Unintentional cueing analysis, collapsed across all experiments
- Lines 743-1293: Unintentional cueing analysis, separately for each experiment
- Lines 1295-1439: Compiled results and plots for reliability and unintentional cueing analyses. You can run the entire script, then view all results together in these three final chunks.
