Evolutionary game theory in R

Evolutionary game theory in R from scratch: the hawk-dove ESS, replicator dynamics, the routes to cooperation, spatial games, and drift in finite populations.

Most of population genetics assumes that a strategy has a fitness. Evolutionary game theory drops that assumption and asks what happens when the payoff to a behaviour depends on what everyone else in the population is doing. The answer changes the shape of the problem: there is no fitness peak to climb, only a moving target set by the current mix of strategies. This page collects every tutorial on this site that builds one of those models by hand in base R, from a single contest over a resource to cooperation on a lattice and drift in a finite population.

Fitness that depends on the opponent

The payoff matrix is the whole apparatus. Two individuals meet, each plays a strategy, and the matrix says what each one gets. Because the population supplies the opponents, the average payoff to a strategy is a function of the strategy frequencies, and that function is what selection sees. Negative frequency dependence, where a strategy does well precisely when it is rare, is the engine behind almost everything on this page: it is what holds a mixed strategy in place, what keeps a sex ratio near parity, and what lets a rare cooperator gain a foothold. The same logic appears in coexistence theory under a different name, which is why the two topics keep meeting.

Stability is several ideas, not one

An evolutionarily stable strategy is defined by an invasion test: a resident that no rare mutant can do better against. That is a static condition, and it is not the same as being the endpoint of a dynamic. The replicator equation supplies the dynamic, and comparing the two exposes the gaps. A strategy can be stable against invasion yet unreachable from most starting points; a cyclic game can circle a rest point forever without settling on it; a coordination game can have several stable outcomes, so that history rather than payoff decides the winner. Being clear about which question is being asked, invasion or convergence, removes most of the confusion in this area.

Cooperation is the hard case

The prisoner’s dilemma is arranged so that defection is the better reply to anything, which makes cooperation an evolutionary puzzle rather than a preference. The escape routes are structural, and each one changes the game rather than the payoffs. Interacting with relatives makes the beneficiary carry copies of the actor’s alleles. Repeating the encounter lets today’s cooperation buy tomorrow’s. Watching third parties lets reputation stand in for personal experience. Putting individuals on a lattice or a graph lets cooperators cluster and shelter each other. Splitting a population into groups makes selection act at more than one level. Each route has its own threshold condition, and the conditions are structurally similar enough that seeing them side by side is more instructive than any one of them alone.

Small populations break the deterministic story

Replicator dynamics describe an infinite, well-mixed population. Real ones are neither. In a finite population a mutant can fix by chance even when selection is against it, and can be lost even when selection favours it, so the honest question is not whether a strategy wins but how probable fixation is. That shift also changes what stability means: a strategy can be resistant to invasion by the standard test and still be the less likely of two to take over. Letting mutations be small rather than arbitrary gives a third view again, in which a population climbs a fitness gradient until it reaches a point that is attracting and yet not stable, and a single lineage splits in two.

The tutorials

Evolutionary game theory

The evolution of cooperation

Indirect reciprocity and reputation

Network reciprocity and spatial games

Finite populations and gradual evolution

Where this connects

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.