Analyse the Simulated Dynamics

Once the dynamics of the community have been simulated, we can analyse the results to better understand the behaviour of the community. To do so, we provide a few functions to compute various properties of the community dynamics.

Let's first simulate the dynamics of a species-rich community with the niche model:

using EcologicalNetworksDynamics, Plots

S = 20 # Number of species.
C = 0.1 # Connectance.
foodweb = Foodweb(:niche; S, C)
m = default_model(foodweb)
B0 = rand(S) # Vector of initial biomasses.
t = 100 # Simulation time.
sol = simulate(m, B0, t)
retcode: Success
Interpolation: 3rd order Hermite
t: 43-element Vector{Float64}:
   0.0
   0.0826459514258767
   0.20736567112434734
   0.3510445490032309
   0.5351801545733756
   0.7932428369008673
   1.0684525838037109
   1.4768869358210566
   1.9324331907505032
   2.528752012074402
   ⋮
  58.62549631929376
  65.17112567662593
  72.59306606016548
  74.72234304923667
  77.15275961354678
  82.8606020330175
  89.16557795325856
  91.33246236260685
 100.0
u: 43-element Vector{Vector{Float64}}:
 [0.5118118487058613, 0.875911868255886, 0.3079854434448738, 0.7257632166193411, 0.244523716680892, 0.012385767784497181, 0.31626151150395077, 0.1295405873603872, 0.22248565849566382, 0.4555937492929675, 0.6920998400498157, 0.9033102982284691, 0.9741640714717302, 0.27475247256896596, 0.647273034252085, 0.2955885170480963, 0.2873695472699491, 0.46343742083951356, 0.6754740118625845, 0.9843212102380331]
 [0.5407335648195932, 0.8833833234387226, 0.31153622636775696, 0.7539236897767229, 0.25198291690675617, 0.01309977074295025, 0.3333453070277649, 0.134827599483683, 0.23517792391190231, 0.46682283828011417, 0.7183461957676418, 0.8588659755790778, 0.9960751487725902, 0.2308232508045278, 0.6049722855333761, 0.2696402196701515, 0.26331526914525955, 0.4464205654015268, 0.5467119222305471, 0.88776910734476]
 [0.5743779322097786, 0.8889636844430922, 0.31493109809441755, 0.7976050662339768, 0.2641879949099497, 0.014236267764335522, 0.3597818511297562, 0.14156695868716562, 0.2537892566613757, 0.4777156637285402, 0.7535044300815728, 0.7862807422969933, 1.0132576584246042, 0.18461881894074447, 0.5437695085813431, 0.23784353129627553, 0.23347669934286677, 0.4159319716515382, 0.40297085124866666, 0.7607644522256636]
 [0.5978531092224991, 0.8886713814059886, 0.31650722253442404, 0.849404488103123, 0.2796661312593753, 0.015626622917720333, 0.3909854229124826, 0.1476035466764411, 0.27378151067277634, 0.48208868965184837, 0.7852003970892476, 0.7032412595894492, 1.009976928703251, 0.149562621148033, 0.4798572648528061, 0.20999369761440806, 0.2070324286635127, 0.379155409181899, 0.2962412015999316, 0.6434844458450257]
 [0.6102359703685709, 0.8807558731948306, 0.31588259242120514, 0.917529380204351, 0.301737571315342, 0.017513073910970775, 0.4316231802905003, 0.1530412259833029, 0.29616527102336765, 0.47724727576116666, 0.8089416660139479, 0.6057325082541067, 0.9763298265871359, 0.12025679839780913, 0.41074032968841, 0.1843239023202062, 0.18241880324297366, 0.3370901225147105, 0.21735262264234712, 0.5345124059628465]
 [0.6095215383064078, 0.8605476511198223, 0.3117705785964919, 1.0142389379864873, 0.33695816585184485, 0.020276231239796477, 0.4883841861129453, 0.15735160745808763, 0.32038762564751977, 0.45632694820946906, 0.8075015189052379, 0.4907434373595169, 0.8959926201334796, 0.09436271192273032, 0.33764735778991845, 0.16086654518881893, 0.15974171509509813, 0.2939851607632384, 0.16132377461920874, 0.4399180388786637]
 [0.5984515858900258, 0.832291010592556, 0.3049608418043341, 1.1139125406539268, 0.3801729365459161, 0.023227610523766457, 0.5463612500829459, 0.15907606992520132, 0.33749520150248263, 0.42294242532389137, 0.7657264112032166, 0.3940446489055994, 0.7972134460555037, 0.07655440491289665, 0.2844216265991917, 0.1457524439402601, 0.14504966349586626, 0.26632927477691193, 0.13221740721617617, 0.38540326280519044]
 [0.5748562310279652, 0.7843774800763377, 0.29260985991041444, 1.2381738481538247, 0.4555059385363559, 0.027266521435496016, 0.6223480893343434, 0.15855554312072126, 0.3502582678568921, 0.36452280459710956, 0.6560847030244737, 0.28912379922362336, 0.6648777060347549, 0.059182521180439075, 0.23650801702304958, 0.13401595188510587, 0.1336202491647527, 0.24828050499314566, 0.11246094484571513, 0.35062349271712695]
 [0.5457531602396861, 0.7282336646841452, 0.2776820116583742, 1.3158291665130786, 0.5556808057490183, 0.030937820204889287, 0.6868585601910379, 0.15594270326075244, 0.3531417288446205, 0.30030889151270534, 0.5197126424064549, 0.21066838014245293, 0.5563946557407602, 0.04625514043590529, 0.2082308432123411, 0.12938663612332765, 0.12915247811188738, 0.24669701285081902, 0.10422944992150422, 0.34361872654380926]
 [0.5082999039814072, 0.6557728648096189, 0.258211338417556, 1.3017556177989165, 0.7091741776428919, 0.034369176413833316, 0.7349996368406602, 0.15159734268562827, 0.34712142775182825, 0.23265885660556807, 0.3787738107473799, 0.1468908296694521, 0.47023686262299497, 0.034600059048045195, 0.19148193551860132, 0.13073457617410056, 0.13060277526445674, 0.25957406063451627, 0.10261408846104277, 0.35663284910078497]
 ⋮
 [0.1887680216998057, 0.2220562565803309, 0.21839179446281248, 0.02496017471530172, 1.0904195979385287, 0.1874344259628312, 0.6365653196031275, 0.28978738438098534, 0.2202282226178711, 0.24980155533181939, 0.18636547538163598, 1.0716651224448e-7, 0.39677241454199724, 0.0, 0.22764579958687886, 0.2276490886317253, 0.22764908863207972, 0.30942977304205954, 0.18832201473888696, 0.46927713477737165]
 [0.18767409810930297, 0.22069136944414305, 0.21833575240741546, 0.022522528738190634, 1.0913638924103524, 0.1871661176479213, 0.6364904610100376, 0.2886445742797661, 0.2195152616626733, 0.25442414170718053, 0.18645667096735646, 1.839386672519918e-8, 0.39648091984286643, 0.0, 0.22765201183596367, 0.22765333815320082, 0.22765333815382366, 0.3087448312145005, 0.18854741383984797, 0.4694243527203762]
 [0.18687481725158295, 0.21970330677376526, 0.218274083859716, 0.020467116558773514, 1.0920688000058043, 0.18670054818374676, 0.6364356661376624, 0.28755851234936963, 0.21898932316717734, 0.2581229353134831, 0.18672925004916938, 2.221935275618426e-9, 0.3962601522827443, 0.0, 0.22764963350274964, 0.2276501184292938, 0.22765011842698804, 0.30823520167295054, 0.18870667811644007, 0.46953492976956296]
 [0.18670625748812208, 0.2194962209430235, 0.21825572220628647, 0.019978816969484017, 1.092221172798806, 0.18655716958717983, 0.6364240738477444, 0.2872931132693452, 0.21887645553386897, 0.25895754840352675, 0.1868213758410286, 1.3385103947011516e-9, 0.39621116415658725, 0.0, 0.22764782915871937, 0.22764820203804578, 0.22764820203791228, 0.3081250566524174, 0.18873883210251138, 0.4695594663308048]
 [0.18653759182448484, 0.21928966785569937, 0.21823421566262752, 0.01946468136903888, 1.0923748413110612, 0.1863944262234251, 0.6364123712161648, 0.2870140465627169, 0.21876229683846282, 0.2598161596510511, 0.18692836220891756, 7.490627167283345e-10, 0.3961606904003529, 0.0, 0.22764540667732083, 0.22764568189138598, 0.22764568189165998, 0.30801324648846035, 0.18877021108911762, 0.46958475870221894]
 [0.1862194777137176, 0.21890297754921412, 0.21818176644308862, 0.01840864646167533, 1.0926696215953753, 0.18602611540194774, 0.6363903042513963, 0.2864485271838223, 0.2185425349517617, 0.2615094780538656, 0.18717718190755667, 1.7096300973618637e-10, 0.39606042098741573, 0.0, 0.22763883329768073, 0.22763896088187358, 0.2276389608803194, 0.30779693550509335, 0.18882660714879745, 0.46963521379152434]
 [0.1859623924909663, 0.21859547889501432, 0.21812188301702173, 0.017439407386102966, 1.0929169068133382, 0.18565349048683255, 0.6363723392590189, 0.28594886721236806, 0.21835875077446046, 0.2629680149686131, 0.1874363345628995, 3.197572977003236e-11, 0.39597240353530194, 0.0, 0.22763090902499133, 0.22763096309087663, 0.22763096309180272, 0.3076147046403202, 0.18886838605288475, 0.4696797836015557]
 [0.1858909913957004, 0.21851141512119648, 0.21810112142579804, 0.017144967138472605, 1.0929879859242544, 0.18553514674956936, 0.6363672901028496, 0.2858026750107307, 0.21830632161105726, 0.26339106398549667, 0.1875199934588171, 1.908681569849089e-11, 0.39594632700646404, 0.0, 0.2276281415199623, 0.22762818269486473, 0.22762818269489915, 0.3075624564816116, 0.1888791552766781, 0.46969305501499653]
 [0.18566292763827735, 0.21824859546300718, 0.21801915680768938, 0.016120083177245413, 1.0932234459567094, 0.18511218322205608, 0.6363508253078042, 0.28531718136546314, 0.2181338919986182, 0.2647976057000078, 0.1878231688492163, 1.1560656986808045e-12, 0.39585695201687854, 0.0, 0.22761740539273803, 0.22761741768429122, 0.22761741768404836, 0.3073899258293515, 0.18891071395096595, 0.46973895711092645]

