View source: R/calendarization.R
| calendarization | R Documentation |
Time series data do not always coincide with calendar periods (e.g., fiscal years starting in March-April or retail data collected in non-monthly intervals). Calendarization is the process of transforming the values of a flow time series observed over varying time intervals into values that cover given calendar intervals such as month, quarter or year. The process involves two steps. At first, a state-space representation of the Denton proportional first difference (PFD) method is considered to perform a temporal disaggregation of the observed data into daily values. After that, the resulting daily values are aggregated into the desired calendar reference periods.
calendarization(
calendarobs,
freq,
start = NULL,
end = NULL,
dailyweights = NULL,
stde = FALSE
)
calendarobs |
A named list containing the observed data. The list must
consist of three elements: |
freq |
An integer specifying the annual frequency. If set to |
start |
The starting day of the calendarization. This date may precede the first observed data (retropolation). |
end |
The ending day of the calendarization. This date may exceed the last observed data (extrapolation). |
dailyweights |
A numeric vector of daily indicator values (or weights). The vector must have the same length as the requested daily series. When available, these weights typically reflects daily levels of activity, which may vary due to seasonality, trading day effects, or other calendar effects such as public holidays. |
stde |
Boolean. If |
A list containing the disaggregated daily values, the final aggregated series, and their associated standard errors if requested.
For more information on the method, its arguments, and the other methods available in the package, see the package vignette:
In R:
browseVignettes(package = "rjd3bench")
Online: https://rjdverse.github.io/rjd3bench/articles/rjd3bench.html
Quenneville, B., Picard F., Fortier S. (2012). Calendarization with interpolating splines and state space models. Statistics Canada, Appl. Statistics (2013) 62, part 3, pp 371-399.
# Example 1 (from Quenneville et al (2012))
## Observed data
obs_1 <- list(
list(start = "2009-02-18", end = "2009-03-17", value = 9000),
list(start = "2009-03-18", end = "2009-04-14", value = 5000),
list(start = "2009-04-15", end = "2009-05-12", value = 9500),
list(start = "2009-05-13", end = "2009-06-09", value = 7000))
## a) calendarization in absence of daily indicator values (or weights)
cal_1a <- calendarization(obs_1, 12, end = "2009-06-30", dailyweights = NULL, stde = TRUE)
ym_1a <- cal_1a$rslt
eym_1a <- cal_1a$erslt
yd_1a <- cal_1a$days
eyd_1a <- cal_1a$edays
## b) calendarization in presence of daily indicator values (or weights)
x <- rep(c(1.0, 1.2, 1.8 , 1.6, 0.0, 0.6, 0.8), 19)
cal_1b <- calendarization(obs_1, 12, end = "2009-06-30", dailyweights = x, stde = TRUE)
ym_1b <- cal_1b$rslt
eym_1b <- cal_1b$erslt
yd_1b <- cal_1b$days
eyd_1b <- cal_1b$edays
# Example 2 (incl. negative value)
obs_2 <- list(
list(start = "1980-01-01", end = "1989-12-31", value = 100),
list(start = "1990-01-01", end = "1999-12-31", value = -10),
list(start = "2000-01-01", end = "2002-12-31", value = 50))
cal_2 <- calendarization(obs_2, 4, end = "2003-12-31")
yq_2 <- cal_2$rslt
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.