object representing time series data - Maple Help

Home : Support : Online Help : Statistics : Time Series Analysis Package : TimeSeriesAnalysis/TimeSeries

TimeSeriesAnalysis[TimeSeries] - object representing time series data

 Calling Sequence TimeSeries(data, opts) TS[rows] TS[rows, columns] TS[columnseq] TS[rows, algexps] TS[boolexps] TS[boolexps, columns]

Parameters

 data - list, Vector, or Matrix of numbers, or another TimeSeries object opts - (optional) equations of the form optionname = value, described later TS - TimeSeries object, constructed using, for example, the first calling sequence rows - range of the form start .. end, where start and end are either integers or strings columns - integer, string, or range of integers or strings, or list of these columnseq - non-empty sequence of integers algexps - algebraic expression or list of algebraic expressions boolexps - boolean expression or list of boolean expressions

Description

 • The TimeSeries command creates a time series object, for use with the TimeSeriesAnalysis package. A TimeSeries object contains one or more sets of data, measured at one set of time points.
 • The data argument is required. It contains the actual numbers making up the data sets. If the object is to represent a single set of data, then data can be given as a list or Vector of numbers. If the object is to represent $k$ sets of data, it can be given as a list of $k$ equally long lists of numbers, or a Matrix of numbers with $k$ columns. Alternatively, you can use a pre-existing TimeSeries data set object to give the data.
 • In the computations of the TimeSeriesAnalysis package, time intervals are all treated as equal - that is, if you specify time points that are irregularly spaced, this information is used only for purposes such as supplying appropriate tickmarks on the axes for graphs.
 • The TimeSeries methods help page describes the commands that can be used to interrogate TimeSeries objects.

Indexing

 • If you construct a time series object TS, you can index it as TS[rows] or TS[rows, columns] to get a new time series object representing a subset of the data.
 • Selecting rows is done using a range of the form start .. end, where start indicates the first row to be selected and end indicates the last.
 – If start or end is a positive integer, it indicates the number of the row, counting the earliest row of data as $1$ and counting up for later rows ($2,3,\mathrm{...}$).
 – If start or end is a negative integer, it indicates the number of the row, counting the last row of data as $-1$ and counting down for earlier rows ($-2,-3,\mathrm{...}$).
 – If start or end is missing, for example in the ranges ${\mathrm{TS}}_{\left(\right)..5},{\mathrm{TS}}_{-5..\left(\right)},{\mathrm{TS}}_{\left(\right)..\left(\right)}$, then they are taken as $1$ and $-1$, respectively. That is, if start is missing, the range starts at the beginning, and if end is missing, the range ends at the end.
 – If start or end is a string, Maple interprets it as a date in the format selected for this time series. The range then includes all data points later than or equal to the given time (for start), or before or equal to the given time (for end).
 • Selecting columns can be done with a string, an integer, a range of strings or integers, or a list of strings, integers, or ranges.
 – A positive integer selects the given column number, counting from left to right.
 – A negative integer selects the given column number, counting $-1$ as the rightmost column and counting down as you move left.
 – A string selects the column with the given header ("name"). The string has to be an exact match. If there are multiple columns with the same header (which is inadvisable), the first column with this header is selected.
 – A range selects all columns from the left hand side to the right hand side of the range, inclusive.
 – A list selects all columns included in the list.
 • To select some columns but not restrict the rows, you can use ${\mathrm{TS}}_{\left(\right)..\left(\right),\mathrm{columns}}$. Specifying $\left(\right)..\left(\right)$ for the rows selects all rows.
 • Columns can also be selected by indexing with a sequence of integers, as in TS[columnseq].  Positive and negative integers work as described above. The resulting TimeSeries will have columns in the same order as the sequence.
 • A TimeSeries with new data can be created with TS[rows, algexps], where algexps is an algebraic expression or a list of algebraic expressions, where the indeterminates are the headers of the columns, as names.
 – The rows of the new TimeSeries are computed from algexps by substituting the column names with the value from that column from the same row. For example, if one column of a TimeSeries object TS has header "revenue" and another column has header "costs", you can create a new TimeSeries with a column that is the difference between these values with TS[.., 'revenue' - 'costs'].
 – Since the headers are used as names, they need to be enclosed in backticks () if they include characters that are not normally part of Maple names, such as spaces. In the previous example, if the columns headers are "gross revenue" and "costs (parts)" instead, you can use TS[.., gross revenue - costs (parts)].
 – The columns of the new TimeSeries are in the same order as the expressions in algexps.
 – The column headers of the new TimeSeries are the default headers, as described in the discussion of the headers option.
 • The rows of a TimeSeries can be filtered with TS[boolexps] or TS[boolexps, columns], where boolexps is a Boolean expression or a list of Boolean expressions, where the indeterminates are the headers of the columns, as names.
 – For each row, the column names in boolexps are substituted with the value from that column in the same row. The values of that row are retained if and only if all expressions in boolexps is satisfied. For example, if a column of a TimeSeries object TS has header "profit", you can select the rows of TS with profits less than 1000 with TS['profit' < 1000].
 – Since the headers are used as names, they need to be enclosed in backticks () if they include characters that are not normally part of Maple names, such as spaces. In the previous examples, if the column is called "gross profit", you can select rows with TS[gross profit < 1000].
 – If one expression in boolexps is not satisfied, then the values in that row becomes undefined.

