Title: | Seasonal Adjustment of Daily Time Series |
---|---|
Description: | Seasonal- and calendar adjustment of time series with daily frequency using the DSA approach developed by Ollech, Daniel (2018): Seasonal adjustment of daily time series. Bundesbank Discussion Paper 41/2018. |
Authors: | Daniel Ollech [aut, cre] |
Maintainer: | Daniel Ollech <[email protected]> |
License: | GPL-3 |
Version: | 1.0.12 |
Built: | 2024-11-13 04:00:42 UTC |
Source: | https://github.com/cran/dsa |
Three time series that have been analysed by Ollech (2021) and their seasonally and calendar adjusted variants.
daily_data
daily_data
An xts data set containing 3 time series:
Currency in circulation in Germany, in billion Euros, sum of small denominations: i.e. 5 Euro + 10 Euro + 20 Euro + 50 Euro. Series compiled by Deutsche Bundesbank
Electricity consumption in Germany in GWh. Compiled by Bundesnetzagentur (German Federal Network Agency)
Nitrogen dioxide (NO2) immissions averaged over all available measuring stations in Europe that are made available by the European Environment Agency (EEA)
#'
Seasonally and calendar adjusted version using dsa of currency_circulation
Seasonally and calendar adjusted version using dsa of elec_consumption
Seasonally and calendar adjusted version using dsa of no2
Daniel Ollech
Own calculations, Deutsche Bundesbank, Bundesnetzagentur, EEA
Ollech, Daniel (2021). Seasonal Adjustment of Daily Time Series. Journal of Time Series Econometrics (forthcoming).
Create a seasonal daily time series and its seasonal and non-seasonal components
daily_sim( n = 8, week_effect = 1, month_effect = 1, year_effect = 1, model = c(3, 1, 1), ar = c(-0.2, 0.5, 0.1), ma = -0.4, moving = T, week_cycles = 2, month_cycles = 3, year_cycles = 8 )
daily_sim( n = 8, week_effect = 1, month_effect = 1, year_effect = 1, model = c(3, 1, 1), ar = c(-0.2, 0.5, 0.1), ma = -0.4, moving = T, week_cycles = 2, month_cycles = 3, year_cycles = 8 )
n |
length of time series in years |
week_effect |
increase size of seasonal factor for day-of-the-week |
month_effect |
increase size of seasonal factor for day-of-the-month |
year_effect |
increase size of seasonal factor for day-of-the-year |
model |
ARIMA model for trend and irregular component of series |
ar |
coefficients for AR terms |
ma |
coefficients for MA terms |
moving |
should seasonal factors be moving (=T) or constant (=F) |
week_cycles |
number of cycles per week |
month_cycles |
number of cycles per month |
year_cycles |
number of cycles per year |
The output is an xts time series containing the time series, the true seasonally adjusted series,
the day-of-the-week seasonal component, the day-of-the-month seasonal component and the
day-of-the-year seasonal component.
Daniel Ollech
time_series <- daily_sim(n=4, year_effect=3) xtsplot(time_series[,1]) # Plot of the time series xtsplot(time_series[,3:5]) # Plot of the seasonal factors
time_series <- daily_sim(n=4, year_effect=3) xtsplot(time_series[,1]) # Plot of the time series xtsplot(time_series[,3:5]) # Plot of the seasonal factors
Delete name of xts
del_names(x)
del_names(x)
x |
xts time series |
This function can be helpful if one xts is created to be equal to another xts and then changed afterwards. In these cases the new xts inherits the column name of the old xts.
Daniel Ollech
timeseries <- dsa::daily_sim()$original # timeseries inherits name from original colnames(timeseries) colnames(del_names(timeseries)) y <- del_names(timeseries) colnames(merge(timeseries, y))
timeseries <- dsa::daily_sim()$original # timeseries inherits name from original colnames(timeseries) colnames(del_names(timeseries)) y <- del_names(timeseries) colnames(merge(timeseries, y))
For a series that has been logged and/or differenced, this function reverses these transformations.
Descaler(x, y = NA, Diff = 0, Sdiff = 0, Log = FALSE, Lag = NA)
Descaler(x, y = NA, Diff = 0, Sdiff = 0, Log = FALSE, Lag = NA)
x |
time series |
y |
time series used as benchmark |
Diff |
number of differences to be taken |
Sdiff |
number of seasonal differences to be taken |
Log |
Should time series be logarithmised |
Lag |
Lag for Sdiff can be specified |
The time series used as a benchmark (y) is necessary, if regular or seasonal differences have to be inversed, because the first values of this series are used to reconstruct the original values or benchmark the new series.
Daniel Ollech
a = ts(rnorm(100, 100, 10), start=c(2015,1), frequency=12) b = Scaler(a, Diff=1, Log=TRUE) Descaler(b,a, Diff=1, Log=TRUE)
a = ts(rnorm(100, 100, 10), start=c(2015,1), frequency=12) b = Scaler(a, Diff=1, Log=TRUE) Descaler(b,a, Diff=1, Log=TRUE)
Seasonally adjust daily time series using the dsa approach
dsa( series, span.start = NULL, model = NULL, Log = FALSE, automodel = "reduced", ic = "bic", include.constant = FALSE, fourier_number = 24, max_fourier = 30, s.window1 = 53, s.window2 = 53, s.window3 = 13, t.window1 = NULL, t.window2 = NULL, t.window3 = NULL, cval = 7, robust1 = TRUE, robust2 = TRUE, robust3 = TRUE, regressor = NULL, forecast_regressor = NULL, reg_create = NULL, reg_dummy = NULL, outlier = TRUE, outlier_types = c("AO", "LS", "TC"), delta = 0.7, model_span = NULL, feb29 = "sfac", trend_month = 3, outer3 = NULL, inner3 = NULL, h = 365, reiterate3 = NULL, scaler = 1e+07, mean_correction = TRUE, progress_bar = TRUE )
dsa( series, span.start = NULL, model = NULL, Log = FALSE, automodel = "reduced", ic = "bic", include.constant = FALSE, fourier_number = 24, max_fourier = 30, s.window1 = 53, s.window2 = 53, s.window3 = 13, t.window1 = NULL, t.window2 = NULL, t.window3 = NULL, cval = 7, robust1 = TRUE, robust2 = TRUE, robust3 = TRUE, regressor = NULL, forecast_regressor = NULL, reg_create = NULL, reg_dummy = NULL, outlier = TRUE, outlier_types = c("AO", "LS", "TC"), delta = 0.7, model_span = NULL, feb29 = "sfac", trend_month = 3, outer3 = NULL, inner3 = NULL, h = 365, reiterate3 = NULL, scaler = 1e+07, mean_correction = TRUE, progress_bar = TRUE )
series |
Input time series in xts format |
span.start |
Define when seasonal adjustment should begin |
model |
ARIMA order of non-seasonal part |
Log |
Boolean. Should multiplicate or additive model be used |
automodel |
Set of models to be considered for automatic model detection. Either "full" or "reduced" set of fourier regressors included |
ic |
Information criterion that is used for automodelling. One of "bic", "aic" or "aicc" |
include.constant |
Should drift be allowed for model that includes differencing |
fourier_number |
Number of trigometric regressors to model annual and monthly seasonality |
max_fourier |
Maximum number of trigonometric regressors allowed if the number is selected automatically, i.e. fourier_number=NULL |
s.window1 |
STL parameter s.window for the day of the week effect |
s.window2 |
STL parameter s.window for the day of the month effect |
s.window3 |
STL parameter s.window for the day of the year effect |
t.window1 |
STL parameter t.window for the day of the week effect |
t.window2 |
STL parameter t.window for the day of the month effect |
t.window3 |
STL parameter t.window for the day of the year effect |
cval |
Critical value for outlier adjustment |
robust1 |
Boolean. Should robust STL be used for the day of the week effect |
robust2 |
Boolean. Should robust STL be used for the day of the month effect |
robust3 |
Boolean. Should robust STL be used for the day of the year effect |
regressor |
Pre-specified regressors |
forecast_regressor |
Pre-specified regressors to be used for forecasting |
reg_create |
Names of Holidays for which regressors will be created |
reg_dummy |
If specified dummy variables of specified length are created and used as regressors |
outlier |
Should an outlier adjustment be conducted? |
outlier_types |
The following are possible: "LS", "TC", "AO", "IO" |
delta |
The decay rate for TC outliers |
model_span |
Last x years used for regARIMA modelling |
feb29 |
How should February 29th be derived: interpolation of adjusted series ("sa") or combined factor ("sfac") |
trend_month |
Length of support period for trend estimation |
outer3 |
Number of iterations of outer loop in STL for day of the year effect |
inner3 |
Number of iterations of inner loop in STL for day of the year effect |
h |
Forecast horizon in number of days |
reiterate3 |
Number of total iterations of STL for the day of the year effect |
scaler |
for additive model, if max(abs(series)) > 1e5, scale series |
mean_correction |
Boolean. Should seasonal factors be standardised so that their mean (over all full cycles) is 0 for additive and 1 for multiplicative models |
progress_bar |
Boolean. Should a progress bar be displayed |
This function can be used to seasonally and calendar adjust daily time series and decomposing the series into a seasonally adjusted series, a day-of-the-week, a moving holiday, a day-of-the-month and a day-of-the-year component.
If mean_correction=TRUE (default), the seasonal and calendar factors are corrected, so that over all full years, the mean of the components is 0 in additive models. They will be close to 1 if a multiplicative decomposition (i.e. Log=TRUE) is used. Deviations from 1 may result, because the mean correction is applied to the components before inverting taking logs.
For long series, the ARIMA modelling and the outlier adjustment may take a long time. It may therefore be a good idea, to specify the ARIMA model used, e.g. model=c(3,1,0). If the series does not contain influential outliers, the outlier adjustment could be skipped by setting outlier=FALSE.
See vignette for further examples.
dsa
returns a daily
object which contains the output of the seasonal adjustment of a daily time series.
output Contains the calendar and seasonally adjusted series, original series, implicit calendar and seasonal component, and Loess based trend as an xts
object
fourier_terms The number of sine and cosine terms used to model the seasonal pattern in the RegARIMA model
reg RegARIMA results
info Basic information on transformation (Log/Level), differencing and forecast horizon
stl A list of length 3, containing the STL results of the day-of-week, day-of-the-month and day-of-the-year adjustment, respectively
outlier Result of the outlier adjustment
sa_result The original series and the intermediate adjustment results after the day-of-week adjustment (s1_adjusted), calendar adjustment (s1k1_adjusted), day-of-the-month adjustment (s1k1s2_adjusted), and the final adjusted series after the day-of-the-year adjustment (seas_adj) as an xts
object
sa_result2 The original series only adjusted for single components as an xts
object. Namely the original series itself (original), the original only adjusted for the day-of-the week (s1_adjusted), calendar (k1_adjusted), day-of-the-month (s2_adjusted), and day-of-the-year (s3_adjusted)
sfac_result The seasonal and calendar components as an xts
object. Namely, the day-of-the-week (s1_fac), calendar (cal_fac), day-of-the-month (s2_fac), and day-of-the-year component (s3_fac)
Daniel Ollech
Ollech, Daniel (2018). Seasonal adjustment of daily time series. Bundesbank Discussion Paper 41/2018.
Ollech, Daniel (2021). Seasonal Adjustment of Daily Time Series. Journal of Time Series Econometrics (forthcoming).
x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13)
x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13)
The dsa results for the three time series that have been analysed by Ollech (2021). Details on the specification can be found in the vignette.
dsa_examples
dsa_examples
A list containing the following three objects
Results from a call to dsa() for the currency in circulation in Germany, in billion Euros, sum of small denominations: i.e. 5 Euro + 10 Euro + 20 Euro + 50 Euro. Series compiled by Deutsche Bundesbank.
Results from a call to dsa() for the electricity consumption in Germany in GWh. Compiled by Bundesnetzagentur (German Federal Network Agency)
Results from a call to dsa() for the nitrogen dioxide (NO2) immissions averaged over all available measuring stations in Europe that are made available by the European Environment Agency (EEA)
Daniel Ollech
Own calculations, Deutsche Bundesbank, Bundesnetzagentur, EEA
Ollech, Daniel (2021). Seasonal Adjustment of Daily Time Series. Journal of Time Series Econometrics (forthcoming).
Estimate the number of periods per year of an xts time series
freq_xts(series)
freq_xts(series)
series |
time series |
Daniel Ollech
x <- xts::xts(rnorm(100), seq.Date(from=as.Date("2010-01-01"), by="months", length.out=100)) frequency(x)
x <- xts::xts(rnorm(100), seq.Date(from=as.Date("2010-01-01"), by="months", length.out=100)) frequency(x)
Get the original time series from a seasonal adjustment object created by the dsa function. Can deviate from the input data as missings are filled up, usually using zoo::na.locf().
get_original(daily.object, forecast = FALSE)
get_original(daily.object, forecast = FALSE)
daily.object |
Output from dsa |
forecast |
Include forecast of component |
Daniel Ollech
get_sa, get_trend
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_original(res)
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_original(res)
Get the calendar- and seasonally adjusted series from a seasonal adjustment object created by the dsa function
get_sa(daily.object, forecast = FALSE)
get_sa(daily.object, forecast = FALSE)
daily.object |
Output from dsa |
forecast |
Include forecast of component |
Daniel Ollech
get_trend, get_original
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_sa(res)
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_sa(res)
Calculate the trend-cycle based on a seasonally adjusted series obtained from a seasonal adjustment object created by the dsa function
get_trend(daily.object, trend_length = 93, forecast = FALSE)
get_trend(daily.object, trend_length = 93, forecast = FALSE)
daily.object |
Output from dsa |
trend_length |
Number of neighbouring points to use, in days |
forecast |
Include forecast of component |
If not odd the parameter trend_length is set to the next highest odd number.
Daniel Ollech
get_sa, get_original
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_trend(res)
set.seed(123) x = daily_sim(n=4)$original # series with length 4 years res <- dsa(x, cval=7, model=c(3,1,0),fourier_number = 13) get_trend(res)
Daily time series in xts format containing many regressors for holidays potentially used in the adjustment of daily time series
holidays
holidays
An xts data set containing 131 regressors for the time span 1950 to 2075:
AllSaints, Nov 1
Ascension
Captures the first day after Ascension
Captures the last day before Ascension
Assumption of Mary, Aug 15
Captures if Assumption of Mary, Aug 15, is a certain weekday (Monday to Sunday)
Regressor made up of 0s, can be used to create other regressors
Boxing Day, Dec 26
Carnival Monday
Christmas Day, Dec 25
Christmas Eve, Dec 24
Corpus Christi
Captures the first day after Corpus Christi
Captures the last day before Corpus Christi
Captures if Dec 24 is a certain weekday (Monday to Sunday)
Captures if Dec 25 is a certain weekday (Monday to Sunday)
Captures if Dec 26 is a certain weekday (Monday to Sunday)
Captures if Dec 31 is a certain weekday (Monday to Sunday)
Daylight Saving Time, Spring=-1, Autumn=1
Daylight Saving Time, Autumn=1
Daylight Saving Time, Spring=1
Easter Monday
Captures the first day after Easter Monday
Captures all days from Holy Thursday to Easter Monday
Easter Sunday
Epiphany, Jan 6
German Unity, Oct 3
Good Friday
Holy Thursday
Holy Saturday
Captures if Jan 1 is a certain weekday (Monday to Sunday)
Captures if Jan 1 is a certain weekday (Monday to Sunday)
Labour Day, May 1
Captures the bridge days created by May 1, i.e. if surrounding days are either a Monday or Friday
Mardi Gras
Captures if Labour Day, May 1, is a certain weekday (Monday to Sunday)
New Years Day, Jan 1
New Years Eve, Dec 31
Captures if Nov 1 is a certain weekday (Monday to Sunday)
Captures the bridge days created by Nov 1, i.e. if surrounding days are either a Monday or Friday
Captures if German Unity, Oct 3, is a certain weekday (Monday to Sunday)
Captures the bridge days created by Nov 1, i.e. if surrounding days are either a Monday or Friday
Captures if Reformation Day, Oct 31, is a certain weekday (Monday to Sunday)
Captures the bridge days created by Reformation Day, i.e. if surrounding days are either a Monday or Friday
Pentecost Monday
Captures the first day after Pentecost Monday
Captures the last day before Pentecost Monday
Alias for Pentecost Monday
Period spanning three days from Pentecost Sunday to Tuesday after Pentecost Monday
Captures Saturdays in the period from Dec 31 to Jan 6
Captures Sundays in the period from Dec 31 to Jan 6
Captures Saturdays in the period from Dec 27 to Jan 2
Captures Sundays in the period from Dec 27 to Jan 2
Captures Saturdays in the period from Dec 27 to Jan 5
Captures Sundays in the period from Dec 27 to Jan 5
Captures Saturdays in the three days leading up to Christmas
Captures Sundays in the three days leading up to Christmas
Reformation Day, Oct 31
Reformation Day, Oct 31 2017 (National holiday that year)
Captures weekdays (Monday to Sunday) in the Christmas period from Dec 21 to Jan 5
Daniel Ollech
Own calculations
Creating holiday regressor that increases linearly up to holiday and decreases afterwards
make_cal(holidays = NULL, h = 365, original = NA, original2 = NA)
make_cal(holidays = NULL, h = 365, original = NA, original2 = NA)
holidays |
Holidays for which regressor will be created |
h |
Forecast horizon |
original |
xts time series which characteristics will be used |
original2 |
ts time series which characteristics will be used |
This function is used internally in dsa()
Daniel Ollech
a <- daily_sim(n=8)$original ## Not run: make_cal(holidays="Easter", original=a, original2=xts2ts(a, freq=365))
a <- daily_sim(n=8)$original ## Not run: make_cal(holidays="Easter", original=a, original2=xts2ts(a, freq=365))
Creating set of dummy variables for specified Holidays
make_dummy( holidays = NULL, from = -5, to = 5, h = 365, original = NA, original2 = NA )
make_dummy( holidays = NULL, from = -5, to = 5, h = 365, original = NA, original2 = NA )
holidays |
holidays for which dummy variables will be created |
from |
start of holiday regressor. Relative to specified holiday |
to |
end of holiday regressor. Relative to specified holiday |
h |
forecast horizon |
original |
xts time series which characteristics will be used |
original2 |
ts time series which characteristics will be used |
This function is used internally in dsa()
Daniel Ollech
This function uses the Holiday dates of the timeDate::timeDate package to create dummies on a specified holiday.
make_holiday(dates = timeDate::Easter(2000:2030), shift = 0)
make_holiday(dates = timeDate::Easter(2000:2030), shift = 0)
dates |
Holiday and period for which dummy shall be created |
shift |
shifting point in time for dummy |
With shift the user can specify for how many days before (negative value) or after (positive value) the holiday a dummy will be created.
Daniel Ollech
make_holiday(dates=timeDate::Easter(2000:2030), shift=-1)
make_holiday(dates=timeDate::Easter(2000:2030), shift=-1)
Change multiple xts to a multivariate ts
multi_xts2ts(x, short = FALSE)
multi_xts2ts(x, short = FALSE)
x |
xts time series |
short |
Is series too short for xts2ts to work? |
If the ts are used for forecasting
Daniel Ollech
x <- dsa::daily_sim()$original y <- dsa::daily_sim()$original multi_xts2ts(merge(x,y))
x <- dsa::daily_sim()$original y <- dsa::daily_sim()$original multi_xts2ts(merge(x,y))
This function creates HTML output in a specified folder for objects of class daily
output( daily_object, path = getwd(), short = FALSE, SI = TRUE, SI365.seed = 3, spec = TRUE, outlier = TRUE, Factor = "auto", every_day = TRUE, seasonals = FALSE, spectrum_linesize = 0.5, seasonality_tests = TRUE, progress_bar = TRUE )
output( daily_object, path = getwd(), short = FALSE, SI = TRUE, SI365.seed = 3, spec = TRUE, outlier = TRUE, Factor = "auto", every_day = TRUE, seasonals = FALSE, spectrum_linesize = 0.5, seasonality_tests = TRUE, progress_bar = TRUE )
daily_object |
output of dsa() function |
path |
Path that HTML file is written to |
short |
Boolean. If true only short version of output is produced |
SI |
Including graphs of SI-ratios |
SI365.seed |
This seed influences which days of the year are shown as SI-ratios |
spec |
Boolean. Inclusion of spectral plots |
outlier |
Boolean. Inclusion of outlier plots |
Factor |
Scaling factor for series with large values |
every_day |
Boolean. Inclusion of table that summarizes daily results |
seasonals |
Boolean. Plots of seasonal factors as interactive instead of static graph |
spectrum_linesize |
Width of lines in spectrum |
seasonality_tests |
Boolean. Inclusion of seasonality tests |
progress_bar |
Should a progress bar be displayed? |
This function can be used to create plots and tables necessary for the analysis of seasonally and calendar adjusted daily time series. Uses the output of dsa() as an input.
Daniel Ollech
res <- dsa(daily_sim(4)$original, cval=7, model=c(3,1,0),fourier_number = 13) ## Not run: output(res)
res <- dsa(daily_sim(4)$original, cval=7, model=c(3,1,0),fourier_number = 13) ## Not run: output(res)
Plot the periodogram of a daily time series
plot_spectrum( x, xlog = FALSE, size = 1, color = "black", vline_color = "#6F87B2" )
plot_spectrum( x, xlog = FALSE, size = 1, color = "black", vline_color = "#6F87B2" )
x |
xts or ts, daily timeseries |
xlog |
should x-axis be log transformed |
size |
linesize |
color |
color of line |
vline_color |
color of vertical lines |
Plot uses ggplot2 and can be changed accordingly. The spectrum is build around the spec.pgram() function
Daniel Ollech
x <- daily_sim(3)$original plot_spectrum(x)
x <- daily_sim(3)$original plot_spectrum(x)
Plotting output for objects of class "daily"
## S3 method for class 'daily' plot(x, dy = TRUE, trend = FALSE, ...)
## S3 method for class 'daily' plot(x, dy = TRUE, trend = FALSE, ...)
x |
Result of dsa() that will be plotted |
dy |
should dygraphs be used for plotting |
trend |
Boolean. Inclusion of a trend estimate. |
... |
Other plot parameters (only if dy=FALSE) |
The original series is plotted in black, the seasonally adjusted series is colored in red, and if trend=T, a blue trend line is added.
Daniel Ollech
x <- daily_sim(3)$original ## Not run: res<- dsa(x, fourier_number = 24, outlier.types="AO", reg.create=NULL, model=c(3,1,0)) ## Not run: plot(res, dy=FALSE)
x <- daily_sim(3)$original ## Not run: res<- dsa(x, fourier_number = 24, outlier.types="AO", reg.create=NULL, model=c(3,1,0)) ## Not run: plot(res, dy=FALSE)
Print output for objects of class "daily"
## S3 method for class 'daily' print(x, ...)
## S3 method for class 'daily' print(x, ...)
x |
Result of dsa() that will be printed |
... |
further arguments handed to print() |
Daniel Ollech
x <- daily_sim(3)$original ## Not run: res<- dsa(x, fourier_number = 24, outlier.types="AO", reg.create=NULL, model=c(3,1,0)) ## Not run: print(res)
x <- daily_sim(3)$original ## Not run: res<- dsa(x, fourier_number = 24, outlier.types="AO", reg.create=NULL, model=c(3,1,0)) ## Not run: print(res)
Logarithmise and / or difference a time series
Scaler(x, Diff = 0, Sdiff = 0, Log = FALSE)
Scaler(x, Diff = 0, Sdiff = 0, Log = FALSE)
x |
time series |
Diff |
number of differences to be taken |
Sdiff |
number of seasonal differences to be taken |
Log |
Should time series be logarithmised |
Function is used in dsa to let the user decide whether logs and differences should be taken.
Daniel Ollech
a = ts(rnorm(100, 100, 10), start=c(2015,1), frequency=12) Scaler(a, Diff=1, Log=TRUE)
a = ts(rnorm(100, 100, 10), start=c(2015,1), frequency=12) Scaler(a, Diff=1, Log=TRUE)
This function computes the weekly aggregates or differences (by default Friday to Friday) for any daily time series in the xts format.
to_weekly(x, incl_forecast = T, forecast_length = 365, diff = T, dayofweek = 5)
to_weekly(x, incl_forecast = T, forecast_length = 365, diff = T, dayofweek = 5)
x |
input series |
incl_forecast |
whether the series contains a forecast that shall be omitted |
forecast_length |
length of forecast |
diff |
should series be differenced |
dayofweek |
which day of the week (friday=5) |
Daniel Ollech
to_weekly(xts::xts(rnorm(365, 10,1), seq.Date(as.Date("2010-01-01"), length.out=365, by="days")))
to_weekly(xts::xts(rnorm(365, 10,1), seq.Date(as.Date("2010-01-01"), length.out=365, by="days")))
Sequentially add a set of time series
ts_sum(...)
ts_sum(...)
... |
list of ts time series that are added together |
This function is used internally in dsa()
Daniel Ollech
ts_sum(list(ts(rnorm(100,10,1)), ts(rnorm(100,10,1)), ts(rnorm(100,10,1))))
ts_sum(list(ts(rnorm(100,10,1)), ts(rnorm(100,10,1)), ts(rnorm(100,10,1))))
Change the format of a time series from ts to xts. Has been optimised for the use in dsa(), i.e. for daily time series.
ts2xts(x_ts)
ts2xts(x_ts)
x_ts |
ts series to be changed to xts |
This function is used internally in dsa(). Does not create values for the 29th of February.
Daniel Ollech
ts2xts(stats::ts(rnorm(1000, 10,1), start=c(2001,1), freq=365))
ts2xts(stats::ts(rnorm(1000, 10,1), start=c(2001,1), freq=365))
Change the format of a time series from xts to ts. Has been optimised for the use in dsa(), i.e. for daily time series.
xts2ts(series, freq = NULL)
xts2ts(series, freq = NULL)
series |
xts series to be changed to ts |
freq |
frequency of ts series |
This function is used internally in dsa(). Does not create values for the 29th of February.
Daniel Ollech
xts2ts(xts::xts(rnorm(1095, 10,1), seq.Date(as.Date("2010-01-01"), length.out=1095, by="days")))
xts2ts(xts::xts(rnorm(1095, 10,1), seq.Date(as.Date("2010-01-01"), length.out=1095, by="days")))
Creates a plot using an xts series
xtsplot( xts, transform = "none", type = "line", years = NA, scale = 1, names = NA, color = NA, main = "", legend = NA, textsize = 1, textsize_x = NA, textsize_y = NA, textsize_legend = NA, textsize_title = NA, linesize = 1.1, WeekOfYear = F, date_breaks = NA, date_labels = NA, submain = NULL )
xtsplot( xts, transform = "none", type = "line", years = NA, scale = 1, names = NA, color = NA, main = "", legend = NA, textsize = 1, textsize_x = NA, textsize_y = NA, textsize_legend = NA, textsize_title = NA, linesize = 1.1, WeekOfYear = F, date_breaks = NA, date_labels = NA, submain = NULL )
xts |
one or many series |
transform |
one of "none","diff", "change" (can be abbreviated) |
type |
either "bar", "bar2" or "line" |
years |
number of years to include |
scale |
by what factor should data be scaled. |
names |
change names of series |
color |
color of the series |
main |
title of the plot |
legend |
alignment of legend. "horizontal" or "vertical" |
textsize |
scale the size of all the text |
textsize_x |
scale size of x-axis labels |
textsize_y |
scale size of y-axis labels |
textsize_legend |
scale size of legend text |
textsize_title |
scale size of title |
linesize |
scale the size of the lines |
WeekOfYear |
should x axis be week of year |
date_breaks |
distance between labels (see examples) |
date_labels |
format of the date label for x-axis |
submain |
subtitle of the plot |
This function uses the ggplot2 package. The difference between type="bar" and type="bar2" is that the former produces barcharts with bars of the second series in front of the bars of the first series (and accordingly for more than two series), while "bar2" creates side-by-side barcharts. If a scale is supplied, the data will be divided by this number.
Daniel Ollech
x <- xts::xts(rnorm(100), seq.Date(as.Date("2010-01-01"), length.out=100, by="months")) y <- xts::xts(runif(100), seq.Date(as.Date("2010-01-01"), length.out=100, by="months")) xtsplot(y, transform="diff", type="bar") xtsplot(y, transform="diff", type="bar", date_breaks="24 months") xtsplot(merge(x,y), names=c("Gaussian", "Uniform"), main="Simulated series")
x <- xts::xts(rnorm(100), seq.Date(as.Date("2010-01-01"), length.out=100, by="months")) y <- xts::xts(runif(100), seq.Date(as.Date("2010-01-01"), length.out=100, by="months")) xtsplot(y, transform="diff", type="bar") xtsplot(y, transform="diff", type="bar", date_breaks="24 months") xtsplot(merge(x,y), names=c("Gaussian", "Uniform"), main="Simulated series")