Learn R Programming

surveillance (version 1.20.3)

aggregate-methods: Aggregate an "sts" Object Over Time or Across Units

Description

Aggregate the matrix slots of an "sts" object. Either the time series is aggregated so a new sampling frequency of nfreq observations per year is obtained (i.e., as in aggregate.ts), or the aggregation is over all columns (units).

Usage

# S4 method for sts
aggregate(x, by = "time", nfreq = "all", ...)

Value

an object of class "sts".

Arguments

x

an object of class "sts".

by

a string being either "time" or "unit".

nfreq

new sampling frequency for by="time". If nfreq="all" then all time points are summed.

...

unused (argument of the generic).

Warning

Aggregation over units fills the upperbound slot with NAs and the map slot is left as-is, but the object cannot be plotted by unit any longer.

The populationFrac slot is aggregated just like observed. Population fractions are recomputed if and only if x is no multinomialTS and already contains population fractions. This might not be intended, especially for aggregation over time.

Examples

Run this code
data("ha.sts")
dim(ha.sts)
dim(aggregate(ha.sts, by = "unit"))
dim(aggregate(ha.sts, nfreq = 13))
# \dontshow{
## population(ha.sts) are trivial fractions, aggregate() should keep them
stopifnot(population(aggregate(ha.sts)) == 1/ncol(ha.sts))
## failed in surveillance <= 1.16.2
# }

Run the code above in your browser using DataLab