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.
Usage
calendarization(
calendarobs,
freq,
start = NULL,
end = NULL,
dailyweights = NULL,
stde = FALSE
)Arguments
- calendarobs
A named list with the observed data. The list must be composed of three elements: start, end and value, the first two corresponding to the starting and ending date of the observation. See example.
- freq
Annual frequency. If 0, only the daily series are computed.
- start
Starting day of the calendarization. Could be before the starting date of the first observation (retropolation).
- end
Ending day of the calendarization. Could be after the ending date of the last observation (extrapolation).
- dailyweights
Daily indicator values (or weights). Should have the same length as the requested series. If available, it typically reflects the daily level of activity that may be varying in function for instance of seasonality, trading day or other calendar effects such as public holidays.
- stde
Boolean. If TRUE, the function also returns the standard errors associated to the results. Default is FALSE.
Value
a list with the disaggregated daily values, the final aggregated results, and their associated errors if requested.
Examples
# Example 1 (from Quenneville et al (2012): "Calendarization with interpolating splines and state space models", Appl. Statistics (2013) 62, part 3, pp 371-399)
## 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