Join time series together - Maple Help

Online Help

All Products    Maple    MapleSim


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

TimeSeriesAnalysis[Join] - Join time series together

Calling Sequence

Join(ts1, ts2, ..., opts)

ts1ts2...

ts1 union ts2 union ...

<ts1, ts2, ...>

<ts1 | ts2 | ...>

Parameters

ts1, ts2, ...

-

TimeSeries data structures

opts

-

(optional) equations of the form keyword = value

Description

• 

The Join command takes multiple TimeSeries data structures and stores them in a single, new, TimeSeries data structure.

• 

The Join command can also be invoked in a few other ways:

Command (2D input)

Command (1D input)

Is equivalent to

ts1ts2ts3

ts1 union ts2 union ts3

Join(ts1, ts2, ts3)

ts1&comma;ts2&comma;ts3

<ts1, ts2, ts3>

Join(ts1, ts2, ts3)

ts1|ts2|ts3

<ts1 | ts2 | ts3>

Join(ts1, ts2, ts3, mergedatasets = false)

  

These alternative calling sequences provide no new functionality, just notational convenience.

• 

All calling sequences described above accept any number of time series to be joined together. The command first determines what the data sets in the new time series object are going to be (see the discussion of the mergedatasets option, below). It then determines what times will be present in the new time series (see the discussion of the regulardates option, below). Finally, a Matrix encompassing all data is constructed, which is turned into a TimeSeries data structure.

Options

• 

mergedatasets = false, true, or force

  

This option determines how Join decides how the data sets will occur in the new time series object. If mergedatasets = false is passed, then every data set in the input time series will be a separate data set in the resulting time series. If mergedatasets = true (the default) then all data sets that have equal names (given by the headers option; see GetHeaders) will be merged. This is the default. If mergedatasets = force is given, then all first data sets in every time series will be merged together; all second data sets (if present) will be merged, and so on.

  

If some data sets are merged, then the resulting data set gets the name of the data set occurring first in the calling sequence. If there are multiple values for one time stamp for the same data set, then the valuetolerance option determines what happens.

• 

valuetolerance = nonnegative real number or infinity

  

Whenever data sets are merged, there can be a range of dates where more than one data set has a value. If this is the case and the values differ by more than the value of the valuetolerance parameter (in absolute sense), then an error is issued. Otherwise, values from data sets in earlier arguments (further to the left in the calling sequence) will be overwritten by values from data sets in later arguments (further to the right in the calling sequence). The default value is 0, meaning that values differing in any way yield an error. If specifying infinity as the value for this option, values will always be overwritten without raising an error.

  

When one of the sets has missing data for a given date, it is not considered for this process.

• 

regulardates = true or false

  

If the dates of two time series do not match up exactly, then Maple needs to make a choice: either include multiple slightly different dates, or move values from one or more time series to a slightly different date. If regulardates = true (the default), then Maple tries to determine a set of time stamps that are mostly regular - i.e., they have intervals of similar length between them. In particular, it finds the time series with the shortest intervals on average and tries to make all time series line up around multiples of that interval. This means, for example, that if monthly data is joined to quarterly data, that monthly data points will always be inserted in between the quarterly data, even if the monthly data has a more limited range. If the time stamps do not exactly line up, the datetolerance option, explained below, determines what difference between them is accepted.

  

If regulardates = false, then Maple simply tries to find relatively few time stamps that occur near the time stamps in the given time series. (How near is determined by the datetolerance option below.) This can be appropriate if you need to join weekly and monthly data, for example. Note, however, that most commands in the TimeSeriesAnalysis package assume that dates are regular.

• 

datetolerance = nonnegative real number

  

