Biological Condition Gradient Level assignment given metric memberships.
BCG.Level.Membership(
df.metric.membership,
df.rules,
col_SAMPLEID = "SAMPLEID",
col_INDEX_NAME = "INDEX_NAME",
col_INDEX_CLASS = "INDEX_CLASS",
col_LEVEL = "LEVEL",
col_METRIC_NAME = "METRIC_NAME",
col_RULE_TYPE = "RULE_TYPE",
col_EXC_RULE = "EXC_RULE",
col_MEMBERSHIP = "MEMBERSHIP",
...
)Data frame of metric memberships (long format, the same as the output of BCG.Metric.Membership).
Data frame of BCG model rules.
column name for sample id. Default = SAMPLEID
column name for index name. Default = INDEX_NAME
column name for site type.Default = INDEX_CLASS
column name for level. Default = LEVEL
column name for metric name. Default = METRIC_NAME
column name for rule type (e.g., Rule0, Rule1, or Rule2). Default = RULE_TYPE
column name for exception rules. Default = EXC_RULE
column name for metric membership. Default = MEMBERSHIP
Arguments passed to BCG.MetricMembership used internally
Returns a data frame of results in the wide format.
Input is metric memberships and a rules tables.
Output is a data frame with the membership for each row to each Level (1:6).
Minimum of:
1- sum of previous levels
Rule0 memberships
max of Rule1 (Alternate1) rules (and min of Rule2 (Alternate2) rules)
That is, perform calculations in this order:
Min of Rule2 (Alternate2) metric memberships
Max of Rule1 (Alternate1) rules and the above result.
Min of: Rule0, the above results, and 1 - the sum of previous levels.
Some exceptions exist for particular models.
| Index_Name | INDEX_CLASS |
| CT_BCG_2015 | fish02 |
| CT_BCG_2015 | fish03 |
| BCG_NMSandyRivers | bugs |
These exceptions are mostly hard coded into the function but gather some information with the parameter col_EXC_RULE from the rules table. A future update may fully automate this process.
2021 saw the introduction of Median Exception rule. For the Pacific Northwest some metrics were grouped and the 2nd of 3 values is used and the other 2 values tossed when determining level membership. This equates to using the median of the 3 values. This is handled by including "MEDIAN" in the Exc_Rule column in Rules.xlsx. Superceded by "SMALL2".
2024 added SMALL2 and SMALL3 Exception rules. For New Mexico BCG some metrics are grouped so use the 2nd or 3rd smallest value instead of the minimum. As above, this is handled by including "SMALL2" or "SMALL3" in the Exc_Rule column in Rules.xlsx.
Some Great Plains rules use multiple groupings of SMALL2. These are coded as "SMALL2A" and "SMALL2B". If additional groupings are needed the code needs to be tweaked.
Deprecated col_SITE_TYPE for col_INDEX_CLASS in v2.0.0.9001.
# library(readxl)
# library(BioMonTools)
# Calculate Metrics
df_samps_bugs <- readxl::read_excel(
system.file("extdata/Data_BCG_PugLowWilVal.xlsx"
, package="BCGcalc")
, guess_max = 10^6)
myDF <- df_samps_bugs[1:500, ]
myCols <- c("Area_mi2",
"SurfaceArea",
"Density_m2",
"Density_ft2")
# populate missing columns prior to metric calculation
col_missing <- c("INFRAORDER",
"HABITAT",
"ELEVATION_ATTR",
"GRADIENT_ATTR",
"WSAREA_ATTR",
"HABSTRUCT",
"UFC",
"SAMP_AREA_M2")
myDF[, col_missing] <- NA
df_met_val_bugs <- BioMonTools::metric.values(myDF
, "bugs"
, fun.cols2keep = myCols)
#> Joining with `by = join_by(SAMPLEID, INDEX_NAME, INDEX_CLASS)`
# Import Rules
df_rules <- readxl::read_excel(system.file("extdata/Rules.xlsx"
, package = "BCGcalc")
, sheet="Rules")
#> Warning: Expecting logical in S2409 / R2409C19: got '1'
#> Warning: Expecting logical in S2410 / R2410C19: got '11'
#> Warning: Expecting logical in S2411 / R2411C19: got '12'
#> Warning: Expecting logical in S2412 / R2412C19: got '15'
#> Warning: Expecting logical in S2413 / R2413C19: got '16'
#> Warning: Expecting logical in S2414 / R2414C19: got '17'
#> Warning: Expecting logical in S2415 / R2415C19: got '18'
#> Warning: Expecting logical in S2416 / R2416C19: got '19'
#> Warning: Expecting logical in S2417 / R2417C19: got '25'
#> Warning: Expecting logical in S2418 / R2418C19: got '29'
#> Warning: Expecting logical in S2419 / R2419C19: got '4'
#> Warning: Expecting logical in S2420 / R2420C19: got '5'
#> Warning: Expecting logical in S2421 / R2421C19: got '8'
#> Warning: Expecting logical in S2422 / R2422C19: got '9'
#> Warning: Expecting logical in S2423 / R2423C19: got '1'
#> Warning: Expecting logical in S2424 / R2424C19: got '11'
#> Warning: Expecting logical in S2425 / R2425C19: got '12'
#> Warning: Expecting logical in S2426 / R2426C19: got '15'
#> Warning: Expecting logical in S2427 / R2427C19: got '16'
#> Warning: Expecting logical in S2428 / R2428C19: got '17'
#> Warning: Expecting logical in S2429 / R2429C19: got '18'
#> Warning: Expecting logical in S2430 / R2430C19: got '19'
#> Warning: Expecting logical in S2431 / R2431C19: got '25'
#> Warning: Expecting logical in S2432 / R2432C19: got '29'
#> Warning: Expecting logical in S2433 / R2433C19: got '4'
#> Warning: Expecting logical in S2434 / R2434C19: got '5'
#> Warning: Expecting logical in S2435 / R2435C19: got '8'
#> Warning: Expecting logical in S2436 / R2436C19: got '9'
#> Warning: Expecting logical in S2437 / R2437C19: got '1'
#> Warning: Expecting logical in S2438 / R2438C19: got '12'
#> Warning: Expecting logical in S2439 / R2439C19: got '15'
#> Warning: Expecting logical in S2440 / R2440C19: got '19'
#> Warning: Expecting logical in S2441 / R2441C19: got '25'
#> Warning: Expecting logical in S2442 / R2442C19: got '29'
#> Warning: Expecting logical in S2443 / R2443C19: got '4'
#> Warning: Expecting logical in S2444 / R2444C19: got '5'
#> Warning: Expecting logical in S2445 / R2445C19: got '9'
#> Warning: Expecting logical in S2446 / R2446C19: got '1'
#> Warning: Expecting logical in S2447 / R2447C19: got '19'
#> Warning: Expecting logical in S2448 / R2448C19: got '29'
#> Warning: Expecting logical in S2449 / R2449C19: got '4'
#> Warning: Expecting logical in S2450 / R2450C19: got '1'
#> Warning: Expecting logical in S2451 / R2451C19: got '11'
#> Warning: Expecting logical in S2452 / R2452C19: got '12'
#> Warning: Expecting logical in S2453 / R2453C19: got '15'
#> Warning: Expecting logical in S2454 / R2454C19: got '16'
#> Warning: Expecting logical in S2455 / R2455C19: got '17'
#> Warning: Expecting logical in S2456 / R2456C19: got '18'
#> Warning: Expecting logical in S2457 / R2457C19: got '19'
#> Warning: Expecting logical in S2458 / R2458C19: got '25'
#> Warning: Expecting logical in S2459 / R2459C19: got '29'
#> Warning: Expecting logical in S2460 / R2460C19: got '4'
#> Warning: Expecting logical in S2461 / R2461C19: got '5'
#> Warning: Expecting logical in S2462 / R2462C19: got '8'
#> Warning: Expecting logical in S2463 / R2463C19: got '9'
#> Warning: Expecting logical in S2464 / R2464C19: got '1'
#> Warning: Expecting logical in S2465 / R2465C19: got '11'
#> Warning: Expecting logical in S2466 / R2466C19: got '12'
#> Warning: Expecting logical in S2467 / R2467C19: got '15'
#> Warning: Expecting logical in S2468 / R2468C19: got '16'
#> Warning: Expecting logical in S2469 / R2469C19: got '17'
#> Warning: Expecting logical in S2470 / R2470C19: got '19'
#> Warning: Expecting logical in S2471 / R2471C19: got '25'
#> Warning: Expecting logical in S2472 / R2472C19: got '29'
#> Warning: Expecting logical in S2473 / R2473C19: got '4'
#> Warning: Expecting logical in S2474 / R2474C19: got '5'
#> Warning: Expecting logical in S2475 / R2475C19: got '8'
#> Warning: Expecting logical in S2476 / R2476C19: got '9'
#> Warning: Expecting logical in S2477 / R2477C19: got '1'
#> Warning: Expecting logical in S2478 / R2478C19: got '12'
#> Warning: Expecting logical in S2479 / R2479C19: got '15'
#> Warning: Expecting logical in S2480 / R2480C19: got '19'
#> Warning: Expecting logical in S2481 / R2481C19: got '25'
#> Warning: Expecting logical in S2482 / R2482C19: got '29'
#> Warning: Expecting logical in S2483 / R2483C19: got '4'
#> Warning: Expecting logical in S2484 / R2484C19: got '5'
#> Warning: Expecting logical in S2485 / R2485C19: got '9'
#> Warning: Expecting logical in S2486 / R2486C19: got '1'
#> Warning: Expecting logical in S2487 / R2487C19: got '19'
#> Warning: Expecting logical in S2488 / R2488C19: got '29'
#> Warning: Expecting logical in S2489 / R2489C19: got '4'
# Calculate Metric Memberships
df_met_memb <- BCG.Metric.Membership(df_met_val_bugs, df_rules)
# Calculate Level Memberships
df_lev_memb <- BCG.Level.Membership(df_met_memb, df_rules)
# Show results
#View(df_lev_memb)
# Save Results
write.table(df_lev_memb
, file.path(tempdir(), "Level_Membership.tsv")
, row.names = FALSE
, col.names = TRUE
, sep = "\t")