aggregate.time.series: Aggregate a fine time series to a coarse summary In bsts: Bayesian Structural Time Series

 aggregate.time.series R Documentation

Aggregate a fine time series to a coarse summary

Description

Aggregate measurements from a fine scaled time series into a coarse time series. This is similar to functions from the `xts` package, but it can handle aggregation from weeks to months.

Usage

``````   AggregateTimeSeries(fine.series,
contains.end,
membership.fraction,
trim.left = any(membership.fraction < 1),
trim.right = NULL,
byrow = TRUE)
``````

Arguments

 `fine.series` A numeric vector or matrix giving the fine scale time series to be aggregated. `contains.end` A logical vector corresponding to `fine.series` indicating whether each fine time interval contains the end of a coarse time interval. `membership.fraction` A numeric vector corresponding to `fine.series`, giving the fraction of each time interval's observation attributable to the coarse interval containing the fine interval's first day. This will usually be a vector of 1's, unless `fine.series` is weekly. `trim.left` Logical indicating whether the first observation in the coarse aggregate should be removed. `trim.right` Logical indicating whether the final observation in the coarse aggregate should be removed. `byrow` Logical. If `fine.series` is a matrix, this argument indicates whether rows (`TRUE`) or columns (`FALSE`) correspond to time points.

Value

A matrix (if `fine.series` is a matrix) or vector (otherwise) containing the aggregated values of `fine.series`.

Author(s)

Steven L. Scott steve.the.bayesian@gmail.com

Examples

``````  week.ending <- as.Date(c("2011-11-05",
"2011-11-12",
"2011-11-19",
"2011-11-26",
"2011-12-03",
"2011-12-10",
"2011-12-17",
"2011-12-24",
"2011-12-31"))
membership.fraction <- GetFractionOfDaysInInitialMonth(week.ending)
which.month <- MatchWeekToMonth(week.ending, as.Date("2011-11-01"))
contains.end <- WeekEndsMonth(week.ending)

weekly.values <- rnorm(length(week.ending))
monthly.values <- AggregateTimeSeries(weekly.values, contains.end, membership.fraction)

``````

bsts documentation built on May 29, 2024, 2:14 a.m.