Calculating area under and above multiple threshold-constrained curves

Disclosure: I am a Matlab novice.
Background to the Problem: I have a clinical dataset comprised of physiological values sampled at equal time intervals. I have established a threshold value such that over the entire epoch, there are sub-intervals during which the values exceed the threshold, and sub-intervals during which the values fall below the threshold. I have used the fill2c function that is available on the File Exchange to nicely visualize the relative time above or below the threshold. This produces a plot with multiple, discontinuous episodes where the value of the variable is below the threshold; the duration and magnitude of deviation during each of these sub-intervals is highly variable.
What I Want to Achieve: Looking at the entire epoch, in addition to qualitatively visualizing, I want to be able quantify, in some way, the duration and magnitude of deviation below the threshold, and compare it quantitatively, to the duration and magnitude of deviation above the threshold. My approach would be to use trapz function (or some other numerical method) to calculate the AUC for each sub-interval, and sum. I have made some very inefficient attempts - e.g., id'ing the respective indices where where the variables first cross the threshold in the downward direction, then recross in the upward, storing as a column vector, and then using the trapz function or colAUC.
Question: This is a VERY inefficient and inelegant approach, yet the problem seems generic. I'm wondering if someone can point me in the direction or provide hints to a more efficient approach/solution, as I need to do this over several very large datasets.

 Accepted Answer

What about cumtrapz? Subtract the threshold from the whole data set.
Edit:
%Example: (Assuming from your description what's in the picture)
x = 0:0.001:2*pi;
y = sin(x);
tr = diff([0 cumtrapz(x,y)]);
gray_area = sum(tr(y<0));
red_area = sum(tr(y>0));
This example will work for you but you need to add x/y points at the zero crossings (in your case 100 crossings, but I would scale it to 0).

4 Comments

Hopefully the figure accessible at the following link will illustrate:
https://rapidshare.com/files/460784651/Sample.fig
The goal is to compare AUC for grey shaded intervals to AUC for red shaded intervals. This is a small dataset. Work involves many large similar datasets. I will eventually need to do this type of comparative analysis within specific start and end times boundaries.
That upload site isn't working for me. Try saving it as a jpg and uploading it at uploadhouse.com
Sorry. Try this:
http://www.uploadhouse.com/viewfile.php?id=10061090&PHPSESSID=6fb4641389c5aec3e8239f6c7d15407d
Did the appropriate modifications, and transposed the red/grey. Works well. Thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!