When running the dynamics of a rich initial pool of species, we generally observe the extinction of some species. You can access the number of surviving species at the end of the simulation with:

richness(sol[end]) # Number of surviving species at the end of the simulation.
19

You can also get the trajectory of the species richness through time with:

richness(sol) # Richness at each time step.
43-element Vector{Int64}:
 20
 20
 20
 20
 20
 20
 20
 20
 20
 20
  ⋮
 19
 19
 19
 19
 19
 19
 19
 19
 19

Similarly, you can compute the persistence, that is the proportion of species that are present at each time step:

persistence(sol) # Equivalent to: richness(sol) ./ S
43-element Vector{Float64}:
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 ⋮
 0.95
 0.95
 0.95
 0.95
 0.95
 0.95
 0.95
 0.95
 0.95

Or the total biomass of the community:

total_biomass(sol)
43-element Vector{Float64}:
 10.000053791973562
  9.747773101005423
  9.419574437952654
  9.105933779644243
  8.779430400098102
  8.417846351184783
  8.111604062755859
  7.7532524741416475
  7.444714478347571
  7.136102190189283
  ⋮
  5.561523649792561
  5.559441092538786
  5.557611194072916
  5.557166680703924
  5.556694338613228
  5.55571256417709
  5.554801978936346
  5.554524472632505
  5.55355785515645

Or the shannon diversity index:

shannon_diversity(sol)
43-element Vector{Float64}:
 16.71723451931988
 16.738036028994124
 16.671102062967147
 16.51655369628933
 16.28808045783551
 15.990836783182258
 15.715834566077367
 15.349174406804075
 14.983244696455223
 14.63562599609837
  ⋮
 14.53244329771246
 14.511036590832534
 14.49262313519923
 14.488209188829241
 14.483545850682042
 14.473911645940056
 14.465001114453996
 14.462280649869596
 14.452749656547581

For example, you can plot how a few of these properties evolve through time:

time = sol.t
plot(
    time,
    total_biomass(sol);
    xlabel = "Time",
    ylabel = "Observable",
    label = "Total biomass",
)
plot!(time, richness(sol); label = "Richness")
plot!(time, shannon_diversity(sol); label = "Shannon diversity")

Figure of the simulation