Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Class Agnostic Time Series with tsbox : : CHEAT SHEET

Basics Helper Functions Class Conversion


IDEA Transform time series of all classes and frequencies tsbox is built around a set of converters, which convert time
tsbox provides a time series toolkit which: series of the following supported classes to each other:
TRANSFORM
1. works identically with most time series classes converter function ts-boxable class

2. handles regular and irregular frequencies 650


ts_ts() ts, mts

3. converts between classes and frequencies


600
ts_trend(): Trend estimation based on loess ts_data.frame(), ts_df() data.frame
550
ts_data.table(), ts_dt() data.table
ts_trend(fdeaths)
Most functions in tsbox have the same structure: ts_tbl() df_tbl, "tibble"
500

ts_xts() xts
1974 1975 1976 1977 1978 1979 1980

function starts first argument is any
 ts_zoo() zoo


ts-boxable object
60
ts_pc(), ts_pcy(), ts_pca(), ts_diff(),
with ts_ 40
ts_tibbletime() tibbletime
20

0
ts_diffy(): (annualized) Percentage change ts_timeSeries() timeSeries
a <- ts_pc(AirPassengers) -20
rates or differences to previous period, year ts_tsibble() tsibble
ts_tslist() a list with ts objects
-40

1974 1975 1976 1977 1978 1979 1980 ts_pc(fdeaths)

returns a ts-boxable obect of the


Time Series in data frames
3

same class as input ts_scale(): normalize mean and variance


2

0
ts_scale(fdeaths)
COMBINE TIME SERIES
-1

1974 1975 1976 1977 1978 1979 1980


LONG STRUCTURE
Default structure to store multiple time series in long data
collect time series of all classes and frequencies as multiple
ts_index():Index, based on levels frames (or data tables, or tibbles)
1.2

time series 1

0.8

0.6
ts_compound(): Index, based on growth rates ts_df(ts_c(fdeaths, mdeaths))

ts_c(mdeaths, austres) 0.4


ts_index(fdeaths, base = 1976) id time value

ww w
w
combine time series to a new, single time series (first
800
1974 1975 1976 1977 1978 1979 1980

ts_seas(): seasonal adjustment using X-13


fdeaths
fdeaths
1974-01-01
1974-02-01
901
689
700
fdeaths 1974-03-01 827
series wins if overlapping) ts_seas(fdeaths)
... ... ...
600

500

ww w
ts_bind(mdeaths, austres) 1974 1975 1976 1977 1978 1979 1980

AUTO-DETECT COLUMN NAMES


tsbox auto-detects a value-, a time- and zero, one or several
SPAN AND FREQUENCY id-columns. Alternatively, the time- and the value-column
like ts_bind, but extra- and retropolate, using growth rates
1000 can be explicitly named time and value.
800
ts_lag(): Lag or lead of time series ts_default(): standardize column names in data frames
ww w
ts_chain(mdeaths, austres) 600

400 ts_lag(fdeaths, 4)
RESHAPE
1974 1976 1978 1980

ts_lag(fdeaths, 3) fdeaths

PLOT AND SUMMARIZE ts_wide(): convert default long structure to wide


ts_long(): convert wide structure to default long
590

Plot time series of all classes and frequencies


580

ts_frequency(): convert to frequency


570

560

550

ts_frequency(fdeaths, "year") USE WITH PIPE


ts_plot(mdeaths, austres) 540

tsbox plays well with tibbles and with %>%, so it can be


530
15000
ts_ggplot(mdeaths, austres) 1974 1975 1976 1977 1978 1979

easily integrated into a dplyr/pipe workflow


10000

5000

ts_summary(ts_c(mdeaths, austres)) ts_span(): filter time series for a time span. library(dplyr)
1975 1980 1985 1990

1000

pass return value as first


mdeaths austres

ts_c(fdeaths, mdeaths) %>%


ts_span(fdeaths, "1976-01-01")
800

ts_tbl() %>% argument to the next


600
ts_span(fdeaths, "-5 year")
ts_trend() %>%
400

ts_pc() function
1975 1976 1977 1978 1979 1980

CC BY SA Christoph Sax • www.cynkra.com • Learn more at tsbox.help • package version 0.1.0 • Updated: 2019-04

You might also like