R/change-avail.R
change_avail.Rd
Change the availability of predator XXX on specific preygroups.
change_avail( dietmatrix, pred = NULL, pred_stanza = NULL, prey = NULL, roc, relative = TRUE, consecutive = FALSE )
dietmatrix | Dataframe in 'long' format containing information about availabilities
with columns 'pred', 'prey', 'pred_stanza', 'prey_stanza', 'code', 'prey_id' and
'avail'. The dataframe should be generated with |
---|---|
pred | Character vector of predator Acronyms (see |
pred_stanza | Integer vector indicating if the predator is juvenile (= 1) or
adult (= 2). |
prey | List of character vectors of prey Acronyms (see |
roc | Vector of multiplication factors which shall be applied to the old set of parameters. Please supply one value per selected group. In case relative is FALSE the new absolute values can be passed as roc. |
relative | Logical if TRUE values are changed relative to base values. If FALSE new values can
be passed directly. Default is |
consecutive | Boolean indicating if multiple calls to change_avail are performed one after
another |
parameterfile *.prm file with the new parameter values.
d <- system.file("extdata", "setas-model-new-trunk", package = "atlantistools") dm <- load_dietmatrix(prm_biol = file.path(d, "VMPA_setas_biol_fishing_Trunk.prm"), fgs = file.path(d, "SETasGroupsDem_NoCep.csv")) dm1 <- change_avail(dietmatrix = dm, pred = "FPS", pred_stanza = 1, prey = "CEP", roc = 0.1234, relative = FALSE) # Show only rows with availability of 0.1234 dm1[apply(apply(dm1[, 5:ncol(dm1)], MARGIN = 2, function(x) x == 0.1234), MARGIN = 1, any), ]#> pred pred_stanza prey_stanza code FPS FVS CEP BML PL DL DR DC DLsed #> 6 FPS 1 1 pPREY1FPS1 0 0 0.1234 0.01 0 0 0 0 0 #> 7 FPS 1 2 pPREY2FPS1 0 0 0.1234 0.01 0 0 0 0 0 #> DRsed DCsed #> 6 0 0 #> 7 0 0dm2 <- change_avail(dietmatrix = dm, pred = c("FPS", "FVS"), pred_stanza = c(1, 2), prey = list(c("FPS", "FVS"), c("FPS", "FVS")), roc = list(c(0.1111, 0.2222), c(0.3333, 0.4444)), relative = FALSE) # Show only rows with availability of 0.1111, 0.2222, 0.3333 or 0.4444 dm2[apply(apply(dm2[, 5:ncol(dm2)], MARGIN = 2, function(x) is.element(x, c(0.1111, 0.2222, 0.3333, 0.4444))), MARGIN = 1, any), ]#> pred pred_stanza prey_stanza code FPS FVS CEP BML PL DL #> 6 FPS 1 1 pPREY1FPS1 0.1111 0.2222 0e+00 0.01 0.000 0.000 #> 7 FPS 1 2 pPREY2FPS1 0.1111 0.2222 0e+00 0.01 0.000 0.000 #> 12 FVS 2 1 pPREY1FVS2 0.3333 0.4444 1e-03 0.00 0.020 0.001 #> 13 FVS 2 2 pPREY2FVS2 0.3333 0.4444 5e-04 0.00 0.004 0.000 #> DR DC DLsed DRsed DCsed #> 6 0e+00 0 0.000 0.00 0 #> 7 0e+00 0 0.000 0.00 0 #> 12 0e+00 0 0.004 0.01 0 #> 13 1e-04 0 0.008 0.01 0