Working with grouped data - data access and analysis (standard deviation)

3 views (last 30 days)
I have a relatively large dataset in which I need to group data based on the cycle of reading, and calculate the median for these cycles. This worked so far. Now I need to compare a value from each member in each cycle with the median for that cycle within some standard deviation range. This should be recorded for some sort of timeseries analysis.
However, I am not able to find a proper solution with the matlab so far. It would be great if someone could help me with this.
so, to recap, - group by cycle - calculate median per group - compare each member valu of the cycle (same members in every cycle) to the group median - save results for each cycle/ member pair in timeseries?
Thanks

Accepted Answer

Tom Lane
Tom Lane on 19 Apr 2012
I can get you partway there. Here is code to generate some cycle values, generate random data, compute the medians for each cycle, and subtract the cycle medians from the data:
cycle = sort(randi(5,30,1));
a = cycle+randn(size(cycle))/5;
meds = grpstats(a,cycle,@median)
a-meds(cycle)
I don't understand how you intend to convert this to a timeseries, but perhaps you can figure that out. Also, if your cycle values are not consecutive integers starting from 1, you may find it helpful to use the grp2idx function to generate group numbers.

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!