This script provides an example of how the dia models are loaded, and QPress used to simulate press perturbations. Here we load just one model version, but for the study, this was repeated for all 128 model versions.
#install.packages(c("tcltk2","XML","devtools"))
#devtools::install_github("SWotherspoon/QPress",ref="Constrain")
library(XML)
source("dia.r")
library(QPress)
##
## Attaching package: 'QPress'
## The following object is masked _by_ '.GlobalEnv':
##
## model.dia
library(DiagrammeR)
set.seed(32)#set random seed
mod<-model.dia("Dia_models/Model_NP_5N.dia") #load the dia model
mod<- enforce.limitation(mod)#enforce self-limitation of nodes
mod
## From To Group Type Pair
## 1 PreRecruits SmallFish 0 P 1
## 2 SmallFish BigFish 0 P 2
## 3 BigFish DeepPredators 0 P 3
## 4 BigFish PreRecruits 0 P 4
## 5 BigFish Catch 0 P 5
## 6 BigFish SmallFish 4 N 6
## 7 DeepPrey BigFish 0 P 7
## 8 ShallowPrey SmallFish 0 P 8
## 9 ShallowPrey BigFish 4 P 9
## 10 PreRecruits ShallowPrey 4 P 10
## 11 TempDepth DeepPrey 0 N 11
## 12 TempDepth BigFish 0 N 12
## 13 SST PreRecruits 0 N 13
## 14 SST ShallowPrey 0 N 14
## 15 TempDepth SmallFish 0 N 15
## 16 Catch BigFish 4 N 16
## 17 Downwelling TempDepth 0 P 17
## 18 Downwelling ShallowPrey 0 N 18
## 19 Downwelling PreRecruits 0 N 19
## 20 LocalDepletion BigFish 0 N 20
## 21 Quota Effort 0 P 21
## 22 DeepPredators Depredation 4 P 22
## 23 Depredation Landings 0 N 23
## 24 BigFish Quota 0 P 24
## 25 LocalDepletion Catch 0 N 25
## 26 Bycatch DeepPrey 0 N 26
## 27 Bycatch ChangeTactic 4 P 27
## 28 ChangeTactic Catch 0 P 28
## 29 Landings ChangeTactic 4 N 29
## 30 Effort Bycatch 4 P 30
## 31 ChangeTactic Effort 0 N 31
## 32 TempDepth LiceMBPs 0 N 32
## 33 TempDepth Catch 4 N 33
## 34 Catch Landings 0 P 34
## 35 LiceMBPs Catch 0 N 35
## 36 Effort Catch 0 P 36
## 37 LiceMBPs ChangeTactic 0 P 37
## 40 DeepPredators BigFish 0 N 3
## 44 BigFish DeepPrey 0 N 7
## 45 SmallFish ShallowPrey 0 N 8
## 46 BigFish ShallowPrey 4 N 9
## 47 ShallowPrey PreRecruits 4 N 10
## 110 BigFish BigFish 0 N 38
## 210 Bycatch Bycatch 0 N 39
## 38 Catch Catch 0 N 40
## 41 ChangeTactic ChangeTactic 0 N 41
## 51 DeepPredators DeepPredators 0 N 42
## 61 DeepPrey DeepPrey 0 N 43
## 71 Depredation Depredation 0 N 44
## 81 Downwelling Downwelling 0 N 45
## 91 Effort Effort 0 N 46
## 101 Landings Landings 0 N 47
## 111 LiceMBPs LiceMBPs 0 N 48
## 121 LocalDepletion LocalDepletion 0 N 49
## 131 PreRecruits PreRecruits 0 N 50
## 141 Quota Quota 0 N 51
## 151 ShallowPrey ShallowPrey 0 N 52
## 161 SmallFish SmallFish 0 N 53
## 171 SST SST 0 N 54
## 181 TempDepth TempDepth 0 N 55
#visualise the model
grViz(grviz.digraph(mod))
Run the simulations
sims <- system.simulate(10000, mod)
#str(sims)
‘sims’ contains all the simulated edge weights and node responses. The former in the matrix w and the latter in the matrices in A.
Use the impact table function to get the mean responses of each node to a press increase of each of the other nodes, averaged over the 10000 simulations for this model version
impacts_5N<-impact.table(sims)
impacts_5N
## BigFish Bycatch Catch ChangeTactic DeepPredators DeepPrey
## BigFish 0.9508 -0.8260 -0.5271 0.2324 -0.8558 0.9507
## Bycatch 0.3615 0.9484 0.0569 -0.4407 -0.4423 0.3610
## Catch 0.9790 -0.7206 0.9512 0.2530 -0.8124 0.9790
## ChangeTactic -0.0296 0.5073 -0.4527 0.9982 0.2552 -0.0296
## DeepPredators 0.9508 -0.8260 -0.5272 0.2323 0.9312 0.9506
## DeepPrey -0.9464 -0.8514 0.2423 0.4045 0.9712 0.9118
## Depredation 0.4253 -0.3390 -0.3270 0.1275 0.4295 0.4251
## Downwelling 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## Effort 0.8823 -0.9465 0.0456 -0.9924 -0.9926 0.8820
## Landings 0.6699 -0.4867 0.9830 0.1830 -0.9884 0.6700
## LiceMBPs 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## LocalDepletion 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## PreRecruits 0.8779 -0.7711 -0.4612 0.2025 -0.7976 0.8776
## Quota 0.9508 -0.8257 -0.5269 0.2320 -0.8558 0.9506
## ShallowPrey -0.3597 0.3463 0.0903 -0.0421 0.3584 -0.3597
## SmallFish 0.3028 -0.3015 -0.0536 0.0153 -0.3109 0.3023
## SST 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## TempDepth 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## Depredation Downwelling Effort Landings LiceMBPs LocalDepletion
## BigFish 0.1088 -0.8812 -0.6178 -0.1088 0.4730 -0.4790
## Bycatch -0.2641 -0.0075 0.4373 0.2642 -0.3881 -0.2888
## Catch 0.1831 -0.4982 0.8080 -0.1831 -0.4488 -0.9762
## ChangeTactic 0.4072 -0.7296 -0.0791 -0.4072 0.9972 0.2869
## DeepPredators 0.1087 -0.8812 -0.6176 -0.1087 0.4732 -0.4787
## DeepPrey 0.2538 -0.0302 -0.0937 -0.2539 0.1523 0.6406
## Depredation 0.9992 -0.3829 -0.3628 -0.0734 0.2803 -0.1294
## Downwelling 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
## Effort -0.4052 -0.0268 0.9872 0.4052 -0.9012 -0.7121
## Landings -0.9976 -0.2913 0.8960 0.9976 -0.5132 -0.8900
## LiceMBPs 0.0000 -1.0000 0.0000 0.0000 1.0000 0.0000
## LocalDepletion 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000
## PreRecruits 0.0900 -0.8916 -0.5470 -0.0899 0.4161 -0.4673
## Quota 0.1084 -0.8812 -0.6176 -0.1087 0.4728 -0.4789
## ShallowPrey -0.0041 0.2520 0.1221 0.0046 -0.0896 0.2844
## SmallFish -0.0060 -0.8838 -0.0843 0.0054 0.0537 -0.2625
## SST 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## TempDepth 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000
## PreRecruits Quota ShallowPrey SmallFish SST TempDepth
## BigFish 0.7291 -0.6176 0.7623 0.6244 -0.8409 -0.8696
## Bycatch 0.2599 0.4373 0.2748 0.1981 -0.3106 0.0525
## Catch 0.7519 0.8080 0.7833 0.6409 -0.8655 -0.4038
## ChangeTactic -0.0276 -0.0790 -0.0324 -0.0301 0.0281 -0.7648
## DeepPredators 0.7291 -0.6175 0.7620 0.6241 -0.8408 -0.8696
## DeepPrey -0.7229 -0.0940 -0.7600 -0.6227 0.8356 -0.2998
## Depredation 0.3051 -0.3627 0.3124 0.2294 -0.3608 -0.3741
## Downwelling 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## Effort 0.6784 0.9872 0.7183 0.5901 -0.7812 0.1080
## Landings 0.5229 0.8960 0.5604 0.4678 -0.5995 -0.2214
## LiceMBPs 0.0000 0.0000 0.0000 0.0000 0.0000 -1.0000
## LocalDepletion 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
## PreRecruits 0.9950 -0.5467 0.2613 0.7881 -0.7878 -0.8990
## Quota 0.7288 0.9596 0.7621 0.6244 -0.8407 -0.8696
## ShallowPrey -0.4915 0.1218 0.8474 -0.9172 -0.2310 0.7030
## SmallFish 0.9914 -0.0839 0.6486 0.9966 -0.9104 -0.7648
## SST 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000
## TempDepth 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000
For Figures 2 and 3 of the paper (the first two analyses), use the data from the impact tables.
For investigating the effects of edge strength on node responses to perturbation (e.g. Figs 5 & 6), the edge weights and node responses for each individual simulation is required. For that, the simulation data (sims) need to be saved. That data has been compiled in ‘savedsims.Rdata’
Note that originally the node that represents fishery behaviour was called ‘MoveOn’, but following further discussion with fishery partners, this was changed to ‘ChangeTactic’ as being more indicative. I have updated most of this example code to reflect this change, but if you dig deep into the saved simulation data, no doubt you will find that it is still called MoveOn. Sorry if that causes any confusion.