surveillance (version 1.12.1)

sts-class: Class "sts" -- surveillance time series

Description

This is a lightweight S4 class to implement (multivariate) time series of counts, typically from public health surveillance. For areal time series, the class can also capture the spatial layout of the regions, where the data originate from. The constructor function sts can be used to setup an "sts" object. Conversion of simple time-series objects (of class "ts") is also possible. The slots of the "sts" class and available methods are described below.

Usage

sts(observed, start = c(2000, 1), frequency = 52,
    population = NULL, ...)

Arguments

observed
a vector (for a single time series) or matrix (one time series per column) of counts. A purely numeric data frame will also do (transformed via as.matrix). This argument sets the observed slot, which is the core el
start,frequency
basic characteristics of the time series data just like for simple "ts" objects. The (historical) default values correspond to weekly data starting in the first week of 2000.
population
a vector of length the number of columns in observed or a matrix of the same dimension as observed. Especially for multivariate time series, the population numbers (or fractions) underlying the counts in each unit
...
further named arguments with names corresponding to slot names (see the list below). For instance, the epoch slot is used to store the observation time, either as an integer sequence (default) or as the numeric representation o

encoding

latin1

Examples

Run this code
## A typical dataset with weekly counts of measles from several districts
data("measlesWeserEms")
measlesWeserEms

## reconstruct data("measlesWeserEms") from its components
counts <- observed(measlesWeserEms)
map <- measlesWeserEms@map
populationFrac <- population(measlesWeserEms)
weserems_nbOrder <- neighbourhood(measlesWeserEms)
## orders of adjacency can also be determined from the map
if (requireNamespace("spdep")) {
    stopifnot(identical(weserems_nbOrder,
                        nbOrder(poly2adjmat(map), maxlag = 10)))
}
mymeasles <- sts(counts, start = c(2001, 1), frequency = 52,
                 population = populationFrac,
                 neighbourhood = weserems_nbOrder, map = map)
stopifnot(identical(mymeasles, measlesWeserEms))

## convert ts/mts object to sts
z <- ts(matrix(rpois(300,10), 100, 3), start = c(1961, 1), frequency = 12)
z.sts <- as(z, "sts")
plot(z.sts)

## conversion of "sts" objects to the quasi-standard "xts" class
if (require("xts")) {
    z.xts <- as.xts(z.sts)
    plot(z.xts)
}

Run the code above in your browser using DataCamp Workspace