# Selection Gradients/MacLev

On these pages I am investigating the evolution of interactions in the MacArthur/Levins resource competition model.

This page explains the adaptive dynamics concepts and questions I'm using, and includes Sage source code for the models.

Child pages use this theory and code to investigate specific cases of the models:

- Selection Gradients/MacLev/One Species, One Resource
- Selection Gradients/MacLev/Two Species, Two Resources

## Contents

## MacArthur-Levins population dynamics

We start with a population-resource model:

- $\frac{d{X}_{i}}{dt}={b}_{i}{X}_{i}\left(\sum _{\mathrm{\ell}}{c}_{i\mathrm{\ell}}{w}_{\mathrm{\ell}}{R}_{\mathrm{\ell}}-{m}_{i}\right)$
- $\frac{d{R}_{\mathrm{\ell}}}{dt}={r}_{\mathrm{\ell}}\left({K}_{\mathrm{\ell}}-{R}_{\mathrm{\ell}}\right)-\sum _{i}{c}_{i\mathrm{\ell}}{X}_{i}$

where ${X}_{i}$ is the density of population $i$, ${R}_{\mathrm{\ell}}$ is the abundance of resource $\mathrm{\ell}$ and the parameters are ${b}_{i}$, an intrinsic population growth rate, ${m}_{i}$, mortality rate, ${c}_{i\mathrm{\ell}}$, the rate at which population $i$ captures resource $\mathrm{\ell}$, ${w}_{\mathrm{\ell}}$, the amount a unit of resource $\mathrm{\ell}$ contributes to population growth, ${r}_{\mathrm{\ell}}$, the resupply rate of resource $\mathrm{\ell}$, and ${K}_{\mathrm{\ell}}$ its maximum possible abundance.

This is a fine model on its own, but I am interested in Lotka-Volterra models, which are models in which there is a simple number ${a}_{ij}$ describing how populations $i$ and $j$ interact with each other. Using a Lotka-Volterra model will let us look at how these interaction terms ${a}_{ij}$ change, telling us how evolution drives these populations to become more competitive, antagonistic, or mutualistic.

In the above model the populations $i$ interact indirectly by taking resources from each other, but we can make the interactions direct by making simplifying assumptions, and this is what MacArthur and Levins did.

We do this by assuming that the resources come to equilibrium very quickly compared to the populations. Under this assumptions, we can hold the population sizes ${X}_{i}$ fixed and solve the second equation above for ${R}_{\mathrm{\ell}}$ when $\frac{d{R}_{\mathrm{\ell}}}{dt}=0$:

Then we simply use that value of ${R}_{\mathrm{\ell}}$ in the first equation, and we have a system of population sizes only:

We can rearrange the terms of this to have the standard Lotka-Volterra form:

where

