add_missing_PU_rows_to_PU_Count_dataframe: Add missing PUs to PU_Count data frame

add_missing_PU_rows_to_PU_Count_dataframeR Documentation

Add missing PUs to PU_Count data frame

Description

When error is added to the input data, it sometimes results in planning units that appear to have no species on them. This function adds these planning units back into the PU_Count data frame so that the apparent problem has the same number of planning units as the correct problem.

Usage

add_missing_PU_rows_to_PU_Count_dataframe(
  marxan_solution,
  all_correct_node_IDs,
  PU_col_name,
  presences_col_name
)

Arguments

marxan_solution

data frame with one row for each planning unit. Has 2 columns, one for the planning unit IDs and the other for the count or indicator of presence/absence. The second column usually contains 0 or 1 to indicate presence or absence of that PU in the marxan solution. However, in the case of marxan's summed solution, the second column contains the number of iterations (restarts) where that planning unit appeared in marxan's solution.

all_correct_node_IDs

numeric vector containing all planning unit IDs that appear in the correct problem, not to be confused with the set of planning IDs that appear in the correct solution

PU_col_name

character string giving planning unit column name in data frames

presences_col_name

character string giving column name for species counts (presences) in data frames

Details

When the pu_spp_pair_indices are written out in marxan's input format, there is no record of the empty planning units in those pairs since each pair is a planning unit ID followed by the ID of a species on that planning unit.

Consequently, marxan's output solutions will have fewer planning units than the problem generator generated and you will get size warnings (that should be errors) when comparing them to things like nodes$dependent_set_member. For example, here is the error that showed this was happening:

Error in marxan_best_df_sorted$SOLUTION - nodes$dependent_set_member : (converted from warning) longer object length is not a multiple of shorter object length

To fix this, you need to add entries for each of the missing PUs.

NOTE: There could also be correct problems that have some patches with no species on them.

NOTE: Not sure if matters, but I had commented in here that the old name for this function was: add_missing_PUs_to_marxan_solutions(). Probably don't need to track that anymoe, but will leave it here for the moment.

Value

Returns marxan solution data frame that includes all planning unit IDs from the correct problem rather than only the IDs that occurred in the apparent problem (see description of marxan_solution in input argument list for this function)


langfob/bdpg documentation built on Dec. 8, 2022, 5:33 a.m.