2
$\begingroup$

I was wondering if it is possible to combine multiple TimeSeries data objects of values that have different dimensionality into one TemporalData object. Assume the following test scenario of two TimeSeries that are created from a list of integers (s1), a list of lists with three elements each (s2) and a list of time-values.

s1 = {{106, 126, 78}, {106, 123, 78}, {107, 120, 79}, {106, 118, 79}, {106, 117, 79}, {106, 117, 79}, {107, 116, 80}, {107, 116, 80}, {107, 117, 80}, {107, 120, 80}};
s2 = {157357, 157910, 156605, 156971, 156632, 155637, 154101, 153654, 152738, 151989};
t = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11};

{ts1,ts2} = Map[TimeSeries[#, {t}] &, {s1, s2}]

Blockquote

Both TimeSeries are created and missing values are interpolated.

ts1[Range[11]]

{157357, 157910, 156605, 156971, 156632, 155637, 154869, 154101, 153654, 152738, 151989}

ts2[Range[11]]

{{106, 126, 78}, {106, 123, 78}, {107, 120, 79}, {106, 118, 79}, {106, 117, 79}, {106, 117, 79}, {213/2, 233/2, 159/2}, {107, 116, 80}, {107, 116, 80}, {107, 117, 80}, {107, 120, 80}}

However I cannot combine the two TimeSeries into one TemporalData object:

TemporalData[{ts1, ts2}]

enter image description here

  1. What is the problem?
  2. Is there a workaround or do I have to stick to a list of TimeSeries in that case?
  3. A side question: Is it possible to avoid extrapolation in TimeSeries?

Thanks for any suggestions!

$\endgroup$
  • $\begingroup$ Maybe TemporalData[Join[TimeSeries/@Transpose[ts1["Values"]],{ts2}]] for the second part of your question? $\endgroup$ – kglr Oct 13 '14 at 15:52
4
$\begingroup$

TemporalData needs to assume equal dimensionality of series in order to distinguish between the case of a single multivariate series and multiple univariate series. There is no workaround to this limitation so you will need to stick to a list of TimeSeries objects.

Also, to avoid extrapolation you can always use a different setting for ResamplingMethod. For example, setting it to None will cause it to return Missing[] anywhere the original data is not defined.

EDIT

I hadn't noticed that your data sets are each of the same length. I would echo @kguler's comment for a work-around.

TemporalData[Transpose[Transpose[s1]~Join~{s2}], {t}]

One possibility for avoiding extrapolation would be to wrap your TimeSeries or TemporalData in a function that specially handles edge behavior. For example:

noEx[ts_][t_?NumericQ] := 
 Piecewise[{{ts[t], ts["FirstTime"] <= t <= ts["LastTime"]}}, 
  Missing[]]

Plot[noEx[ts1][t], {t, 0, 12}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for your advice. I will try to do it with the workaround. Do you have an idea if it is possible to do interpolation of values in between but to avoid extrapolation? $\endgroup$ – g3kk0 Oct 14 '14 at 9:08
  • $\begingroup$ Thanks for your update of the answer. That looks very promising! $\endgroup$ – g3kk0 Oct 15 '14 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.