Skip to content

Commit 0d56add

Browse files
authored
Add files via upload
1 parent 6843262 commit 0d56add

14 files changed

+100
-50
lines changed

ABMmodels_intro.Rmd

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output: pdf_document
66

77
# Introduction
88

9-
This tutorial shows how to create very simple simulation or agent-based models of cultural evolution in R (R Core Team 2021). It uses the RStudio notebook or RMarkdown (.Rmd) format, allowing you to execute code as you read the explanatory text. Each model is contained in a separate RMarkdown file which you should open in RStudio. Currently these are:
9+
This tutorial shows how to create very simple simulation or agent-based models of cultural evolution in R (R Core Team 2021). Currently these are:
1010

1111
* Model 1: Unbiased transmission
1212
* Model 2: Unbiased and biased mutation
@@ -21,6 +21,10 @@ This tutorial shows how to create very simple simulation or agent-based models o
2121
* Model 11: Cultural group selection
2222
* Model 12: Historical dynamics
2323

24+
## How to use this tutorial
25+
26+
Each model is contained in a separate RMarkdown (Rmd) file. You can either (i) download each of these Rmd files from https://github.com/amesoudi/cultural_evolution_ABM_tutorial then open them in RStudio or another IDE, executing the code as you read the explanatory text, or (ii) read the online version of the tutorial at https://bookdown.org/amesoudi/ABMtutorial_bookdown/, copying and pasting the code into RStudio as you go.
27+
2428
I assume you have basic knowledge of R as a programming language, e.g. the use of variables, dataframes, functions, subsetting and loops. If not, *Hands On Programming With R* by Garrett Grolemund is a good introduction.
2529

2630
I'm putting all model parameters in italicised $equation$ text. This allows useful features such as superscripts (e.g. $x^y$) and subscripts (e.g. $x_{t=1}$). Hover the cursor over the equation text to see this in RStudio. All code variables are in regular *italics*, and all commands and functions in **bold**.
@@ -32,6 +36,17 @@ All the concepts covered here are introduced, discussed and mathematically model
3236
Each chapter has some exercises with suggestions for how to fully explore the models and extend the models in interesting ways. Each chapter also has an 'Analytic Appendix', where I show how to derive the same results analytically.
3337

3438

39+
## How to cite this tutorial
40+
41+
You can cite the tutorial as:
42+
43+
* Mesoudi, Alex (2021) *Simulation models of cultural evolution in R*. doi:10.5281/zenodo.5155821. Available at https://github.com/amesoudi/cultural_evolution_ABM_tutorial and https://bookdown.org/amesoudi/ABMtutorial_bookdown/.
44+
45+
A longer and more detailed book-length resource, which builds on some of these models, can be found here:
46+
47+
* Alberto Acerbi, Alex Mesoudi, and Marco Smolla (2020) *Individual-based models of cultural evolution. A step-by-step guide using R*. doi:110.31219/osf.io/32v6a. Available at: https://acerbialberto.com/IBM-cultevo/
48+
49+
3550
## What is cultural evolution?
3651

3752
The theory of evolution is typically applied to genetic change. Darwin pointed out that the diversity and complexity of living things can be explained in terms of a deceptively simple process. Organisms vary in their characteristics. These characteristics are inherited from parent to offspring. Those characteristics that make an organism more likely to survive and reproduce will tend to increase in frequency. That's pretty much it. Since Darwin, biologists have filled in many of the details of this abstract idea. Geneticists have shown that 'characteristics' are determined by genes, and worked out where genetic variation comes from (e.g. mutation, recombination) and how genetic inheritance works (e.g. via Mendel's laws, and DNA). The details of selection have been explored, revealing the many reasons why some genes spread and others don't. Others realised that not all biological change results from selection, it can also result from random processes like population bottlenecks (genetic drift).

ABMmodels_model01_unbiased_transmission.Rmd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ output: pdf_document
66

77
# Model 1: Unbiased transmission
88

9+
## Introduction
10+
911
Here we will simulate perhaps the simplest possible case of cultural evolution. We assume $N$ individuals each of whom possesses one of two cultural traits, denoted $A$ and $B$. Each generation, the $N$ agents are replaced with $N$ new agents. Each new agent picks a member of the previous generation at random and copies their cultural trait. This is known as unbiased oblique cultural transmission: unbiased because traits are copied entirely at random, and oblique because one generation learns from the previous non-overlapping generation (as opposed to horizontal cultural transmission where individuals copy members of the same generation, and vertical cultural transmission where offspring copy their parents - our model is way too simple to have actual parents and offspring though).
1012