- ${k}_{i}={b}_{i}\left(\sum _{\mathrm{\ell}}{c}_{i\mathrm{\ell}}{w}_{\mathrm{\ell}}{K}_{\mathrm{\ell}}-{m}_{1}\right)$ (ordinarily I'd call this ${r}_{i}$, but the name is already in use),
- ${a}_{ij}=-{b}_{i}\sum _{\mathrm{\ell}}\sum _{j}\frac{{c}_{i\mathrm{\ell}}{c}_{j\mathrm{\ell}}{w}_{\mathrm{\ell}}}{{r}_{\mathrm{\ell}}}$.

I'll be interested in how the interaction terms ${a}_{ij}$ change as the populations coevolve, because this expresses whether competition becomes stronger or weaker. When two coevolving populations compete for resources, we expect them to differentiate from each other and lessen the competition, but I'd like to look at both that and other cases, and do some detailed analysis about when it lessens and when it greatens.

## Adaptive dynamics in the Macarthur-Levins model

And now here's where we look at how that single population *evolves* in the Mac-Lev model. I won't review the details of how adaptive dynamics is done, but in summary: suppose that certain aspects of the population dynamics depend on the characteristics of the population, and those characteristics are able to mutate. Then over time, mutants will arise, and if they are better able to thrive in the environment they encounter than their forefathers, they will gradually replace them, and the characteristics of the population will slowly change.

In this model, it's ${b}_{i}$, ${c}_{i\mathrm{\ell}}$, and ${m}_{i}$ that have to do with the populations, so we introduce a *phenotype* variable ${u}_{i}$ representing the characteristics of the population and suppose that ${b}_{i}$, ${c}_{i\mathrm{\ell}}$ and ${m}_{i}$ are determined by the value of $u$. Then we can find out how $u$ changes in time in response to the conditions created by the population dynamics, and also how the other values such as ${X}_{i}$, ${R}_{\mathrm{\ell}}$, ${a}_{ij}$, ${k}_{i}$, change as $u$ evolves.

The change in $u$, to make a long story short, is driven by how the population growth rate of a rare mutant varies with the mutant's phenotype $u$. That is, there's an "invasion speed" $\mathcal{I}$ that is closely related to the population growth rate $\frac{d{X}_{i}}{dt}$, and the change in $u$ (that is, $\frac{du}{dt}$) is in proportion to $\frac{\partial \mathcal{I}}{\partial u}$.

To be precise:

- $\mathcal{I}\left({u}_{i}\right|E)=\underset{{X}_{i}\to 0}{lim}\frac{1}{{X}_{i}}\frac{d{X}_{i}}{dt}$

defines the invasion speed (where $E$ is the environment that an individual population $i$ experiences, including the rest of population $i$ and all other populations), and then

where $\gamma $ is a coefficient accounting for the frequency and size of available mutations. In simple cases, it's a constant, while when available mutations are not quite so simple and uniform, it may not be (as we will see).

## Adaptive geometry of ecological parameters

Now let's go deeper into what happens in that evolutionary change. We're considering several different ways to describe the evolving population, and now I want to give them clearer notation:

- ${\mathbf{u}}_{i}$, the "underlying phenotype". I'm going to be using a scalar ${u}_{i}$, and in fact just one of them, so I can call it $u$, but in general it's a vector of numbers, which is what I mean by writing it in boldface.
- $\mathbf{p}\left({\mathbf{u}}_{i}\right)=\left(\begin{array}{c}\hfill {b}_{i}\left({\mathbf{u}}_{i}\right)\hfill \\ \hfill {m}_{i}\left({\mathbf{u}}_{i}\right)\hfill \\ \hfill {c}_{i1}\left({\mathbf{u}}_{i}\right)\hfill \\ \hfill \mathrm{\vdots}\hfill \\ \hfill {c}_{im}\left({\mathbf{u}}_{i}\right)\hfill \end{array}\right)$, the "ecological phenotype"
- $\mathbf{A}\left(\mathbf{p}\left({\mathbf{u}}_{i}\right),\mathbf{p}\left({\mathbf{u}}_{1}\right),\mathrm{\dots},\mathbf{p}\left({\mathbf{u}}_{n}\right)\right)=\left(\begin{array}{c}\hfill {k}_{i}\left(\mathbf{p}\left({\mathbf{u}}_{i}\right)\right)\hfill \\ \hfill {a}_{i1}\left(\mathbf{p}\left({\mathbf{u}}_{i}\right),\mathbf{p}\left({\mathbf{u}}_{1}\right)\right)\hfill \\ \hfill \mathrm{\vdots}\hfill \\ \hfill {a}_{in}\left(\mathbf{p}\left({\mathbf{u}}_{i}\right),\mathbf{p}\left({\mathbf{u}}_{n}\right)\right)\hfill \end{array}\right)$, the "interaction phenotype"

These are vectors that are functions of one another. Using a suitable vector notation in our calculus, we can write the adaptive dynamics of $\mathbf{u}$ directly, ignoring the intermediate variables $\mathbf{p}$ and $\mathbf{A}$ for the moment:

The $T$ sign is for vector or matrix transposition: with the notation I'm using, ${\mathbf{u}}_{i}$ is a column vector - a point in a vector space of values - and $\frac{\partial \mathcal{I}}{\partial {\mathbf{u}}_{i}}$ is a row vector - a thing that operates on points. Since $\frac{d{\mathbf{u}}_{i}}{dt}$ is a column, we need to transpose the derivative of $\mathcal{I}$ to make it match. The ${\partial}_{1}$ sign is for the partial derivative with respect to the first argument.

Now we can use the chain rule to see how $\mathbf{p}$ changes:

- $\frac{d\mathbf{p}\left({\mathbf{u}}_{i}\right)}{dt}=\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}\frac{d{\mathbf{u}}_{i}}{dt}$
- $=\gamma {\widehat{X}}_{i}\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}{\partial}_{1}\mathcal{I}{\left({\mathbf{u}}_{i}\right)}^{T}$
- $=\gamma {\widehat{X}}_{i}\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}{\left({\partial}_{1}\mathcal{I}\left(\mathbf{p}\left({\mathbf{u}}_{i}\right)\right)\frac{d\mathbf{p}}{d{\mathbf{u}}_{i}}\right)}^{T}$
- $=\gamma {\widehat{X}}_{i}\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}{\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}}^{T}{\partial}_{1}\mathcal{I}{\left(\mathbf{p}\left({\mathbf{u}}_{i}\right)\right)}^{T}$.