This option, together with the regulardates option, determines what are the time stamps of the time series to be constructed. In particular, if one time series has time stamps on the last day of every month, and another has time stamps on the 28th of every month, one could include both dates and either insert alternating missing values in between, or interpolate - but it seems more likely that, say, January 28th and January 31st can be considered the same time point. The datetolerance option determines when dates are merged. The way it works is as follows: given a sequence ti of dates, Maple determines a time interval tidelta..ti&plus;delta for every date ti, where delta is typically equal to 12ti&plus;1ti1datetolerance. It then ensures that for every ti, there is a corresponding time stamp Tk in the new time series such that Tk is in the range tidelta..ti&plus;delta. If regulardates is true, then an error is raised if this is not possible within the constraints given. If regulardates is false, then extra time stamps are simply inserted.

  

Setting datetolerance=0 means different time stamps are never merged. If regulardates is false, then setting datetolerance equal to 1 or higher means that multiple dates from the same time series will have overlapping dates and is not recommended. (With time intervals that are not equally long, such as months, this is even possible for values of datetolerance that are a little less than 1.) If regulardates is true, this cannot happen. The default value is 0.05.

• 

interpolate = none, nearest, or linear

  

If dates are inserted in between values for a time series, then by default the result will not have values coming from that time series. This option offers the opportunity to insert values obtained by interpolation.

  

More precisely, suppose a data set has values xk and xk&plus;1 for dates tk and tk&plus;1. These are mapped to times Tm and Tm&plus;n, with 1<n. For times Tm&plus;i with 0<i and i<n, the default option, interpolate = none, will not supply any values for the resulting data set. If the option interpolate = nearest is supplied, then the resulting data set's value for Tm&plus;i will get the value for tk if i<12n and the value for tk&plus;1 otherwise. If the option interpolate = linear is supplied, then the value will be determined by linear interpolation: the value for time Tm&plus;i is xk&plus;ixk&plus;1xkn.

Examples

withTimeSeriesAnalysis&colon;

Consider the following time series.

ts1:=TimeSeries5.2&comma;4.8&comma;2.9&comma;3.9&comma;4.3&comma;4.3&comma;3.1&comma;16.3&comma;19.1&comma;15.6&comma;18.2&comma;undefined&comma;17.7&comma;19.6&comma;headers&equals;A&comma;B&comma;frequency&equals;monthly&comma;enddate&equals;2011-10-30

ts1:=Time seriesA, B7 rows of data:2011-04-30 - 2011-10-30

(1)

ts2:=TimeSeries17.8&comma;19.9&comma;21.2&comma;22.5&comma;23.9&comma;header&equals;B&comma;enddate&equals;2012-01-31&comma;frequency&equals;monthly

ts2:=Time seriesB5 rows of data:2011-09-30 - 2012-01-31

(2)

This is what the data from the time series looks like.

TimeSeriesPlotts1&comma;ts2

Trying to merge the data will not work without specifying some options, because there are different values for the same time.

ts3:=Joints1&comma;ts2

Error, (in TimeSeries:-Join) for time 2011-09-30, new data set B has two candidate values, HFloat(17.7) and HFloat(17.8), which differ by more than valuetolerance (0)

By specifying the value tolerance, we can complete the join successfully.

ts3:=Joints1&comma;ts2&comma;valuetolerance&equals;0.5

ts3:=Time seriesA, B10 rows of data:2011-04-30 - 2012-01-31

(3)

TimeSeriesPlotts3

The dates for both time series are not exactly the same; ts2 always has a data point at the last day of the month, and ts1 on the 30th. (In this case, there is no data for February, but if there were it would be on the last day of February.) So the fact that we get single data points makes use of the fact that the date tolerance is nonzero. If we set the date tolerance to 0, we get an error if we do not specify regulardates&equals;false:

ts4:=Joints1&comma;ts2&comma;datetolerance&equals;0&comma;valuetolerance&equals;0.5

Error, (in TimeSeries:-interval_adjustment_helper) incompatible dates around 2011-10-31 00:00:00; consider increasing datetolerance

If we do specify regulardates&equals;false, we will get separate points for both input time series at the end of October, but the date in September will be the 30th for both. We specify the time series in the other order, so that the value of ts1 overwrite the one for ts2 for September 30th.

