Annual mean density from interval (monthly / seasonal) surfaces
Source:R/density.R
density_annual.RdThe annual surface a static score consumes is the mean over ALL intervals of the year, with
an interval in which a cell carries no value counted as ZERO — not the mean over the
intervals in which the cell happens to be present. The v8 gm/nc ingests averaged only the
present intervals, which biases every cell upward and most for the sparsest species (a cell
modelled in 2 of 12 months at density 1 is 0.17 animals km^-2 year-round, not 1).
Arguments
- x
a data frame with columns
cell_id, an interval column and a density column; one row per (cell, interval) where the cell has a value.- n_intervals
integer; the number of intervals in the year (12 months, 4 seasons).
- value
name of the density column (default
"dens").- interval
name of the column holding the interval label (
"01".."12", a season); required withweights.- weights
named numeric vector, one weight per interval (e.g.
month_day_weights()): the annual is the WEIGHTED mean over alln_intervals, an interval without a surface contributing zero over its weight.NULL(default) = the plain mean (sum / n_intervals), every interval weighing the same.
Details
Whether an UNMODELLED interval (a season NCCOS did not fit for a species, a -9999 month) is
truly zero is the caller's decision: pass only the intervals that count in n_intervals.
Examples
x <- data.frame(cell_id = c(1, 1, 2), interval = c("01", "02", "01"), dens = c(1, 1, 3))
density_annual(x, n_intervals = 12) # cell 1: 2/12; cell 2: 3/12
#> cell_id dens
#> 1 1 0.1666667
#> 2 2 0.2500000