Biological Condition Gradient fuzzy membership for metrics.

BCG.Metric.Membership(
  df.metrics,
  df.rules,
  input.shape = "wide",
  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_LOWER = "LOWER",
  col_UPPER = "UPPER",
  col_METRIC_VALUE = "METRIC_VALUE",
  col_INCREASE = "INCREASE",
  ...
)

Arguments

df.metrics

Wide data frame with metric values to be evaluated.

df.rules

Data frame of metric thresholds to check.

input.shape

Shape of df.metrics; wide or long. Default is wide.

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 index class 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). Default = "RULE_TYPE"

col_LOWER

Column name for lower limit. Default = "LOWER"

col_UPPER

Column name for upper limit. Default = "UPPER"

col_METRIC_VALUE

Column name for metric value. Default = "METRIC_VALUE"

col_INCREASE

Column name for if the metric value increases. Default = "INCREASE"

...

Arguments passed to `BCG.MetricMembership` used internally

Value

Returns a data frame of results in the long format.

Details

Converts metric values into BCG membership values. Uses a rules table to define the metrics, scoring range, and direction for each named index.

Deprecated col_SITE_TYPE for col_INDEX_CLASS in v2.0.0.9001.

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[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'

# Run function
df_met_memb <- BCG.Metric.Membership(df_met_val_bugs, df_rules)

# Show Results
#View(df_met_memb)

# Save Results
write.table(df_met_memb
            , file.path(tempdir(), "Metric_Membership.tsv")
            , row.names = FALSE
            , col.names = TRUE
            , sep = "\t")