split_mets: Split metrics

Description Usage Arguments Details Value Examples

Description

Split metrics into BCG levels for calibration

Usage

1
split_mets(met_in, splt, bcgs, both = FALSE)

Arguments

met_in

input data.frame of coral metrics

splt

list of split values for each metric from 0 to 1

bcgs

list of BCG levels for each metric

both

logical if a data.frame is returned in long format that includes raw and bcg levels fore ach metric

Details

The inputs for splt and bcgs are separate lists where each element is named as a metric in met_in. Numeric values for for each elemene tin splt must be monotonic in the range from and including zero to one. These values are converted to the scale of each metric for assigning BCG levels. Numeric values in each element of bcgs are the BCG levels assigned to each split in splt, with total length of each element equal to the length of each element in splt - 1.

This is splitting into definite, crisp intervals (no fuzzy logic).

Value

A data.frame with metric values converted to BCG levels. This will have the same dimensions as met_in unless both = TRUE. NA values are returned for non-unique metrics.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(dplyr)

# get metrics, number of metrics, and number of bcg levels
met_in <- get_stony_mets(crl_dem) 
nmets <- ncol(met_in) - 1
nbcgs <- 4

# setup splits, these may differ by metric
splt <- rep(seq(0, 1, length = nbcgs + 1), times = nmets) %>% 
 matrix(nrow = nbcgs + 1) %>% 
 data.frame %>% 
 as.list
names(splt) <- names(met_in)[-1]

# setup bcg levels, one minus splts, reverse for bleached, diseased
# this approach can include non-monotonic change
bcgs <- rep(seq(nbcgs + 1, 2), times = nmets) %>% 
 matrix(ncol = nmets) %>% 
 data.frame
names(bcgs) <- names(met_in)[-1]
bcgs[, names(bcgs) %in% c('bleached', 'diseased')] <- seq(2, nbcgs + 1)
bcgs <- as.list(bcgs)

split_mets(met_in, splt = splt, bcgs = bcgs)

USEPA/CoralBCG documentation built on May 20, 2019, 3:28 p.m.