Convenience wrapper around add_effects that keeps only negative
effects, represented by rows with loss > 0.
This function is useful when the workflow is focused only on damaging
consequences of actions and a loss-only wrapper is more convenient than
calling add_effects(..., component = "loss") directly. Internally,
it calls add_effects() with component = "loss".
The canonical stored result therefore contains only rows whose effect
satisfies \(\mathrm{loss}_{iaf} > 0\).
In addition, a mirror table containing only the loss component is stored in
x$data$dist_loss.
Arguments
- x
A
Problemobject created withcreate_problem. It must already contain feasible actions; runadd_actionsfirst.- losses
Alias of
effects, used for symmetry withadd_benefits().- effect_type
Character string indicating how supplied effect values are interpreted. Must be one of:
"delta": values represent signed net changes,"after": values represent after-action amounts and are converted to net changes relative to baseline feature amounts.
- effect_aggregation
Character string giving the aggregation used when converting raster values to planning-unit level. Must be one of
"sum"or"mean".
Value
An updated Problem object containing:
dist_effectsThe canonical filtered effects table, containing only rows with
loss > 0.dist_lossA convenience table containing only the loss component.
losses_metaMetadata for the stored loss table.
Examples
pu <- data.frame(id = 1:2, cost = c(1, 2))
features <- data.frame(id = 1, name = "sp1")
dist_features <- data.frame(pu = 1:2, feature = 1, amount = c(5, 10))
p <- create_problem(
pu = pu,
features = features,
dist_features = dist_features
)
p <- add_actions(
p,
data.frame(id = "harvest")
)
eff <- data.frame(
pu = c(1, 2),
action = c("harvest", "harvest"),
feature = c(1, 1),
delta = c(2, -4)
)
p <- add_losses(p, losses = eff)
p$data$dist_loss
#> pu action feature loss internal_pu internal_action internal_feature
#> 2 2 harvest 1 4 2 1 1
#> feature_name action_name
#> 2 sp1 harvest