Examples

 > $\mathrm{with}\left(\mathrm{TimeSeriesAnalysis}\right):$

A simple time series object.

 > $\mathrm{t1}:=\mathrm{TimeSeries}\left(\left[4,5,6\right]\right)$
 ${\mathrm{t1}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2012 - 2014}}\end{array}\right]$ (1)
 > $\mathrm{GetData}\left(\mathrm{t1}\right)$
 $\left[\begin{array}{c}{4.}\\ {5.}\\ {6.}\end{array}\right]$ (2)
 > $\mathrm{GetDates}\left(\mathrm{t1}\right)$
 $\left[\begin{array}{c}{"2012"}\\ {"2013"}\\ {"2014"}\end{array}\right]$ (3)
 > $\mathrm{GetHeaders}\left(\mathrm{t1}\right)$
 $\left[{"data set"}\right]$ (4)

The same data, but now specifying the header and the times.

 > $\mathrm{t2}:=\mathrm{TimeSeries}\left(\left[4,5,6\right],'\mathrm{header}'="Monthly sales",'\mathrm{startdate}'="2013-01-31",'\mathrm{frequency}'="monthly"\right)$
 ${\mathrm{t2}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Monthly sales}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2013-01-31 - 2013-03-31}}\end{array}\right]$ (5)
 > $\mathrm{GetData}\left(\mathrm{t2}\right)$
 $\left[\begin{array}{c}{4.}\\ {5.}\\ {6.}\end{array}\right]$ (6)
 > $\mathrm{GetDates}\left(\mathrm{t2}\right)$
 $\left[\begin{array}{c}{"2013-01-31"}\\ {"2013-02-28"}\\ {"2013-03-31"}\end{array}\right]$ (7)
 > $\mathrm{GetHeaders}\left(\mathrm{t2}\right)$
 $\left[{"Monthly sales"}\right]$ (8)

