Evaluate number of planning units selected.
Calculate the number of planning units selected within a solution
to a conservation planning problem()
.
eval_n_summary(x, solution) ## Default S3 method: eval_n_summary(x, solution) ## S3 method for class 'ConservationProblem' eval_n_summary(x, solution)
x |
|
solution |
|
This summary statistic is calculated as the sum of the values in
the solution. As a consequence, this metric can produce a
non-integer value (e.g. 4.3) for solutions containing proportion values
(e.g. generated by solving a problem()
built using the
add_proportion_decisions()
function).
tibble::tibble()
object containing the number of planning
units selected within a solution.
It contains the following columns:
character
description of the summary statistic.
The statistic associated with the "overall"
value
in this column is calculated using the entire solution
(including all management zones if there are multiple zones).
If multiple management zones are present, then summary statistics
are also provided for each zone separately
(indicated using zone names).
numeric
number of selected planning units.
Broadly speaking, the argument to solution
must be in the same format as
the planning unit data in the argument to x
.
Further details on the correct format are listed separately
for each of the different planning unit data formats:
x
has numeric
planning unitsThe argument to solution
must be a
numeric
vector with each element corresponding to a different planning
unit. It should have the same number of planning units as those
in the argument to x
. Additionally, any planning units missing
cost (NA
) values should also have missing (NA
) values in the
argument to solution
.
x
has matrix
planning unitsThe argument to solution
must be a
matrix
vector with each row corresponding to a different planning
unit, and each column correspond to a different management zone.
It should have the same number of planning units and zones
as those in the argument to x
. Additionally, any planning units
missing cost (NA
) values for a particular zone should also have a
missing (NA
) values in the argument to solution
.
x
has Raster
planning unitsThe argument to solution
be a Raster
object where different grid cells (pixels) correspond
to different planning units and layers correspond to
a different management zones. It should have the same dimensionality
(rows, columns, layers), resolution, extent, and coordinate reference
system as the planning units in the argument to x
. Additionally,
any planning units missing cost (NA
) values for a particular zone
should also have missing (NA
) values in the argument to solution
.
x
has data.frame
planning unitsThe argument to solution
must
be a data.frame
with each column corresponding to a different zone,
each row corresponding to a different planning unit, and cell values
corresponding to the solution value. This means that if a data.frame
object containing the solution also contains additional columns, then
these columns will need to be subsetted prior to using this function
(see below for example with sf::sf()
data).
Additionally, any planning units missing cost
(NA
) values for a particular zone should also have missing (NA
)
values in the argument to solution
.
x
has Spatial
planning unitsThe argument to solution
must be a Spatial
object with each column corresponding to a
different zone, each row corresponding to a different planning unit, and
cell values corresponding to the solution value. This means that if the
Spatial
object containing the solution also contains additional
columns, then these columns will need to be subsetted prior to using this
function (see below for example with sf::sf()
data).
Additionally, the argument to solution
must also have the same
coordinate reference system as the planning unit data.
Furthermore, any planning units missing cost
(NA
) values for a particular zone should also have missing (NA
)
values in the argument to solution
.
x
has sf::sf()
planning unitsThe argument to solution
must be
a sf::sf()
object with each column corresponding to a different
zone, each row corresponding to a different planning unit, and cell values
corresponding to the solution value. This means that if the
sf::sf()
object containing the solution also contains additional
columns, then these columns will need to be subsetted prior to using this
function (see below for example).
Additionally, the argument to solution
must also have the same
coordinate reference system as the planning unit data.
Furthermore, any planning units missing cost
(NA
) values for a particular zone should also have missing (NA
)
values in the argument to solution
.
## Not run: # set seed for reproducibility set.seed(500) # load data data(sim_pu_raster, sim_pu_sf, sim_features, sim_pu_zones_sf, sim_features_zones) # build minimal conservation problem with raster data p1 <- problem(sim_pu_raster, sim_features) %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s1 <- solve(p1) # print solution print(s1) # plot solution plot(s1, main = "solution", axes = FALSE, box = FALSE) # calculate number of selected planning units within solution r1 <- eval_n_summary(p1, s1) print(r1) # build minimal conservation problem with polygon (sf) data p2 <- problem(sim_pu_sf, sim_features, cost_column = "cost") %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s2 <- solve(p2) # plot solution plot(s2[, "solution_1"]) # print first six rows of the attribute table print(head(s2)) # calculate number of selected planning units within solution r2 <- eval_n_summary(p2, s2[, "solution_1"]) print(r2) # manually calculate number of selected planning units r2_manual <- sum(s2$solution, na.rm = TRUE) print(r2_manual) # build multi-zone conservation problem with polygon (sf) data p3 <- problem(sim_pu_zones_sf, sim_features_zones, cost_column = c("cost_1", "cost_2", "cost_3")) %>% add_min_set_objective() %>% add_relative_targets(matrix(runif(15, 0.1, 0.2), nrow = 5, ncol = 3)) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s3 <- solve(p3) # print first six rows of the attribute table print(head(s3)) # create new column representing the zone id that each planning unit # was allocated to in the solution s3$solution <- category_vector( s3[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) s3$solution <- factor(s3$solution) # plot solution plot(s3[, "solution"]) # calculate number of selected planning units within solution r3 <- eval_n_summary( p3, s3[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) print(r3) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.