binData: Construct bins either double in size or are of equal width,...

View source: R/fitting.R

binDataR Documentation

Construct bins either double in size or are of equal width, and encompass the data

Description

Construct bins that start from floor(min(x)) or min(x) and either double in size or are of equal width, and encompass the data. More generalised version of log2bins().

Usage

binData(
  x = NULL,
  counts = NULL,
  binWidth = NULL,
  binBreaks = NULL,
  startInteger = TRUE
)

Arguments

x

vector of individual values (e.g. body masses). Only x or counts can be specified.

counts

dataframe (or array) with first column being an x value (e.g. body mass), and second column being the counts of the number of individuals for that value. Only x (the vector) or counts can be specified.

binWidth

type of bins to use:

  • "2k" will result in binBreaks that:

    • with startInteger=TRUE are powers of 2, i.e. ..., 0.25, 0.5, 1, 2, 4, 8, 16,....

    • with startInteger=FALSE are bins that double in size and start with min(x); not yet implemented, since have to think about what the width of the first bin should be.

  • numeric value (call it a) will result in binBreaks are separated by a and span the data, that:

    • with startInteger=TRUE start from z = floor(min(x)) and are then ⁠z, z+a, z+2a, z+3a, ....⁠ (if z = 0 then power-law cannot be fit so then need to use startInteger=FALSE)

    • with startInteger=FALSE start from z = min(x) and are then ⁠z, z+a, z+2a, z+3a, ....⁠

  • only binWidth or binBreaks can be specified.

binBreaks

pre-defined bin breaks as a vector. Only binWidth or binBreaks can be specified.

startInteger

TRUE or FALSE, whether to start the bin breaks at an integer power of 2 (for method "2k") or an integer. See binWidth above. startInteger is ignored if binBreaks is specified.

Value

list containing:

  • indiv: dataframe with a row for each x value, with columns:

    • x: original x values

    • binMid, binMin, binMax, binWidth: midpoint, minimum, maximum, and width, respectively, of the bin within which the x value falls. If indiv has ⁠>=10^6⁠ rows then it isn't saved. If counts was specified then an equivalent x vector is created and is column x (i.e. x values are repeated). May not be the most efficient way, but is easiest to program.

  • binVals: dataframe with a row for each new bin and columns:

    • binMid, binMin, binMax, binWidth: midpoint, minimum, maximum, and width, respectively, of the bin

    • binCount: total number of individuals in that bin

    • binCountNorm: normalised bin count, binCount / binWidth

    • binSum: sum of individual values in that bin (appropriate if x represents biomass, but not length)

    • binSumNorm: binSum / binWidth

    • log10.... - log10() of some of the above quantities

Author(s)

Andrew Edwards


andrew-edwards/sizeSpectra documentation built on June 28, 2023, 7:09 p.m.