Species coexistence in R

Coexistence theory in R from scratch: niche and fitness differences, the storage effect, Janzen-Connell, priority effects, and the invasion test.

A patch of grassland or a hectare of forest holds many species that all want the same few things: light, water, nutrients, space. Simple competition theory says the best competitor should win and the rest should go, yet they persist side by side. Coexistence theory is the body of work that explains why, and it turns out to have several distinct answers. This page collects every tutorial on this site that builds one of those answers by hand in base R, from the classical competition models to the modern invasion-based framework.

Stabilising and equalising

Modern coexistence theory splits the problem cleanly. A stabilising mechanism is anything that makes a species grow faster when it is rare than when it is common, so that whichever competitor falls behind is pushed back up; niche differences are the classic source. A fitness difference is the average advantage one species holds regardless of frequency, and it works the other way, toward exclusion. Coexistence is not about having a large niche difference in absolute terms; it is about the stabilising difference being large enough to overcome the fitness difference between the particular species in question. That balance, not either quantity alone, is the verdict.

Enemies that punish being common

One of the oldest specific mechanisms is the idea that a species carries its own specialised enemies, the seed predators, herbivores and soil pathogens that attack it and not its neighbours. Those enemies build up wherever the species is abundant, so an individual does worst exactly where its own kind is common. This conspecific negative density dependence gives every species an advantage when rare, and scaled across a community it can turn competitive exclusion into a diverse forest. It is a leading explanation for why tropical forests hold so many tree species, though it is deceptively hard to measure without fooling yourself.

Two ways a changing world helps

A constant environment is unkind to coexistence, but a varying one can hold competitors together that a fixed one would separate. There are two routes. The storage effect works when species respond differently to good and bad years and can store the gains of a good year in a long-lived or dormant stage; a rare species then banks its private good years without paying the crowding cost a common species cannot avoid. Relative nonlinearity is subtler, working through differences in how curved each species’ response to competition is, and it can stabilise or destabilise depending on the details. Both are fluctuation-dependent: switch off the variability and they vanish.

When there is more than one answer

Sometimes the community has not one stable outcome but several, and which one you get depends on history rather than on who is the better competitor. When each species suppresses the other more than itself, whoever arrives first wins, and the same patch under identical conditions can settle into different states. Followed along a slowly changing driver, that structure produces tipping points and hysteresis: a sudden collapse that reversing the driver does not undo. These are not failures of coexistence theory but a different regime of it, and telling a genuine alternative stable state from a smooth response to the environment takes a manipulation, not a snapshot.

The test is an invasion

Every one of these answers is checked the same way. Push a species to low density, hold the others at their usual abundances, and ask whether it grows. If each competitor can invade a community of the others, none can be lost and coexistence is stable; this is mutual invasibility, and it is the common currency that lets the mechanisms above be compared and even added together. It is also where the difficulty lives, because a low-density growth rate is easy to define and hard to measure, and much of the craft of coexistence analysis is in earning that number rather than assuming it.

The tutorials

Competition and the coexistence question

Enemies and negative density dependence

Coexistence in a fluctuating environment

More than one stable outcome

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.