Mean (with confidence bands) for signals sampled at different timepoints
Show older comments
I have ratings from multiple subjects, which I'd like to average and display with confidence bands to show cross-subject variability, more or less like in this random plot I found in some paper (where 3 separate conditions are shown):

Once I have the mean and confidence intervals at each timepoint, I figured I could then plot those either with the ciplot Exchange function, or with something like:
fill(x,y_CI, colours, 'FaceAlpha',0.2, 'LineStyle','-');
The problem is that each of my subjects' rating curve is sampled at different time points, for instance one subject might have ratings at [0.5s, 1.1s, ..], and another at [0.2s, 0.6s, ..].
I could manually define a linspace with 100ms-or-so bins and manually compute an average + CI for each. But this seems hacky, and I'm sure a more elegant & simple way exists, although I found no built-in Matlab function for it. One answer to this question suggests using defining and synchronising timetables, but this probably doesn't work in my case as the total number of ratings differs across subjects.
Any help would be greatly appreciated!
11 Comments
" one subject might have ratings at [0.5s, 1.1s, ..], and another at [0.2s, 0.6s, .. "
I presume those are both from a time zero for each subject so one can't time-shift each to a new origin by subtracting first point...
Is the observation value at the origin something known so can set that value?
Is this a continuous measurement or ...???
About all one could hope to do is some sort of interpolation to put on a common time basis; how much faith one could place in this would be something we have no way to judge, but MATLAB has tools to do such in a trivally simple manner -- the timetable and retime.
However, I would add the caution that just because you can do something doesn't mean that you should.
z8080
on 12 Aug 2022
dpb
on 12 Aug 2022
OK, that's good enough description.
What I forgot to ask is what form/where are the exsiting data for starting point to process? Just how/which tools/tricks to use can be significantly different, depending...
In general, I'd probably still go the timetable route; either synchonize or retime would be able to do the job of interpolating; the difference is that retime works within a given timetable while synchronize matches one to another.
I also realize I'm not sure about the comment above of " the total number of ratings differs across subjects" -- are we computing means by subject or across subjects? -- either is doable, but just need to know precisely what it is we're after here.
As per usual, ti would be a lot easier to provide specific code if you could attach a couple of the sample files to have something to poke at that actually fits the real problem...
z8080
on 12 Aug 2022
dpb
on 12 Aug 2022
Wowsers!!! What a mess!!!
What is the rating we're trying to do something with? And what does time have to do with ratings along with all the other variables?
How did you get this array of struct created -- where did the data for that come from? I'd probably go back to that point and build a more suitable data storage scheme that matched up with what was trying to do more easily instead.
z8080
on 13 Aug 2022
dpb
on 13 Aug 2022
Think would have to see how the data are stored initially that you retrieved to be able to judge that -- and an idea of just what it is that you really need to keep (do you really need all the stuff or are you just interested in some subset but saved it all "just because"?
So, they're "rating" thie piece while it's being listened to during the piece,I gather? Which is why there are various times/ratings?
dpb
on 14 Aug 2022
OK, so I see from whence came the struct array -- the jsondecode routine does its best although it fails on some subfields it appears.
But, I'm totally at sea in knowing what any of it means (if anything) and what has bearing on what you think you want to try to do with it...
" we can just take one subejct, for any of the stimuli, in any one given condition..."
There's only a "Condition" variable for struct's whose rt ("Real time" in some units, maybe?") is -1 which doesn't seem to make the above supposition. There's something called "conditions" in a vector; what, if anything, does that have to do with the other and which is what you're after? And, if it has to do with the vector; what's that correlate to and how with anything else? It's an absolute mess that only its mother could love...
z8080
on 14 Aug 2022
dpb
on 14 Aug 2022
"Using `synchronize` with spline gave me artefactual interpolations, with y values that go way outside of the 0-100 range."
Yes, not too surprising with a spline if the data have points of inflection; the spline will fit a quadratic through each subsequent set of points -- it will go through each point identically, but is not constrained in between -- I forget whether the method matches even first derivative at the breakpoints or not; my thinking is "not".
Would have to see what particular datasets you're looking at look like to have any specific recomendations other than the obvious(?) of using 'linear' interpolation between the existing data.
Answers (0)
Categories
Find more on Design Condition Indicators Interactively 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!