Here we see the usefulness of this row-and-column-vector notation, because it lets us use the chain rule in a natural way: when we write $\frac{d\mathbf{p}\left({\mathbf{u}}_{i}\right)}{dt}=\frac{\partial \mathbf{p}}{\partial {\mathbf{u}}_{i}}\frac{d{\mathbf{u}}_{i}}{dt}$, we're multiplying a matrix by a column vector to get another column vector, in just the way we want.

I like to write $S\left(\mathbf{u}\right)={\partial}_{1}\mathcal{I}{\left(\mathbf{u}\right)}^{T}$ for the "selection gradient" of $\mathbf{u}$ -- the direction of increasing fitness in the space of possible $\mathbf{u}$ values. I'm very interested in the role of this selection gradient in various spaces, as we'll see. Notice that in the derivation above I switched from $S\left({\mathbf{u}}_{i}\right)={\left(\frac{\partial \mathcal{I}\left(\mathbf{v}\right|{\mathbf{u}}_{1},\mathrm{\dots},{\mathbf{u}}_{n})}{\partial \mathbf{v}}\right)}_{\mathbf{v}={\mathbf{u}}_{i}}$ to

These different selection gradients are very different objects: they're vectors expressing the direction of selection in different spaces -- here, the space of $\mathbf{u}$ values *vs.* the space of $\mathbf{p}$ values. Soon enough we'll also be looking at the selection gradient in $\mathbf{A}$ space.

Using the above chain rule manipulations, we can write

- $\frac{d{\mathbf{u}}_{i}}{dt}=\gamma {\widehat{X}}_{i}S\left({\mathbf{u}}_{i}\right)$
- $\frac{d\mathbf{p}\left({\mathbf{u}}_{i}\right)}{dt}=\gamma {\widehat{X}}_{i}\frac{\partial \mathbf{p}}{\partial \mathbf{u}}{\frac{\partial \mathbf{p}}{\partial \mathbf{u}}}^{T}S\left(\mathbf{p}\right)$.

Like $\mathbf{u}$ or whatever other vector, $\mathbf{p}$ would evolve in the direction of $S\left(\mathbf{p}\right)$ if it were to mutate in all directions equally. However, it doesn't do that: since $\mathbf{p}$ is a function of $\mathbf{u}$, it only mutates in directions given by mutations in $\mathbf{u}$. The matrix multiplying $S\left(\mathbf{p}\right)$ in the dynamics of $\mathbf{p}$ is a projection matrix, restricting the motion of $\mathbf{p}$ to directions allowed by the mapping between $\mathbf{u}$ and $\mathbf{p}$. (To be precise, $\frac{\partial \mathbf{p}}{\partial \mathbf{u}}{\frac{\partial \mathbf{p}}{\partial \mathbf{u}}}^{T}S\left(\mathbf{p}\right)$ is not precisely the projection of $S\left(\mathbf{p}\right)$ onto the subspace parametrized by $\mathbf{u}$ unless the columns of $\frac{\partial \mathbf{p}}{\partial \mathbf{u}}$ are unit-length; otherwise there's some scaling by positive numbers involved. But it definitely transforms the vector into a direction allowed by the restriction to points parametrized by $\mathbf{u}$.)

