aggregate.time.series {bsts} | 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
|
membership.fraction |
A numeric vector corresponding to
|
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 |
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)