1113
We are interested in tracking the proportion of individuals who possess trait $A$ over successive generations. We will call this proportion $p$. We could also track the proportion who possess trait $B$, but this will always be $1 - p$ given that everyone who does not possess $A$ must possess $B$, so there is really no need. For example, if 70% of the population have trait $A$, then $p = 0.7$. The remaining 30% must have trait $B$, which is a proportion $1 - p = 1 - 0.7 = 0.3$.
1214

1315
The output of the model will be a plot showing $p$ over all generations (or timesteps) up to the last generation. Generations are denoted by $t$, where generation one is $t = 1$, generation two is $t = 2$, up to the last generation $t = t_{max}$. These could correspond to biological generations, but could equally be 'cultural generations' (or learning episodes) within the same fixed population, which would be much shorter.
1416

17+
## Model 1: Unbiased transmission
18+
1519
First we need to specify the fixed parameters of the model. These are $N$ (the number of individuals) and $t_{max}$ (the number of generations). Let's start with $N = 100$ and $t_{max} = 200$.
1620

1721
```{r}
@@ -362,7 +366,7 @@ invisible(dev.off())
362366

363367
***
364368

365-
# Summary of Model 1
369+
## Summary
366370

367371
Even this extremely simple model provides some valuable insights. First, unbiased transmission does not in itself change trait frequencies. As long as populations are large, trait frequencies remain the same.
368372

@@ -374,7 +378,7 @@ In Model 1 we have introduced several programming techniques that will be useful
374378

375379
***
376380

377-
# Exercises
381+
## Exercises
378382

379383
1. Try different values of $p_0$ with large $N$ to confirm that unbiased transmission does not change the frequency of $p$, irrespective of the starting value $p_0$.
380384

@@ -384,7 +388,7 @@ In Model 1 we have introduced several programming techniques that will be useful
384388

385389
***
386390

387-
# Analytical Appendix
391+
## Analytical Appendix
388392

389393
If $p$ is the frequency of $A$ in one generation, we are interested in calculating $p'$, the frequency of $A$ in the next generation under the assumption of unbiased transmission. Each new individual in the next generation picks a demonstrator at random from amongst the previous generation. The demonstrator will have $A$ with probability $p$. The frequency of $A$ in the next generation, then, is simply the frequency of $A$ in the previous generation:
390394

@@ -421,7 +425,7 @@ More generally, creating deterministic recursion-based models can be a good way
421425

422426
***
423427

424-
# References
428+
## References
425429

426430
Bentley, R. A., Hahn, M. W., & Shennan, S. J. (2004). Random drift and culture change. Proceedings of the Royal Society of London B, 271(1547), 1443-1450.
427431

ABMmodels_model02_mutation.Rmd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ author: "Alex Mesoudi"
44
output: pdf_document
55
---
66

7-
87
# Model 2: Unbiased and biased mutation
98

9+
## Introduction
10+
1011
Evolution doesn't work without a source of variation that introduces new variation upon which selection, drift and other processes can act. In genetic evolution, mutation is almost always blind with respect to function. Beneficial genetic mutations are no more likely to arise when they are needed than when they are not needed - in fact most genetic mutations are neutral or detrimental to an organism. Cultural evolution is more interesting, in that novel variation may sometimes be directed to solve specific problems, or systematically biased due to features of our cognition. In the models below we'll simulate both unbiased and biased mutation.
1112

1213

@@ -252,7 +253,7 @@ Now trait $A$ reaches fixation around generation $t = 50$. Play around with $N$
252253

253254
***
254255

255-
# Summary of Model 2
256+
## Summary
256257

257258
With this simple model we can draw the following insights. Unbiased mutation, which resembles genetic mutation in being non-directional, always leads to an equal mix of the two traits. It introduces and maintains cultural variation in the population. It is interesting to compare unbiased mutation to unbiased transmission from Model 1. While unbiased transmission did not change $p$ over time, unbiased mutation always converges on $p^* = 0.5$, irrespective of the starting frequency. (NB $p^* = 0.5$ assuming there are two traits; more generally, $p^* = 1/v$, where $v$ is the number of traits.)
258259

@@ -264,7 +265,7 @@ In terms of programming techniques, the major novelty in Model 2 is the use of *
264265

265266
***
266267

267-
# Exercises
268+
## Exercises
268269

269270
1. Try different values of $p_0$ in **UnbiasedMutation** to confirm that any starting value converges on approximately $p=0.5$.
270271

@@ -280,7 +281,7 @@ In terms of programming techniques, the major novelty in Model 2 is the use of *
280281

281282
***
282283

283-
# Analytical Appendix
284+
## Analytical Appendix
284285

285286
If $p$ is the frequency of $A$ in one generation, we are interested in calculating $p'$, the frequency of $A$ in the next generation under the assumption of unbiased mutation. The next generation retains the cultural traits of the previous generation, except that $\mu$ of them switch to the other trait. There are therefore two sources of $A$ in the next generation: members of the previous generation who had $A$ and didn't mutate, therefore staying $A$, and members of the previous generation who had $B$ and did mutate, therefore switching to $A$. The frequency of $A$ in the next generation is therefore:
286287

@@ -366,7 +367,7 @@ Second, it says that the rate of increase is proportional to $\mu_b$. This expla
366367

367368
***
368369

369-
# References
370+
## References
370371

371372
Eerkens, J. W., & Lipo, C. P. (2005). Cultural transmission, copying errors, and the generation of variation in material culture and the archaeological record. Journal of Anthropological Archaeology, 24(4), 316-334.
372373

ABMmodels_model03_direct_bias.Rmd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ author: "Alex Mesoudi"
44
output: pdf_document
55
---
66

7-
# Model 3: Biased transmission (direct/content bias)
7+
# Model 3: Biased transmission (direct / content bias)
8+
9+
## Introduction
810

911
So far we have looked at unbiased transmission (Model 1) and unbiased/biased mutation (Model 2). Let's complete the set by looking at biased transmission. This occurs when one trait or one demonstrator is more likely to be copied than another trait or demonstrator. Trait-based copying is often called 'direct' or 'content' bias, while demonstrator-based copying is often called 'indirect' or 'context' bias. Both are sometimes also called 'cultural selection' because one thing (trait or demonstrator) is selected to be copied over another. In Model 3 we'll look at trait-based (direct, content) bias.
1012

1113
(As an aside, there is a confusing array of terminology in the field of cultural evolution, as illustrated by the preceding paragraph. That's why models are so useful. Words and verbal descriptions can be ambiguous. Often the writer doesn't realise that there are hidden assumptions or unrecognised ambiguities in their descriptions. They may not realise that what they mean by 'cultural selection' is entirely different to how someone else uses it. Models are great because they force us to specify exactly what we mean by a particular term or process. I can use the words in the paragraph above to describe biased transmission, but it's only really clear when I model it, making all my assumptions explicit.)
1214

15+
## Model 3: Direct / content bias
16+
1317
As in Models 1 and 2, we assume there are two traits $A$ and $B$. Let's assume that biased transmission favours trait $A$. Perhaps $A$ is a more effective tool, more memorable story, or more easily pronounced word. We're not including any mutation in the model, so we need to include some $A$s at the beginning of the simulation otherwise it would never appear. However, let's make it initially rare. Then we can see how selection favours this initially-rare trait.
1418

1519
To simulate biased transmission, following Model 1, we assume that each agent chooses another agent from the previous generation at random. But this time, if that chosen agent possesses trait $A$, then the focal agent copies trait $A$ with probability $s$. This parameter $s$ gives the strength of biased transmission, or the probability that an agent encountering another agent with a more favourable trait than their current trait abandons their current trait and adopts the new trait. If $s = 0$, there is no selection and agents never switch as a result of biased transmission. If $s = 1$, then agents always switch when encountering a favoured alternative.
@@ -109,7 +113,7 @@ As we might expect, increasing the strength of selection increases the speed wit
109113

110114
***
111115

112-
# Summary of Model 3
116+
## Summary
113117

114118
In Model 3 we saw how biased transmission causes a trait favoured by the selection bias to spread and go to fixation in a population, even when it is initially very rare. Biased transmission differs in its dynamics from biased mutation. Its action is proportional to the variation in the population at the time at which it acts. It is strongest when there is lots of variation (in our model, when there are equal numbers of $A$ and $B$ at $p = 0.5$), and weakest when there is little variation (when $p$ is close to 0 or 1). This generates an s-shaped pattern of diffusion over time.
115119

@@ -135,15 +139,15 @@ Given that it is unlikely that 37 countries independently invented postage stamp
135139

136140
***
137141

138-
# Exercises
142+
## Exercises
139143

140144
1. Try different values of $s$ to confirm that larger $s$ increases the speed with which $A$ goes to fixation.
141145

142146
2. Change $s$ in **BiasedTransmission** to $s_a$, and add a new parameter $s_b$ which specifies the probability of an agent copying trait $B$ from a demonstrator who possesses that trait. Run the simulation to show that the equilibrium value of $p$, and the speed at which this equilibrium is reached, depends on the difference between $s_a$ and $s_b$. How do these dynamics differ from the $mu_a$ and $mu_b$ you implemented in Model 2 Q5?
143147

144148
***
145149

146-
# Analytical Appendix
150+
## Analytical Appendix
147151

148152
As before, we have $p$ agents with trait $A$ and $1 - p$ agents with trait $B$. The $p$ agents with trait $A$ keep their $A$s, because $A$ is favoured by biased transmission. The $1 - p$ agents with trait $B$ pick another agent at random. If the random agent has $B$ then nothing happens. However if the random agent has $A$, which they will with probability $p$, then with probability $s$ they switch to that trait $A$. We can therefore write the recursion for $p$ under biased transmission as:
149153

@@ -185,7 +189,7 @@ We can also say that $p = 0$ is an unstable equilibrium, meaning that any slight
185189

186190
***
187191

188-
# References
192+
## References
189193

190194
Henrich, J. (2001). Cultural transmission and the diffusion of innovations: Adoption dynamics indicate that biased cultural transmission is the predominate force in behavioral change. American Anthropologist, 103(4), 992-1013.
191195

ABMmodels_model04_indirect_bias.Rmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ output: pdf_document
66

77
# Model 4: Biased transmission (indirect bias)
88

9+
## Introduction
10+
911
In Model 3 we examined direct bias, where certain cultural traits are preferentially copied from a randomly chosen demonstrator. Here we will simulate *indirect bias* (Boyd & Richerson 1985). This is another form of biased transmission, or cultural selection, but where certain demonstrators are more likely to be copied than other demonstrators. For this reason, indirect bias is sometimes called 'demonstrator-based' or 'context' bias.
1012

1113
Indirect bias comes in several forms. Learners might preferentially copy demonstrators who have high success or payoffs (which may or may not derive from their cultural traits), demonstrators who are old (and perhaps have accrued valuable knowledge, or at least good enough to keep them alive to old age), demonstrators who are the same gender as the learner (if cultural traits are gender-specific), or demonstrators who possess high social status or prestige.
@@ -16,7 +18,7 @@ Model 4 presents a simple model of indirect bias, first showing how payoff-based
1618

1719
In Model 4a we will simulate a case where new agents preferentially copy the cultural traits of agents from the previous generation who have higher relative payoffs. This is sometimes called 'payoff' or 'success' bias.
1820

19-
We will start with the skeleton of Model 3. As in Model 3, there are $N$ agents, each of whom possess a single cultural trait, either $A$ or $B$. The frequency of trait $A$ is denoted $p$, and the initial frequency in the first generation is $p_0$. There are $t_max$ timesteps and $r_max$ independent runs.
21+
We will start with the skeleton of Model 3. As in Model 3, there are $N$ agents, each of whom possess a single cultural trait, either $A$ or $B$. The frequency of trait $A$ is denoted $p$, and the initial frequency in the first generation is $p_0$. There are $t_{max}$ timesteps and $r_{max}$ independent runs.
2022

2123
In Model 3, agents were picked at random from the previous generation, and if that randomly-chosen agent possessed trait $A$ then trait $A$ was copied with probability $s$. For indirect bias, we need to change this. Demonstrator choice is no longer random: demonstrators are chosen non-randomly based on their payoffs. To implement this, we need to specify payoffs for each agent.
2224

@@ -346,7 +348,7 @@ data_model4b <- IndirectBias2(N = 10000,
346348

347349
***
348350

349-
# Summary of Model 4
351+
## Summary
350352

351353
Indirect bias occurs when individuals preferentially learn from demonstrators who have particular characteristics, such as being wealthy or socially successful (having high 'payoffs' in the language of modelling), being old, having a particular gender, or being prestigious. There is extensive evidence for these indirect transmission biases from the broad social and behavioural sciences (e.g. Rogers 2010; Labov 1972; Bandura, Ross & Ross 1963) and cultural evolution research specifically (e.g. Mesoudi 2011; Henrich & Gil-White 2001; Brand et al. 2020; Wood et al. 2012; McElreath et al. 2008; Henrich & Henrich 2010). Consequently, it is worth modelling indirect bias to understand its dynamics, and how it is similar or different to other forms of biased transmission.
352354

@@ -364,7 +366,7 @@ In terms of programming innovations, we saw in Model 4a how to assign payoffs to
364366

365367
***
366368

367-
# Exercises
369+
## Exercises
368370

369371
1. Try different values of $s$ in **IndirectBias** to confirm that larger $s$ increases the speed with which $A$ goes to fixation.
370372

@@ -374,7 +376,7 @@ In terms of programming innovations, we saw in Model 4a how to assign payoffs to
374376

375377
***
376378

377-
# Analytical Appendix
379+
## Analytical Appendix
378380

379381
In Model 4a, the frequency of trait $A$ in the next generation, $p'$, is simply the relative payoff of all agents with trait $A$ in the previous generation. This is given by:
380382

@@ -410,7 +412,7 @@ This is identical to Equation 3.2, the equivalent for direct bias. Again, there
410412

411413
***
412414

413-
# References
415+
## References
414416

415417
Bandura, A., Ross, D., & Ross, S. A. (1963). A comparative test of the status envy, social power, and secondary reinforcement theories of identificatory learning. The Journal of Abnormal and Social Psychology, 67(6), 527.
416418

0 commit comments

Comments
 (0)