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: 35-element Vector{Float64}:
0.0
0.08712734730775361
0.23686251721713492
0.4121420441506616
0.660452066251864
0.9476141218874673
1.3625133467709114
1.7708844836550584
2.432745995291824
3.130438078299851
⋮
56.76151209685211
63.154425458937574
69.32817656542483
75.3291419326319
81.26831089158935
87.21812698922747
93.20009084086526
99.2089639640656
100.0
u: 35-element Vector{Vector{Float64}}:
[0.4569505571485645, 0.8674034191601074, 0.6393065207708892, 0.7399609167374255, 0.3569404150894674, 0.6099407820190381, 0.017654600799786757, 0.4056377219490618, 0.6122056988836555, 0.7384807877897548, 0.28771486304940674, 0.0813643638950372, 0.3961219861021582, 0.7802271581967881, 0.8465892649295682, 0.555984574577707, 0.4432736400438244, 0.6246449098887126, 0.449017295573661, 0.13569130852179068]
[0.47179611011282985, 0.89458218537784, 0.6444447922838141, 0.7564638100441291, 0.3572990369392244, 0.6290523482810296, 0.018104245647334035, 0.4093971053779308, 0.6156949345927085, 0.6349590235391096, 0.2883313511756693, 0.08234493340439984, 0.4140427159630399, 0.7496874416034157, 0.8164631417185659, 0.5261193837134991, 0.4114929025395907, 0.6229189802513695, 0.4395203115484049, 0.1183546081494504]
[0.4972678040383297, 0.9337732483914641, 0.653462762258424, 0.7841772732588825, 0.35793478685493596, 0.6566107220373072, 0.018856343270356436, 0.4158907224802691, 0.6151737270932426, 0.48376710792816935, 0.28900137096166173, 0.08361309887640972, 0.44310017913473504, 0.6962344498321212, 0.7627946183098558, 0.47762195834105237, 0.3636850772618559, 0.6175476905039345, 0.42186611078309305, 0.10019836691737928]
[0.5269087541112951, 0.9651510036856878, 0.6641592964109448, 0.8153281584426281, 0.35869974400879, 0.6786749336594984, 0.019695900651047076, 0.4233085577860116, 0.6036831418961222, 0.35281402672656736, 0.28944756678622513, 0.08452126583069842, 0.4730442247187549, 0.6350529386232368, 0.6990362059568962, 0.4259478355733977, 0.31770051482864375, 0.6079773725863598, 0.40042959367331366, 0.08853368119884383]
[0.568275661496249, 0.985699321650678, 0.6791817696045311, 0.8566392235157892, 0.3597994673407633, 0.6931241009695347, 0.02079578059244463, 0.432878496889492, 0.5721621922267284, 0.23796261310412792, 0.28926719631407966, 0.08494947429739348, 0.5053845278669731, 0.554643634604406, 0.6116011342077707, 0.36282155289251106, 0.2671584952343355, 0.5898075646333841, 0.3702341361410174, 0.08042175601967838]
[0.6145869671013686, 0.9879295297076152, 0.6958895384657641, 0.8998708275640405, 0.361031589851621, 0.6946923387886, 0.021922713264555225, 0.4417496566022917, 0.5254203503858093, 0.16656901245629985, 0.28679174481197756, 0.08446573041096002, 0.5258479899665618, 0.47364396306244716, 0.5203416899974688, 0.30402560049537836, 0.22391507863472151, 0.5643784637860702, 0.3368350888710489, 0.07712010094797525]
[0.6769924367608435, 0.9730986169838434, 0.7182412951040891, 0.9533237098377491, 0.36251194741538534, 0.6842635367975352, 0.023264349006890887, 0.44928099461493237, 0.4560909828931713, 0.11445814458409465, 0.27777169679863817, 0.08246440005586463, 0.5255960693298394, 0.3801808791342667, 0.41259255175701154, 0.24141913581022972, 0.17975686418539574, 0.5240055123332595, 0.29282340807483526, 0.07818930901741539]
[0.7314031166969424, 0.9502592345998314, 0.7379928822157891, 0.9953958834468846, 0.36333308397395514, 0.6682033386885342, 0.02425706179091035, 0.45019752651838163, 0.3945121853633898, 0.08730345485768364, 0.26367022393505424, 0.07956069693764758, 0.5008845230193167, 0.3116471958371872, 0.3326410493495141, 0.19843892251570786, 0.14930648492031548, 0.48466739667886255, 0.25506191827151126, 0.0831660309107537]
[0.8022140168548365, 0.907534628132908, 0.7653197509659633, 1.041851846474043, 0.36284908978888664, 0.6381602476604589, 0.025220483100706362, 0.43946429735625375, 0.3138000400437169, 0.06295649954063283, 0.2354458296554772, 0.07393474784548505, 0.4377657107043185, 0.23589990674037248, 0.2433655977109042, 0.15272303296621223, 0.11584103601374637, 0.42904027100553926, 0.2055160796581626, 0.09658977298171222]
[0.8542164202621665, 0.8607513659991712, 0.7880858284666248, 1.0646678012115485, 0.3598136153060319, 0.6052631909266002, 0.02550318153808655, 0.4165025671267801, 0.2515195408248547, 0.048347193427280194, 0.20524377857763598, 0.06771169291941276, 0.3675450384248708, 0.18606966450388296, 0.18311341827790986, 0.12248887171163307, 0.09312550779034175, 0.38491190134515874, 0.16707186318766493, 0.11600484636281885]
⋮
[0.839439431018743, 0.009660437098435707, 0.1385143239421074, 0.0679520697644837, 0.023448252133124393, 0.006793026668226647, 0.0010625034494528328, 0.011277444363798317, 0.0009997980526266978, 9.202323963167034e-6, 0.0048671719077538434, 0.00036657725919528474, 0.0008954423353152504, 0.3055567363138991, 1.290910701302058e-6, 0.00048648468208146485, 0.03214967975185618, 0.32287618735094026, 0.033868034563310466, 0.19933110693037076]
[0.8356168923726257, 0.005648382407205045, 0.10804256917114083, 0.053151664328413555, 0.016687469815127233, 0.003971829838910624, 0.0008087906494473192, 0.008308455924607962, 0.0005843486698322052, 3.54563037809532e-6, 0.004118996423080193, 0.00019794313340494026, 0.0006589551338541485, 0.3166621079115733, 3.31134011799078e-7, 0.000262692745432897, 0.02858369385736512, 0.3240855400808286, 0.02983617503919663, 0.19731649117891692]
[0.8329087504242698, 0.00336388502171454, 0.08498564108850598, 0.04249803037942603, 0.012014963425531449, 0.0023654168469307933, 0.0006307305900146612, 0.006194927644834831, 0.000347948822036236, 1.411337624816634e-6, 0.003586746024411124, 0.00010877605580629802, 0.0005110188852685419, 0.32549089849603574, 8.886410543148817e-8, 0.00014435835212405548, 0.02565294124278592, 0.3249375393070661, 0.026599408710922128, 0.19581284455429313]
[0.8309908502129665, 0.0020326252590337187, 0.06729591195735128, 0.03456389295523495, 0.008730514942618587, 0.0014293015368179365, 0.0005011922634768443, 0.004661027716318101, 0.00021023161647188037, 5.764056924366887e-7, 0.0031925675215761814, 6.062803293219194e-5, 0.00041261368674063597, 0.3326361129747542, 2.4719141013245385e-8, 8.046040202724739e-5, 0.02321509405609278, 0.32550123595186226, 0.02395175912820342, 0.19467375231146314]
[0.8295788367332347, 0.0012346002903983596, 0.05341482980197945, 0.028422840280636512, 0.006364737086425021, 0.0008681462972968835, 0.0004031180504467363, 0.0035189054018567034, 0.00012768836456885488, 2.375822566189504e-7, 0.0028877363868527644, 3.392926509433959e-5, 0.00034315445200795665, 0.33859255487410617, 6.965238788937494e-9, 4.502804415658504e-5, 0.021138891918029343, 0.3258946075622218, 0.021724798939727497, 0.1937722142647323]
[0.8284915372868463, 0.0007492163965706147, 0.042378677592008016, 0.023542960144280558, 0.004637367674476817, 0.0005268340252431194, 0.00032682330106178494, 0.0026560652047612422, 7.748625807040779e-5, 9.776973644359125e-8, 0.002644818576210592, 1.8938871942919343e-5, 0.00029201891912205495, 0.3436508943264127, 1.9582753537442866e-9, 2.513405904571941e-5, 0.019340177192955034, 0.32619609317956877, 0.01981399273648536, 0.19304251595969302]
[0.8276318035841195, 0.0004534361870414384, 0.0335803642552429, 0.019609863632460825, 0.0033730054207493252, 0.000318847281911319, 0.00026659069608637754, 0.0020020950809414603, 4.689537194812037e-5, 4.004150387937227e-8, 0.0024478623001935366, 1.0525181676575864e-5, 0.000253342489762576, 0.34798599944711023, 5.468901636878965e-10, 1.396812279407608e-5, 0.01776956291932811, 0.32643930013309985, 0.01815822679811541, 0.19244821177418464]
[0.8269437757644469, 0.00027380669492033897, 0.026580688771953975, 0.01641433976374777, 0.0024498453920939684, 0.00019253540617060117, 0.00021863481491721386, 0.0015073831376891946, 2.831758100546522e-5, 1.633322581523948e-8, 0.00228647221820559, 5.828066263007625e-6, 0.00022353115736179223, 0.35172119545322866, 1.5187690727737506e-10, 7.734511199488157e-6, 0.016393507329545573, 0.32663816381364447, 0.016716496400813338, 0.19196054966200954]
[0.8269795587999483, 0.0002562147780546222, 0.025775176455696387, 0.01604063708704291, 0.0023488536320806948, 0.00018016512114142882, 0.00021309146403125827, 0.0014521092653199663, 2.649818446243499e-5, 1.4514077062599594e-8, 0.0022674884010271197, 5.391408965175337e-6, 0.00022013678819599004, 0.3521722751376709, 1.282328086069516e-10, 7.155016888423675e-6, 0.0162257444715461, 0.32653606595462675, 0.016541264791767873, 0.19190360881209095]
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.
20
You can also get the trajectory of the species richness through time with:
richness(sol) # Richness at each time step.
35-element Vector{Int64}:
20
20
20
20
20
20
20
20
20
20
⋮
20
20
20
20
20
20
20
20
20
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
35-element Vector{Float64}:
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
⋮
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
Or the total biomass of the community:
total_biomass(sol)
35-element Vector{Float64}:
10.045110785126406
9.901069362263355
9.672577418533479
9.430114717154963
9.122808099601887
8.807027975172574
8.406325840495292
8.061902210528173
7.585492885200336
7.1679572881904745
⋮
1.9995552008203856
1.934546875445353
1.8881563260737073
1.8541403736507756
1.8283668625612675
1.8084116514327668
1.7928099412651604
1.7805628224243197
1.7791514502128671
Or the shannon diversity index:
shannon_diversity(sol)
35-element Vector{Float64}:
17.361598259882957
17.353097441515754
17.27994310358157
17.125031479065377
16.85427797085357
16.52697750677759
16.049366906394127
15.58196498477746
14.864921119666029
14.203358212761515
⋮
5.85365618131048
5.448491498254823
5.1326951374391765
4.8829736103591035
4.680522298519565
4.513625850824927
4.375047815739205
4.259668914679863
4.245747296577988
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")