A time series with three data sets.

 > $\mathrm{t3}:=\mathrm{TimeSeries}\left(\left[\left[5,6,7,8\right],\left[3,4,5,6\right],\left[2,3,4,5\right]\right],'\mathrm{headers}'="Region",'\mathrm{dates}'=\left["March:2006:08","March:2006:29","April:2006:19","May:2006:10"\right],'\mathrm{format}'="%B:%Y:%d"\right)$
 ${\mathrm{t3}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Region 1, Region 2, Region 3}}\\ {\mathrm{4 rows of data:}}\\ {\mathrm{March:2006:08 - May:2006:10}}\end{array}\right]$ (9)
 > $\mathrm{GetData}\left(\mathrm{t3}\right)$
 $\left[\begin{array}{ccc}{5.}& {3.}& {2.}\\ {6.}& {4.}& {3.}\\ {7.}& {5.}& {4.}\\ {8.}& {6.}& {5.}\end{array}\right]$ (10)
 > $\mathrm{GetDates}\left(\mathrm{t3}\right)$
 $\left[\begin{array}{c}{"March:2006:08"}\\ {"March:2006:29"}\\ {"April:2006:19"}\\ {"May:2006:10"}\end{array}\right]$ (11)
 > $\mathrm{GetHeaders}\left(\mathrm{t3}\right)$
 $\left[{"Region 1"}{,}{"Region 2"}{,}{"Region 3"}\right]$ (12)

Time series as a plot.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{t3}\right)$

You can select the data for regions 1 and 3 only.

 > $\mathrm{t3a}:={\mathrm{t3}}_{\left(\right)..\left(\right),\left["Region 1","Region 3"\right]}$
 ${\mathrm{t3a}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Region 1, Region 3}}\\ {\mathrm{4 rows of data:}}\\ {\mathrm{March:2006:08 - May:2006:10}}\end{array}\right]$ (13)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{t3a}\right)$

Next, select the rows corresponding to March and April of region two.

 > $\mathrm{t3b}:={\mathrm{t3}}_{"March:2006:01".."April:2006:30",2}$
 ${\mathrm{t3b}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Region 2}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{March:2006:08 - April:2006:19}}\end{array}\right]$ (14)

Taking a quality measurement every minute, for one day.

 > $s:=\mathrm{Statistics}:-\mathrm{Sample}\left(\mathrm{ChiSquare}\left(2\right),60\cdot 24\right)$
 ${s}{:=}\left[\begin{array}{c}{\mathrm{1 .. 1440}}{{\mathrm{Vector}}}_{{\mathrm{row}}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (15)
 > $\mathrm{t4}:=\mathrm{TimeSeries}\left(s,'\mathrm{startdate}'="2013-11-06 00:00",'\mathrm{frequency}'=60,'\mathrm{format}'="%Y-%m-%d %H:%M",'\mathrm{header}'="Quality"\right)$
 ${\mathrm{t4}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Quality}}\\ {\mathrm{1440 rows of data:}}\\ {\mathrm{2013-11-06 00:00 - 2013-11-06 23:59}}\end{array}\right]$ (16)
 > ${\mathrm{GetData}\left(\mathrm{t4}\right)}_{1..10}$
 $\left[\begin{array}{c}{8.23569715700137}\\ {2.86989491872752}\\ {0.906387485203342}\\ {6.66617415333070}\\ {0.912886574675588}\\ {0.127544800632028}\\ {0.290688114150592}\\ {0.422868454117775}\\ {7.23735557258824}\\ {10.9349083968833}\end{array}\right]$ (17)
 > ${\mathrm{GetDates}\left(\mathrm{t4}\right)}_{1..10}$
 $\left[\begin{array}{c}{"2013-11-06 00:00"}\\ {"2013-11-06 00:01"}\\ {"2013-11-06 00:02"}\\ {"2013-11-06 00:03"}\\ {"2013-11-06 00:04"}\\ {"2013-11-06 00:05"}\\ {"2013-11-06 00:06"}\\ {"2013-11-06 00:07"}\\ {"2013-11-06 00:08"}\\ {"2013-11-06 00:09"}\end{array}\right]$ (18)
 > $\mathrm{GetHeaders}\left(\mathrm{t4}\right)$
 $\left[{"Quality"}\right]$ (19)

You can select the quality measurements starting at 6pm and exclude the last ten measurements.

 > $\mathrm{t4a}:={\mathrm{t4}}_{"2013-11-06 18:00"..-11}$
 ${\mathrm{t4a}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{Quality}}\\ {\mathrm{350 rows of data:}}\\ {\mathrm{2013-11-06 18:00 - 2013-11-06 23:49}}\end{array}\right]$ (20)