ts4:=Joints2&comma;ts1&comma;valuetolerance&equals;0.5&comma;datetolerance&equals;0&comma;regulardates&equals;false

ts4:=Time seriesB, A11 rows of data:2011-04-30 - 2012-01-31

(4)

GetDatests4

1 .. 11 VectorcolumnData Type: anythingStorage: rectangularOrder: Fortran_order

(5)

TimeSeriesPlotts4

We can force merging the first data set in each of ts1 and ts2.

ts5:=Joints1&comma;ts2&comma;mergedatasets&equals;force&comma;valuetolerance&equals;&infin;

ts5:=Time seriesA, B10 rows of data:2011-04-30 - 2012-01-31

(6)

TimeSeriesPlotts5

We can also force viewing the data sets as separate. This can be done by including the mergedatasets = false option, or using the following calling sequence:

ts6:=ts1&verbar;ts2

ts6:=Time seriesA, B, B 110 rows of data:2011-04-30 - 2012-01-31

(7)

TimeSeriesPlotts6

Using the calling sequences ts1&comma;ts2 or (equivalently) ts1ts2 will not work, for the same reason that the first call to Join above did not work: there are conflicting values that cannot be merged. But the following time series can be merged with ts1.

ts7:=ts23..

ts7:=Time seriesB3 rows of data:2011-11-30 - 2012-01-31

(8)

ts8:=TimeSeries4.9&comma;4.8&comma;2.4&comma;4.0&comma;undefined&comma;3.1&comma;4.0&comma;frequency&equals;monthly&comma;startdate&equals;2011-11-30&comma;header&equals;A

ts8:=Time seriesA7 rows of data:2011-11-30 - 2012-05-30

(9)

ts9:=ts1&comma;ts7&comma;ts8

ts9:=Time seriesA, B14 rows of data:2011-04-30 - 2012-05-30

(10)

TimeSeriesPlotts9

ts10:=ts1&cup;ts7&cup;ts8

ts10:=Time seriesB, A14 rows of data:2011-04-30 - 2012-05-30

(11)

TimeSeriesPlotts10

The time series ts9 and ts10 are the same. (They could also be obtained as TimeSeriesAnalysis:-Joints1&comma;ts7&comma;ts8.)

If we have a time series with weekly data, it is not straightforward how to join it with one with monthly data - even if the time series are not merged. This is because the dates do not line up well. In particular, we will need to use the regulardates = false option. This still leaves the issue of what happens in the monthly data set at the time stamps inserted for the weekly data set. There are a few options: the default one is to make each data set have missing values where only the other data sets have values.

ts11:=TimeSeries8.7&comma;10.1&comma;10.9&comma;9.4&comma;10.7&comma;9.5&comma;9.6&comma;12.2&comma;9.1&comma;9.8&comma;11.7&comma;11.7&comma;10.9&comma;10.6&comma;10.8&comma;11.2&comma;undefined&comma;10.2&comma;10.6&comma;undefined&comma;9.8&comma;10.8&comma;10.5&comma;10.1&comma;9.5&comma;9.4&comma;10.4&comma;11.5&comma;9.4&comma;12.1&comma;startdate&equals;2011-11-01&comma;frequency&equals;weekly&comma;header&equals;C

ts11:=Time seriesC30 rows of data:2011-11-01 - 2012-05-22

(12)

TimeSeriesPlotts11

ts12:=Joints8&comma;ts11&comma;regulardates&equals;false

ts12:=Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30

(13)

TimeSeriesPlotts12

The other option is to insert values at the new dates whenever there are two adjacent values in the original data set. This can be done by copying the nearest original data value, or by linear interpolation.

ts13:=Joints8&comma;ts11&comma;interpolate&equals;nearest&comma;regulardates&equals;false

ts13:=Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30

(14)

TimeSeriesPlotts13

ts14:=Joints8&comma;ts11&comma;interpolate&equals;linear&comma;regulardates&equals;false

ts14:=Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30

(15)

TimeSeriesPlotts14

See Also

TimeSeriesAnalysis


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam