I am trying to randomize the order of a time series data set. I generated my data as:

    ts5 = RandomFunction[FractionalBrownianMotionProcess[.5], {0, 999, 1}]

Now I need to create a randomized control of this data: essentially, I need to treat the y and t values as their own lists and only randomize the y values while keeping the t values in the same order (0-999).

However, I have not found a way to separate the data, and the built in random functions are unable to preform this task (or so says my Google Fu).

Any help would be much appreciated.

  • $\begingroup$ Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 May 13 '16 at 16:45
  • $\begingroup$ Your ts5 data is wrapped in a TemporalData object. You can use First@ts5["Paths"] to get a {{t0, y0}, {t1, y1}...} regular list of pairs. $\endgroup$ – MarcoB May 13 '16 at 16:50
  • $\begingroup$ Thank you @MarcoB! I will update my post with my new attempt. $\endgroup$ – FoxForceFive May 13 '16 at 16:59

Extract the path from the TemporalData object, then isolate the $y$ values and produce a random permutation using RandomSample; finally add back the $t$ values:

ts5List = First@ts5["Paths"];
scrambled = Transpose@{ts5List[[All, 1]], RandomSample[ts5List[[All, 2]], Length[ts5List]]}


Mathematica graphics

|improve this answer|||||
  • $\begingroup$ This is exactly what I needed. $\endgroup$ – FoxForceFive May 13 '16 at 17:07
  • $\begingroup$ @FoxForceFive glad to be of help! $\endgroup$ – MarcoB May 13 '16 at 18:10

Working from what @MarcoB suggested, I came up with:

    ts5randomized = RandomSample[ts5["Values"]];
    ts5randomizeSeries = TimeSeries[ts5randomized, {0, 999, 1}]

This appears to be what I needed. Thanks again @MarcoB!

|improve this answer|||||

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.