The motion of $\mathbf{A}$ is the same way, except that it is influenced by all the populations in the system, not just one, because two phenotypes are involved in each ${a}_{ij}$ value. For that reason, the dynamics of $\mathbf{A}$ has some extra terms...

But before we go into that, let's look at the selection gradient and the dynamics of $\mathbf{p}\left(\mathbf{u}\right)$.

## Adaptive geometry of interaction terms

Now, let's get to how ${a}_{ij}$ and ${k}_{i}$ "would like to evolve" and why they move in the directions they do.

Expanding out the dynamics of the $\mathbf{A}$ vector has more involved than doing it for the $\mathbf{p}$ vector, because $\mathbf{A}$ depends on all the different phenotypes ${\mathbf{u}}_{j}$, not just one we're concerned with. Also, we have to keep careful track of ${\mathbf{u}}_{i}$, because it appears in $\mathbf{A}$ in two different ways: on the left-hand side of each ${\mathbf{a}}_{ij}=a\left({\mathbf{u}}_{i},{\mathbf{u}}_{j}\right)$ term, which describes how population $i$ (the "patient") is affected by an encounter with population $j$ (the "agent"); and also on the right-hand side of the ${a}_{ii}=a\left({\mathbf{u}}_{i},{\mathbf{u}}_{i}\right)$ term, as the "agent" in an encounter between $i$ and $i$. This distinction is important because every encounter has two effects, the effect on oneself and the effect on the other, and we'll see that selection treats these two effects very differently.

So to be clear, we'll work with the notation

- ${\mathbf{A}}_{i}={\mathbf{A}\left(\mathbf{v},{\mathbf{u}}_{1},\mathrm{\dots},{\mathbf{u}}_{n}\right)|}_{\mathbf{v}={\mathbf{u}}_{i}}$ $={\left(\begin{array}{c}\hfill \mathbf{a}\left(\mathbf{v},{\mathbf{u}}_{1}\right)\hfill \\ \hfill \mathrm{\vdots}\hfill \\ \hfill \mathbf{a}\left(\mathbf{v},{\mathbf{u}}_{n}\right)\hfill \\ \hfill k\left(\mathbf{v}\right)\hfill \end{array}\right)}_{\mathbf{v}={\mathbf{u}}_{i}}$,

to distinguish the two different roles of ${\mathbf{u}}_{i}$ (suppressing the intermediate variable $\mathbf{p}$), and we'll refer to the two different partial derivatives that relate to ${\mathbf{u}}_{i}$ as ${\partial}_{1}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right)={\frac{\partial {\mathbf{A}}_{i}}{\partial \mathbf{v}}|}_{\mathbf{v}={\mathbf{u}}_{i}}$ and ${\partial}_{2}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right)={\frac{\partial {\mathbf{A}}_{i}}{\partial {\mathbf{u}}_{i}}|}_{\mathbf{v}={\mathbf{u}}_{i}}$.

So first of all, if we use ${\mathbf{A}}_{i}$ as an intermediate variable, the dynamics of ${\mathbf{u}}_{i}$ is

- $\frac{d{\mathbf{u}}_{i}}{dt}=\gamma {\widehat{X}}_{i}{\partial}_{1}\mathcal{I}{\left({\mathbf{u}}_{i}\right)}^{T}$
- $=\gamma {\widehat{X}}_{i}{\left({\partial}_{1}\mathcal{I}\left({\mathbf{A}}_{i}\right){\partial}_{1}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right)\right)}^{T}$
- $=\gamma {\widehat{X}}_{i}{\partial}_{1}{\mathbf{A}}_{i}{\left({\mathbf{u}}_{i}\right)}^{T}{\partial}_{1}\mathcal{I}{\left({\mathbf{A}}_{i}\right)}^{T}$.

