2
$\begingroup$

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.

$\endgroup$
3
  • $\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
    Commented May 13, 2016 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
    Commented May 13, 2016 at 16:50
  • $\begingroup$ Thank you @MarcoB! I will update my post with my new attempt. $\endgroup$ Commented May 13, 2016 at 16:59

2 Answers 2

3
$\begingroup$

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]]}

ListPlot[scrambled]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ This is exactly what I needed. $\endgroup$ Commented May 13, 2016 at 17:07
  • $\begingroup$ @FoxForceFive glad to be of help! $\endgroup$
    – MarcoB
    Commented May 13, 2016 at 18:10
2
$\begingroup$

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

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

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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