MLS demo 3.2
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Multilevel selection NetLogo model overview
Getting started
You can open the model in your browser simply by clicking, although it’ll be in a window within Canvas so might be a bit tight.
If you right click and ‘Save As…’, you can download the .html file to your hard drive, then open the saved file. (It should open with your default browser.)
You can also download the .nlogo file, download NetLogo onto your computer, and use it to open the model file (.nlogo).
Running the model
Starting/stopping. Running the model requires that you click ‘Setup’, then ‘Go’ (purple buttons on the right-hand side of the interface). You should see the 2D model view (with little simulated dots cooperating or not) and plots start changing. Click ‘Go’ again at any point to pause the model (it stops after it completes the current step). Note the slider at the very top, which allows you to control the speed of the model. If you are getting frustrated with how it’s taking, drag that slider all the way right and things will speed up (your computer willing).
Default populations. The default populations are a random distribution of altruists (A) and cheaters (C). You can monitor populations visually, and the graphs show (1) the frequency of the A allele, as well as (2) the balance of variance among groups and variance within groups (the purple line in graph 2). (When the purple line is above the black line, variance among groups > variance within groups.)
Invasion experiments. After you have clicked ‘Setup’ (before or after clicking ‘Go’, up to you), clicking either ‘invades’ button will instantly convert all members of the population except for one into the opposite genotype, so that you can more easily see what happens to that genotype. The invader’s habitat will flash blue/red (for A or C, respectively) to make it easier to find them visually. For example, ‘Altruists invade’ will convert the entire population to C, and you will see a lone A highlighted for awhile, until it goes extinct or is clearly spreading.
As with all experiments, remember to replicate each test multiple times—these models have randomness built in, so one failed invasion doesn’t mean much on its own.
Parameters (aka ‘Independent Variables’). You are free to vary any parameters you can find if you would like, but the two on the left are the most straightforward and likely to tell you something interested about multilevel selection. To change a parameter value before or during an experiment, simply click the slider and drag right or left.
Note that mutation_rate is set to zero by default, and should probably remain zero for invasion experiments.
mutationrate = the probability that a parent and offspring have a different phenotype. migrationrate = the probability that an individual will move to a neighboring group between rounds.
Model rules
Habitats. All individuals occupy a single habitat at any one time. Habitats are separated by uninhabitable areas (white squares). Habitats have their own local carrying capacity (K), which determines how many individuals can live in that square before lack of resources stops their reproduction. Black squares have relatively low K, whereas greener squares have higher K (can support more individuals; so green = high quality). When a group reaches K and can no longer reproduce, the square will flash brown.
After a certain number of rounds (‘duration,’ which is 10 by default), patches ‘reset’ and all individuals disperse at random to start reproducing/gathering resources again. (This represents seasonality, disturbance, resource exhaustion, etc., and is vaguely based on social insect and microbial group life cycles.) The more of a genotype there is just before patch reset, the more chances they will have to successfully colonize new patches immediately after reset.
Phenotypes. An Altruist (A) individual divides its effort roughly equally into (1) acquiring resources that will be shared with all group members (increasing the carrying capacity (K) of their habitat), and (2) reproducing asexually. In contrast, Cheaters (C) do not attempt to secure resources (never increase K), and instead attempt reproduction every chance they get. Neither phenotype can reproduce once their group size exceeds K.
Comments and Questions
globals [global-ticks within-group-var among-group-var freqA binsA wg5 wg4 wg3 wg2 wg1 ag5 ag4 ag3 ag2 ag1] patches-own [grid quality Kp mean-A var-A] turtles-own [A reproductive?] to Setup clear-all crt (count patches * p * K * (1 - survival)) [set size t-size face one-of patches fd (1 + random (5 * max-pycor)) set shape "dot" set A (random-float 1) set-turtle-color] ask patches [set quality 0 set grid 1] if grid? = 1 [ask patches [let n ((pycor + pxcor) / 2) ifelse round n = n [set grid 1] [set grid 0]]] ; Create a grid pattern by choosing patches with even products of x and y coordinates ask n-of (p * count patches with [grid = 1]) patches with [grid = 1] [set quality 1 set Kp (quality * K)] ask patches [assign-colors] ask turtles [ifelse [quality] of patch-here = 0 [die] [move-to patch-here]] if Discrete? = 1 [ask turtles [set A round A set-turtle-color]] initial-math set global-ticks 0 reset-ticks end to Go ask turtles [set reproductive? 1 set-turtle-color] interact migrate? ;assign-colors if ticks > duration [reshuffle reset-ticks] do-math set global-ticks (global-ticks + 1) tick end to set_A=0 ask turtles [set A 0 set shape "dot" set size t-size set-turtle-color] ask patches [set Kp (K * quality) assign-colors] end to set_A=1 ask turtles [set A 1 set shape "dot" set size t-size set-turtle-color] ask patches [set Kp (K * quality) assign-colors] end to summon_altruist ;crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 0] ask patch-here [set quality 1 set Kp K] set A 1 set-turtle-color follow-me] crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 1 and grid = 1] ask patch-here [set quality 1 set Kp K set pcolor blue] set A 1 set-turtle-color ask turtles-here with [A < 0.5] [die]] end to summon_cheater crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 1 and grid = 1] ask patch-here [set quality 1 set Kp K set pcolor red] set A 0 set-turtle-color ask turtles-here with [A > 0.5] [die] ] end to interact ask turtles [if [quality] of patch-here = 0 [die] if count turtles-here > Kp [die]] ask turtles [if reproductive? > 0 [move-to patch-here ifelse random-float 2 < A [nudge set reproductive? 0 ask patch-here [set Kp (Kp + b)]] [nudge reproduce]]] ;ask turtles [face one-of patches fd random-float 0.5] ;ask turtles [if [quality] of patch-here = 0 [carefully [move-to one-of neighbors with [quality = 1]] []]] ask patches with [quality > 0] [if count turtles-here < 1 [set Kp K assign-colors]] ask patches with [quality > 0] [if Kp > (5 * K * b) [set Kp (5 * K * b)] assign-colors] end to migrate? ;ask turtles [if random-float 1 < migration [move-to one-of patches with [quality > 0]]] ask turtles [if random-float 1 < migration [move-to one-of neighbors with [quality > 0]]] ask turtles-on patches with [quality = 0] [die] end to reproduce ifelse count turtles-on patch-here < Kp [hatch 1 [mutate set reproductive? 0] set reproductive? 0] [ask patch-here [set pcolor brown]] end to nudge face one-of patches fd random-float 0.5 end to mutate ifelse Discrete? = 1 [if random-float 1 < mutation [set A (1 - A) set-turtle-color]] [if random-float 1 < mutation [set A (A + (random-normal 0 0.5)) if A < 0 [set A 0] if A > 1 [set A 1] set-turtle-color]] end to set-turtle-color ifelse Discrete? = 1 [ifelse A < 0.5 [set color red] [set color blue]] [ifelse A < 0.5 [set color (scale-color red A -0.15 0.75)] [set color (scale-color blue A 0.25 1.15)]] end to initial-math ;let increment (1 / nbins) ;set binsA [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] calc-freq end to do-math ask patches with [quality = 1 and count turtles-here > 1] [set mean-A mean [A] of turtles-here set var-A variance [A] of turtles-here] set among-group-var variance [mean-A] of patches with [quality = 1] set within-group-var mean [var-A] of patches with [quality = 1] set ag5 ag4 set ag4 ag3 set ag3 ag2 set ag2 ag1 set ag1 among-group-var set wg5 wg4 set wg4 wg3 set wg3 wg2 set wg2 wg1 set wg1 within-group-var end ;to calc-freq ;set freqA [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] ; set freqA map [ x -> count turtles with [A = x]] [binsA] ; precision 1 ;end to reshuffle ask patches [set quality 0 set Kp 0 assign-colors] ask n-of (p * count patches) patches [set quality 1 set Kp (quality * K) assign-colors] ask turtles [ifelse random-float 1 < survival [die] [face one-of patches jump (1 + random (5 * max-pycor)) if count turtles-here > 1 [die] if Kp < 0.5 [die]]] stop-inspecting-dead-agents end to assign-colors ;ask patches with [quality = 1] [set pcolor white] ;set pcolor scale-color green (1 - (Kp / (5 * K))) -0.3 1.0 ifelse grid = 0 [set quality 0 set pcolor white] [ ifelse quality > 0 [set pcolor scale-color green (Kp / (5 * K)) -0.5 5] [set pcolor black]] end
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
MLS demo 3.2.png | preview | Preview for 'MLS demo 3.2' | over 4 years ago, by William Driscoll | Download |
This model does not have any ancestors.
This model does not have any descendants.