Then

- $\frac{d{\mathbf{A}}_{i}}{dt}={\partial}_{1}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right)\frac{d{\mathbf{u}}_{i}}{dt}+\stackrel{n}{\sum _{j=1}}{\partial}_{2}{\mathbf{A}}_{i}\left({\mathbf{u}}_{j}\right)\frac{d{\mathbf{u}}_{j}}{dt}$
- $=\gamma {\widehat{X}}_{i}{\partial}_{1}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right){\partial}_{1}{\mathbf{A}}_{i}{\left({\mathbf{u}}_{i}\right)}^{T}{\partial}_{1}\mathcal{I}{\left({\mathbf{A}}_{i}\right)}^{T}+\stackrel{n}{\sum _{j=1}}\gamma {\widehat{X}}_{j}{\partial}_{2}{\mathbf{A}}_{i}\left({\mathbf{u}}_{j}\right){\partial}_{1}{\mathbf{A}}_{j}{\left({\mathbf{u}}_{j}\right)}^{T}{\partial}_{1}\mathcal{I}{\left({\mathbf{A}}_{j}\right)}^{T}$
- $=\gamma {\widehat{X}}_{i}{\partial}_{1}{\mathbf{A}}_{i}\left({\mathbf{u}}_{i}\right){\partial}_{1}{\mathbf{A}}_{i}{\left({\mathbf{u}}_{i}\right)}^{T}S\left({\mathbf{A}}_{i}\right)+\stackrel{n}{\sum _{j=1}}\gamma {\widehat{X}}_{j}{\partial}_{2}{\mathbf{A}}_{i}\left({\mathbf{u}}_{j}\right){\partial}_{1}{\mathbf{A}}_{j}{\left({\mathbf{u}}_{j}\right)}^{T}S\left({\mathbf{A}}_{j}\right)$.

This expression is made up of two somewhat complex terms. The first term, the $S\left({\mathbf{A}}_{i}\right)$ term, expresses the change in the interactions experienced by population $i$ due to change in population $i$ in its patient role. I refer to this as the **direct effect** of selection on population $i$. The second term, the sum of $S\left({\mathbf{A}}_{j}\right)$ vectors, expresses the change in population $i$'s interactions due to change in all the different agents it encounters, including population $i$ itself in its agent role. I refer to this as an **indirect effect** of selection on the various populations.

What would happen if there were no constraints on ${\mathbf{A}}_{i}$? That is, if all the terms just mutate independently without being constrained by dependence on $\mathbf{u}$ variables. In this case, we would simply have

In the constrained case, as with $\mathbf{p}$, the motion due to $S\left({\mathbf{A}}_{i}\right)$ is modified by a transformation matrix. Here, though, there's also another term dealing with the effect of changing $\mathbf{u}$ values as the second argument to $a\left({\mathbf{u}}_{i},{\mathbf{u}}_{j}\right)$. Let's expand that out one step further:

Here I'm using colors to distinguish three different vector quantities, which I'll soon plot in the same colors:

- $\frac{d{\mathbf{A}}_{i}}{dt}$, the resultant change in ${\mathbf{A}}_{i}$, blue.
- $D\left({\mathbf{u}}_{i}\right)$, the direct effect of change in ${\mathbf{u}}_{i}$ as patient, green.
- $I\left({\mathbf{u}}_{i}\right|{\mathbf{u}}_{1},\mathrm{\dots},{\mathbf{u}}_{n})$, the indirect effect of change in all agents ${\mathbf{u}}_{j}$ including ${\mathbf{u}}_{i}$, purple.

## Supplementary materials

Here are the Sage classes that do the work for the Mac-Lev models. above. They use generalized Sage machinery that's stored at SageDynamics.

Now here's the MacArthur-Levins resource competition model.

Loading WorkingWiki file "maclevmodels.py.step" dynamically. If it doesn't load, click to view the page statically.