Interactive exploration

Sex Evolution Sandbox

Macro-evolutionary emergence of sex

Interactive Ensemble Dynamics under Selection

This document simulates an ensemble of populations under selection to explore the evolutionary dynamics of sexual reproduction and recombination. The simulation tracks populations of fictitious organisms with two genes (loci) X and Y, and demonstrates a fundamental result about the selective advantage of sex.

Biological Context

The simulation models populations where:

  • Each individual has two genes (X and Y) that contribute to fitness
  • Fitness is determined by the exponential of the sum of these two genetic values
  • Selection acts on the population, changing allele frequencies over time
  • The “sex potential” is proportional to the negative covariance between X and Y
  • The selective advantage of sex is proportional to the negative cumulative covariance

This framework allows us to explore why sexual reproduction might be evolutionarily advantageous, even though it comes with costs like the “twofold cost of sex.”

Mathematical Foundation

The key insight is that sexual reproduction can break up unfavorable genetic associations (linkage disequilibrium). When two loci are negatively correlated (negative covariance), recombination can create beneficial combinations that selection can then act upon. The cumulative covariance over time provides a measure of the total selective advantage that sex provides.

Try editing the parameters and re-running to explore different scenarios!

Inputs

This section sets up the simulation parameters and defines the initial genetic distributions. The parameters control the evolutionary dynamics and allow you to explore different scenarios.

Distribution Type

  • Distribution Type: Sets the statistical distribution used to generate the initial genetic values (X and Y) for each individual in the population.
    • "multivariate_normal": The most common choice; both loci are normally distributed with a specified correlation (rho). This models traits influenced by many small additive effects.
    • "bivariate_t": Both loci are drawn from a t-distribution, which has heavier tails than the normal. This allows for more extreme initial values and can model populations with rare, large-effect variants.
    • "bivariate_uniform": Both loci are drawn from a uniform distribution within a specified range. This models a population with maximum genetic diversity and no initial bias toward any value.

Try changing the distribution type to see how different genetic architectures affect the evolutionary dynamics and the selective advantage of sex!

Parameters

  • Number of Distinct Genotypes (m): Number of genetic variants in each population
  • Number of Populations (n_pops): Size of the ensemble for statistical analysis
  • Number of Generations (ngens): Length of the simulation
  • Time Increments (ti): Subdivisions within each generation for smoother dynamics
  • Correlation (rho): Frequency-independent correlation between X and Y loci
  • Means (mu_X, mu_Y): Initial mean values for the two loci
  • Standard Deviations (sigma_X, sigma_Y): Initial genetic variation at each locus

The sample_bivariate() function generates the initial genetic values according to your chosen distribution, creating the starting point for each population in the ensemble.

Initial Frequency Type

  • Initial Frequency Type: Controls how the starting frequencies of genotypes are assigned in each population.
    • "equal": All genotypes start with the same frequency (uniform distribution)
    • "random": Genotype frequencies are randomly assigned and normalized to sum to 1

This option allows you to explore how the initial distribution of genetic variation affects the evolutionary dynamics. Try switching between equal and random initial frequencies to see how it influences the results!
Run code in sequence from left to right

Simulation

This section runs the core evolutionary simulation. For each population in the ensemble, it tracks how allele frequencies change over time under selection.

What the Simulation Does

  1. Initialization: For each population, it generates initial genetic values (X, Y) for all individuals and sets equal initial frequencies
  2. Fitness Calculation: Individual fitness is calculated as exp(X + Y), creating a multiplicative fitness landscape
  3. Selection Dynamics: Over each generation, allele frequencies change according to their relative fitness
  4. Covariance Tracking: The covariance between X and Y is calculated at each time point using the current allele frequencies

Key Mathematical Operations

  • Fitness: fitnesses = np.exp(XY[:,0] + XY[:,1]) - Multiplicative fitness from both loci
  • Selection: freqs = freqs * (fitnesses / wbar)**(1/ti) - Frequency change proportional to relative fitness
  • Covariance: cov_ensemble[gen, pop] = np.sum(fq*(XY[:,0] - np.sum(XY[:,0]*fq))*(XY[:,1] - np.sum(XY[:,1]*fq))) - Weighted covariance using current frequencies

The simulation runs for all populations in parallel, creating an ensemble of evolutionary trajectories that we can analyze statistically.

Key Plot: Mean cumulative covariance

This is the most important plot in the simulation, demonstrating a fundamental theoretical result about the selective advantage of sex.

What This Plot Shows

The blue line shows the cumulative mean covariance over time, which represents the total selective advantage that sexual reproduction provides. The gray line at zero serves as a reference point.

The Key Result

The cumulative covariance always ends up below zero - this is not a coincidence, but a mathematical theorem that holds under very general conditions. This result proves that:

  1. The ensemble mean selective advantage of sex is asymptotically non-negative
  2. Sexual reproduction provides a systematic advantage in breaking up unfavorable genetic associations
  3. This advantage accumulates over time and becomes more pronounced as selection continues

Why This Matters

This theoretical result explains why sexual reproduction can be evolutionarily stable despite its costs. The negative cumulative covariance means that sex systematically creates beneficial genetic combinations that selection can act upon, providing a long-term advantage that outweighs short-term costs.

Interactive Exploration

You are encouraged to: - Modify the parameters (correlation, means, standard deviations) to see how the result holds across different scenarios - Change the distribution type to explore different genetic architectures - Adjust the simulation length to observe the asymptotic behavior - Experiment with the code to test the robustness of this fundamental result

The universality of this result across different parameter settings demonstrates the deep mathematical foundation underlying the evolution of sexual reproduction.

Now let’s try this:

Progress: starting…