Join time series together
Join(ts1, ts2, ..., opts)
ts1 union ts2 union ...
<ts1, ts2, ...>
<ts1 | ts2 | ...>
ts1, ts2, ...
TimeSeries data structures
(optional) equations of the form keyword = value
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
ts1 union ts2 union 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.
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 ti−δ..ti+δ for every date ti, where δ is typically equal to ti+1−ti−1⁢datetolerance2. 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 ti−δ..ti+δ. 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+1 for dates tk and tk+1. These are mapped to times Tm and Tm+n, with 1<n. For times Tm+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+i will get the value for tk if i<n2 and the value for tk+1 otherwise. If the option interpolate = linear is supplied, then the value will be determined by linear interpolation: the value for time Tm+i is xk+i⁢xk+1−xkn.
Consider the following time series.
ts1 ≔ TimeSeries⁡5.2,4.8,2.9,3.9,4.3,4.3,3.1,16.3,19.1,15.6,18.2,undefined,17.7,19.6,headers=A,B,frequency=monthly,enddate=2011-10-30
ts1≔Time seriesA, B7 rows of data:2011-04-30 - 2011-10-30
ts2 ≔ TimeSeries⁡17.8,19.9,21.2,22.5,23.9,header=B,enddate=2012-01-31,frequency=monthly
ts2≔Time seriesB5 rows of data:2011-09-30 - 2012-01-31
This is what the data from the time series looks like.
Trying to merge the data will not work without specifying some options, because there are different values for the same time.
ts3 ≔ Join⁡ts1,ts2
Error, (in TimeSeries:-Join) for time 2011-09-30, new data set B has two candidate values, 17.7 and 17.8, which differ by more than valuetolerance (0)
By specifying the value tolerance, we can complete the join successfully.
ts3 ≔ Join⁡ts1,ts2,valuetolerance=0.5
ts3≔Time seriesA, B10 rows of data:2011-04-30 - 2012-01-31
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=false:
ts4 ≔ Join⁡ts1,ts2,datetolerance=0,valuetolerance=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=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 ≔ Join⁡ts2,ts1,valuetolerance=0.5,datetolerance=0,regulardates=false
ts4≔Time seriesB, A11 rows of data:2011-04-30 - 2012-01-31
We can force merging the first data set in each of ts1 and ts2.
ts5 ≔ Join⁡ts1,ts2,mergedatasets=force,valuetolerance=∞
ts5≔Time seriesA, B10 rows of data:2011-04-30 - 2012-01-31
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|ts2
ts6≔Time seriesA, B, B 110 rows of data:2011-04-30 - 2012-01-31
Using the calling sequences ts1,ts2 or (equivalently) ts1∪ts2 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
ts8 ≔ TimeSeries⁡4.9,4.8,2.4,4.0,undefined,3.1,4.0,frequency=monthly,startdate=2011-11-30,header=A
ts8≔Time seriesA7 rows of data:2011-11-30 - 2012-05-30
ts9 ≔ ts1,ts7,ts8
ts9≔Time seriesA, B14 rows of data:2011-04-30 - 2012-05-30
ts10 ≔ ts1∪ts7∪ts8
ts10≔Time seriesB, A14 rows of data:2011-04-30 - 2012-05-30
The time series ts9 and ts10 are the same. (They could also be obtained as Join⁡ts1,ts7,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 ≔ TimeSeries⁡8.7,10.1,10.9,9.4,10.7,9.5,9.6,12.2,9.1,9.8,11.7,11.7,10.9,10.6,10.8,11.2,undefined,10.2,10.6,undefined,9.8,10.8,10.5,10.1,9.5,9.4,10.4,11.5,9.4,12.1,startdate=2011-11-01,frequency=weekly,header=C
ts11≔Time seriesC30 rows of data:2011-11-01 - 2012-05-22
ts12 ≔ Join⁡ts8,ts11,regulardates=false
ts12≔Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30
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 ≔ Join⁡ts8,ts11,interpolate=nearest,regulardates=false
ts13≔Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30
ts14 ≔ Join⁡ts8,ts11,interpolate=linear,regulardates=false
ts14≔Time seriesA, C33 rows of data:2011-11-01 - 2012-05-30
The TimeSeriesAnalysis[Join] command was introduced in Maple 18.
For more information on Maple 18 changes, see Updates in Maple 18.
Download Help Document
What kind of issue would you like to report? (Optional)