Hourly data is by default considered potentially seasonal with a period of one day.

 > $\mathrm{t5}:=\mathrm{TimeSeries}\left(s,'\mathrm{startdate}'="2010-01-01 00:00",'\mathrm{format}'="%Y-%m-%d %H:%M",'\mathrm{frequency}'="hourly"\right)$
 ${\mathrm{t5}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{1440 rows of data:}}\\ {\mathrm{2010-01-01 00:00 - 2010-03-01 23:00}}\end{array}\right]$ (21)
 > $\mathrm{GetPeriod}\left(\mathrm{t5}\right)$
 ${24}$ (22)

You can override this parameter if you expect that assuming seasonality with a period of 12 hours can give a better model, such as in the case of tidal information.

 > $\mathrm{t6}:=\mathrm{TimeSeries}\left(s,'\mathrm{startdate}'="2010-01-01 00:00",'\mathrm{format}'="%Y-%m-%d %H:%M",'\mathrm{frequency}'="hourly",'\mathrm{period}'=12\right)$
 ${\mathrm{t6}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{1440 rows of data:}}\\ {\mathrm{2010-01-01 00:00 - 2010-03-01 23:00}}\end{array}\right]$ (23)
 > $\mathrm{GetPeriod}\left(\mathrm{t6}\right)$
 ${12}$ (24)

Selecting columns with a sequence of integers.

 > $\mathrm{t7}:=\mathrm{TimeSeries}\left(\left[\left[1,2,3\right],\left[4,5,6\right],\left[7,8,9\right]\right],\mathrm{headers}=\left["a","b","c"\right]\right)$
 ${\mathrm{t7}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{a, b, c}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2012 - 2014}}\end{array}\right]$ (25)
 > $\mathrm{GetData}\left({\mathrm{t7}}_{2}\right)$
 $\left[\begin{array}{c}{4.}\\ {5.}\\ {6.}\end{array}\right]$ (26)
 > $\mathrm{GetData}\left({\mathrm{t7}}_{-2,-3}\right)$
 $\left[\begin{array}{cc}{4.}& {1.}\\ {5.}& {2.}\\ {6.}& {3.}\end{array}\right]$ (27)

Creating a TimeSeries with new data from existing TimeSeries.

 > $\mathrm{GetData}\left({\mathrm{t7}}_{\left(\right)..\left(\right),'a'+'b'}\right)$
 $\left[\begin{array}{c}{5.}\\ {7.}\\ {9.}\end{array}\right]$ (28)
 > $\mathrm{GetData}\left({\mathrm{t7}}_{\left(\right)..\left(\right),\left['b'-'a','a'+'b'\right]}\right)$
 $\left[\begin{array}{cc}{3.}& {5.}\\ {3.}& {7.}\\ {3.}& {9.}\end{array}\right]$ (29)

Filtering the rows of a TimeSeries.

 > $\mathrm{t8}:=\mathrm{TimeSeries}\left(\left[\left[1,2,3,4\right],\left[5,6,7,8\right]\right],\mathrm{headers}=\left["a","b"\right]\right)$
 ${\mathrm{t8}}{:=}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{a, b}}\\ {\mathrm{4 rows of data:}}\\ {\mathrm{2011 - 2014}}\end{array}\right]$ (30)
 > $\mathrm{GetData}\left({\mathrm{t8}}_{'b'\ne 6}\right)$
 $\left[\begin{array}{cc}{1.}& {5.}\\ {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)& {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)\\ {3.}& {7.}\\ {4.}& {8.}\end{array}\right]$ (31)
 > $\mathrm{GetData}\left({\mathrm{t8}}_{\left['b'\ne 6,4\ne 'a'\right]}\right)$
 $\left[\begin{array}{cc}{1.}& {5.}\\ {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)& {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)\\ {3.}& {7.}\\ {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)& {\mathrm{HFloat}}{}\left({\mathrm{undefined}}\right)\end{array}\right]$ (32)
 >