BCG.Level.Membership: BCG Level Membership

View source: R/BCG.Level.Membership.R

BCG.Level.MembershipR Documentation

BCG Level Membership

Description

Biological Condition Gradient Level assignment given metric memberships.

Usage

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",
  ...
)

Arguments

df.metric.membership

Data frame of metric memberships (long format, the same as the output of BCG.Metric.Membership).

df.rules

Data frame of BCG model rules.

col_SAMPLEID

column name for sample id. Default = SAMPLEID

col_INDEX_NAME

column name for index name. Default = INDEX_NAME

col_INDEX_CLASS

column name for site type.Default = INDEX_CLASS

col_LEVEL

column name for level. Default = LEVEL

col_METRIC_NAME

column name for metric name. Default = METRIC_NAME

col_RULE_TYPE

column name for rule type (e.g., Rule0, Rule1, or Rule2). Default = RULE_TYPE

col_EXC_RULE

column name for exception rules. Default = EXC_RULE

col_MEMBERSHIP

column name for metric membership. Default = MEMBERSHIP

...

Arguments passed to BCG.MetricMembership used internally

Details

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:

  1. Min of Rule2 (Alternate2) metric memberships

  2. Max of Rule1 (Alternate1) rules and the above result.

  3. 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.

Value

Returns a data frame of results in the wide format.

Examples

# 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
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")
myDF[, col_missing] <- NA
df_met_val_bugs <- BioMonTools::metric.values(myDF
                                              , "bugs"
                                              , fun.cols2keep = myCols)


# Import Rules
df_rules <- readxl::read_excel(system.file("extdata/Rules.xlsx"
                                           , package = "BCGcalc")
                      , sheet="Rules")

# 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")

leppott/BCGcalc documentation built on Oct. 9, 2024, 11:03 a.m.